Skip to content

Commit 330be18

Browse files
committed
lint
1 parent 9e6f713 commit 330be18

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

biome.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"recommended": true,
88
"correctness": {
99
"noUnusedImports": "error",
10-
"noUnusedVariables": "warn"
10+
"noUnusedVariables": "error"
1111
},
1212
"suspicious": {
1313
"noTemplateCurlyInString": "off",
1414
"noControlCharactersInRegex": "off",
15-
"noImplicitAnyLet": "warn",
16-
"noAssignInExpressions": "warn"
15+
"noImplicitAnyLet": "error",
16+
"noAssignInExpressions": "error"
1717
},
1818
"style": {
19-
"noNonNullAssertion": "warn"
19+
"noNonNullAssertion": "error"
2020
}
2121
}
2222
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"lint:fix": "biome check --write .",
1515
"test": "vitest",
1616
"test:run": "vitest run",
17-
"test:unit": "vitest run --exclude='**/comparison/**'",
18-
"test:comparison": "vitest run src/comparison",
17+
"test:unit": "vitest run --config vitest.unit.config.ts",
18+
"test:comparison": "vitest run --config vitest.comparison.config.ts",
1919
"shell": "npx tsx src/cli/shell.ts"
2020
},
2121
"keywords": [],

src/BashEnv.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,14 @@ export class BashEnv {
880880
this.callDepth--;
881881

882882
// Pop the local scope and restore shadowed variables
883-
const localScope = this.localScopes.pop()!;
884-
for (const [varName, originalValue] of localScope) {
885-
if (originalValue === undefined) {
886-
delete this.env[varName];
887-
} else {
888-
this.env[varName] = originalValue;
883+
const localScope = this.localScopes.pop();
884+
if (localScope) {
885+
for (const [varName, originalValue] of localScope) {
886+
if (originalValue === undefined) {
887+
delete this.env[varName];
888+
} else {
889+
this.env[varName] = originalValue;
890+
}
889891
}
890892
}
891893

src/commands/basename/basename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const basenameCommand: Command = {
4949

5050
// If not multiple mode, second arg is suffix
5151
if (!multiple && names.length >= 2) {
52-
suffix = names.pop()!;
52+
suffix = names.pop() ?? "";
5353
}
5454

5555
const results: string[] = [];

src/commands/cp/cp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const cpCommand: Command = {
3232
};
3333
}
3434

35-
const dest = paths.pop()!;
35+
const dest = paths.pop() ?? "";
3636
const sources = paths;
3737
const destPath = ctx.fs.resolvePath(ctx.cwd, dest);
3838

src/commands/find/find.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,13 @@ export const findCommand: Command = {
305305
return;
306306
}
307307

308-
let stat;
308+
let stat: Awaited<ReturnType<typeof ctx.fs.stat>> | undefined;
309309
try {
310310
stat = await ctx.fs.stat(currentPath);
311311
} catch {
312312
return;
313313
}
314+
if (!stat) return;
314315

315316
// For the starting directory, use the search path itself as the name
316317
// (e.g., when searching from '.', the name should be '.')

src/commands/grep/grep.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,11 @@ function grepContent(
412412
if (onlyMatching) {
413413
// Output only the matched parts
414414
regex.lastIndex = 0;
415-
let match;
416-
while ((match = regex.exec(line)) !== null) {
415+
for (
416+
let match = regex.exec(line);
417+
match !== null;
418+
match = regex.exec(line)
419+
) {
417420
let outputLine = match[0];
418421
if (filename) {
419422
outputLine = `${filename}:${outputLine}`;

src/commands/mv/mv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const mvCommand: Command = {
2626
};
2727
}
2828

29-
const dest = paths.pop()!;
29+
const dest = paths.pop() ?? "";
3030
const sources = paths;
3131
const destPath = ctx.fs.resolvePath(ctx.cwd, dest);
3232

src/commands/printf/printf.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ function convertArgs(format: string, args: string[]): (string | number)[] {
152152

153153
// Match format specifiers: %[flags][width][.precision][length]specifier
154154
const specifierRegex = /%[-+0 #]*\d*(?:\.\d+)?[hlL]?([diouxXeEfFgGaAcspn%])/g;
155-
let match;
156155

157-
while ((match = specifierRegex.exec(format)) !== null) {
156+
for (
157+
let match = specifierRegex.exec(format);
158+
match !== null;
159+
match = specifierRegex.exec(format)
160+
) {
158161
const specifier = match[1];
159162

160163
if (specifier === "%") {

src/commands/sed/sed.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ export const sedCommand: Command = {
229229
lineStart === undefined ||
230230
(lineNum >= lineStart && lineNum <= (lineEnd ?? lineStart));
231231

232-
if (sedCmd.type === "substitute" && inRange) {
232+
if (sedCmd.type === "substitute" && inRange && sedCmd.pattern) {
233233
let flags = "";
234234
if (sedCmd.global) flags += "g";
235235
if (sedCmd.ignoreCase) flags += "i";
236-
const regex = new RegExp(sedCmd.pattern!, flags);
236+
const regex = new RegExp(sedCmd.pattern, flags);
237237

238238
// Handle & replacement
239239
line = line.replace(regex, (match) =>
240-
processReplacement(sedCmd.replacement!, match),
240+
processReplacement(sedCmd.replacement ?? "", match),
241241
);
242242
} else if (sedCmd.type === "delete") {
243243
if (sedCmd.addressPattern) {
@@ -315,13 +315,13 @@ export const sedCommand: Command = {
315315
lineStart === undefined ||
316316
(lineNum >= lineStart && lineNum <= (lineEnd ?? lineStart));
317317

318-
if (sedCmd.type === "substitute" && inRange) {
318+
if (sedCmd.type === "substitute" && inRange && sedCmd.pattern) {
319319
let flags = "";
320320
if (sedCmd.global) flags += "g";
321321
if (sedCmd.ignoreCase) flags += "i";
322-
const regex = new RegExp(sedCmd.pattern!, flags);
322+
const regex = new RegExp(sedCmd.pattern, flags);
323323
line = line.replace(regex, (match) =>
324-
processReplacement(sedCmd.replacement!, match),
324+
processReplacement(sedCmd.replacement ?? "", match),
325325
);
326326
} else if (sedCmd.type === "delete") {
327327
if (sedCmd.addressPattern) {

0 commit comments

Comments
 (0)