Skip to content

Commit 357b7c5

Browse files
author
Hweinstock
committed
fix(tui): add safe assertions for typechecker
1 parent 0065c1d commit 357b7c5

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

.oxlintrc.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3-
"plugins": [
4-
"typescript",
5-
"react"
6-
],
3+
"plugins": ["typescript", "react"],
74
"categories": {
85
"correctness": "error"
96
},
10-
"ignorePatterns": [
11-
"dist/",
12-
"node_modules/"
13-
],
7+
"ignorePatterns": ["dist/", "node_modules/"],
148
"overrides": []
159
}

src/components/ui/data-table/DataTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export function DataTable<T extends Record<string, unknown>>({
8383
// Sort
8484
const sorted = sortColumn
8585
? [...filtered].sort((a, b) => {
86-
const av = String(a[sortColumn] ?? "");
87-
const bv = String(b[sortColumn] ?? "");
88-
return sortDirection === "asc" ? av.localeCompare(bv) : bv.localeCompare(av);
89-
})
86+
const av = String(a[sortColumn] ?? "");
87+
const bv = String(b[sortColumn] ?? "");
88+
return sortDirection === "asc" ? av.localeCompare(bv) : bv.localeCompare(av);
89+
})
9090
: filtered;
9191

9292
const totalPages = Math.ceil(sorted.length / pageSize);

src/components/ui/markdown/Markdown.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,17 @@ export const Markdown: React.FC<MarkdownProps> = ({ content, theme = darkTheme }
144144
let i = 0;
145145

146146
while (i < lines.length) {
147-
const line = lines[i];
147+
// Note: assertion is safe based on bound above.
148+
const line = lines[i]!;
148149

149150
// Fenced code block
150151
if (line.startsWith("```")) {
151152
const lang = line.slice(3).trim();
152153
const codeLines: string[] = [];
153154
i++;
154-
while (i < lines.length && !lines[i].startsWith("```")) {
155-
codeLines.push(lines[i]);
155+
// Note: assertions on lines[i] are safe based on first term in the while condition.
156+
while (i < lines.length && !lines[i]!.startsWith("```")) {
157+
codeLines.push(lines[i]!);
156158
i++;
157159
}
158160
elements.push(
@@ -253,10 +255,11 @@ export const Markdown: React.FC<MarkdownProps> = ({ content, theme = darkTheme }
253255
// Ordered list
254256
const olMatch = line.match(/^(\d+)\.\s(.*)/);
255257
if (olMatch) {
258+
// note: if the regex matched, there must be number at olMatch[1], so assertion is safe.
256259
elements.push(
257260
<Box key={i} flexDirection="row">
258-
<Text color={theme.colors.primary}>{` ${olMatch[1]}. `}</Text>
259-
<Text>{renderInline(parseInline(olMatch[2]), theme)}</Text>
261+
<Text color={theme.colors.primary}>{` ${olMatch[1]!}. `}</Text>
262+
<Text>{renderInline(parseInline(olMatch[2] ?? ""), theme)}</Text>
260263
</Box>,
261264
);
262265
i++;

0 commit comments

Comments
 (0)