Skip to content

Commit 696aeed

Browse files
committed
Removes arguments with leading _ from unused variable lint check.
This allows `_` to be used as a prefix for unused variable names, which is a common annotation. ESLint supports different options for variables, arguments, catch clauses, and destructured array. I opted to only allow this annotation for arguments and destructures because IMHO: * Unused variables are extremely rare, only ocurring in `@rules_prerender` in type-only tests. Those variables are usually load bearing in a unique way and deserve an actual ignore comment, otherwise the meaning of the leading `_` is unclear. * Catch clauses already support optional names, you can do `try {} catch {}`, so if the error is unused, the name should be omitted entirely.
1 parent fa3a9d0 commit 696aeed

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

.eslintrc.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ rules:
4040
no-constant-condition:
4141
- error
4242
- checkLoops: false # `while (true) { /* ... */ }` is ok.
43+
no-unused-vars:
44+
- error
45+
- argsIgnorePattern: "^_"
46+
destructuredArrayIgnorePattern: "^_"
47+
# Deliberately _not_ setting `varsIgnorePattern`, since that benefits from
48+
# an explicit ignore comment instead of a load-bearing `_`.
4349

4450
# Enable TypeScript rules only for `*.[cm]?ts` files.
4551
overrides:
@@ -62,6 +68,13 @@ overrides:
6268
no-undef:
6369
- off
6470

71+
'@typescript-eslint/no-unused-vars':
72+
- error
73+
- argsIgnorePattern: "^_"
74+
destructuredArrayIgnorePattern: "^_"
75+
# Deliberately _not_ setting `varsIgnorePattern`, since that benefits from
76+
# an explicit ignore comment instead of a load-bearing `_`.
77+
6578
- files:
6679
- "**/*_test.ts"
6780
- "**/test.ts"

common/file_system_fake.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class FileSystemFake implements FileSystem {
2727
this.fs.set(dest, contents);
2828
}
2929

30-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3130
public async mkdir(_dir: string, _options?: { recursive?: boolean }):
3231
Promise<void> {
3332
// Nothing to do.
@@ -37,7 +36,6 @@ export class FileSystemFake implements FileSystem {
3736
readFile(path: string, options: { encoding: 'utf8' }): Promise<string>;
3837
readFile(path: string, options?: string | { encoding?: string }):
3938
Promise<string | Buffer>;
40-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4139
public async readFile(inputPath: string, _options?: string | { encoding?: string }): Promise<string | Buffer> {
4240
const filePath = path.normalize(inputPath);
4341
const content = this.fs.get(filePath);

0 commit comments

Comments
 (0)