Skip to content

docs(linter): Fix/improve the configuration docs for no-unused-vars#17188

Merged
graphite-app[bot] merged 1 commit intomainfrom
docs-for-unused-vars
Dec 21, 2025
Merged

docs(linter): Fix/improve the configuration docs for no-unused-vars#17188
graphite-app[bot] merged 1 commit intomainfrom
docs-for-unused-vars

Conversation

@connorshea
Copy link
Member

@connorshea connorshea commented Dec 20, 2025

Previously we were skipping the generation of config schema/docs for several options due to the previous Regex issues we had. Now that those are fixed, we should render the docs fully.

This also renders default values now, and fixes the casing of the values you can pass to the args option, which should always use kebab-case. It also fixes caughtErrors, which was listed as a boolean despite taking an enum.

The docs are below:


Configuration

This rule accepts a configuration object with the following properties:

args

type: "after-used" | "all" | "none"

Controls how unused arguments are checked.

This option has three settings:

  1. after-used - Unused positional arguments that occur before the last
    used argument will not be checked, but all named arguments and all
    positional arguments after the last used argument will be checked.
    This is the default setting.
  2. all - All named arguments must be used.
  3. none - Do not check arguments.

"after-used"

Unused positional arguments that occur before the last used argument
will not be checked, but all named arguments and all positional
arguments after the last used argument will be checked.

"all"

All named arguments must be used

"none"

Do not check arguments

argsIgnorePattern

Specifies exceptions to this rule for unused arguments. Arguments whose
names match this pattern will be ignored.

By default, this pattern is ^_ unless options are configured with an
object. In this case it will default to [None]. Note that this
behavior deviates from both ESLint and TypeScript-ESLint, which never
provide a default pattern.

Example

Examples of correct code for this option when the pattern is ^_:

function foo(_a, b) {
  console.log(b);
}
foo(1, 2);

caughtErrors

type: "all" | "none"

Used for catch block validation.

It has two settings:

  • none - do not check error objects. This is the default setting.
  • all - all named arguments must be used.

none corresponds to false, while all corresponds to true.

caughtErrorsIgnorePattern

Specifies exceptions to this rule for errors caught within a catch block.
Variables declared within a catch block whose names match this pattern
will be ignored.

Example

Examples of correct code when the pattern is ^ignore:

try {
  // ...
} catch (ignoreErr) {
  console.error("Error caught in catch block");
}

destructuredArrayIgnorePattern

This option specifies exceptions within destructuring patterns that will
not be checked for usage. Variables declared within array destructuring
whose names match this pattern will be ignored.

By default this pattern is unset.

Example

Examples of correct code for this option, when the pattern is ^_:

const [a, _b, c] = ["a", "b", "c"];
console.log(a + c);

const {
  x: [_a, foo],
} = bar;
console.log(foo);

let _m, n;
foo.forEach((item) => {
  [_m, n] = item;
  console.log(n);
});

ignoreClassWithStaticInitBlock

type: boolean

default: false

The ignoreClassWithStaticInitBlock option is a boolean. Static
initialization blocks allow you to initialize static variables and
execute code during the evaluation of a class definition, meaning
the static block code is executed without creating a new instance
of the class. When set to true, this option ignores classes
containing static initialization blocks.

Example

Examples of incorrect code for the { "ignoreClassWithStaticInitBlock": true } option

/* no-unused-vars: ["error", { "ignoreClassWithStaticInitBlock": true }]*/

class Foo {
  static myProperty = "some string";
  static mymethod() {
    return "some string";
  }
}

class Bar {
  static {
    let baz; // unused variable
  }
}

Examples of correct code for the { "ignoreClassWithStaticInitBlock": true } option

/* no-unused-vars: ["error", { "ignoreClassWithStaticInitBlock": true }]*/

class Foo {
  static {
    let bar = "some string";

    console.log(bar);
  }
}

ignoreRestSiblings

type: boolean

default: false

Using a Rest property it is possible to "omit" properties from an
object, but by default the sibling properties are marked as "unused".
With this option enabled the rest property's siblings are ignored.

Example

Examples of correct code when this option is set to true:

// 'foo' and 'bar' were ignored because they have a rest property sibling.
var { foo, ...coords } = data;

var bar;
({ bar, ...coords } = data);

ignoreUsingDeclarations

type: boolean

default: false

When set to true, the rule will ignore variables declared with
using or await using declarations, even if they are unused.

This is useful when working with resources that need to be disposed
via the explicit resource management proposal, where the primary
purpose is the disposal side effect rather than using the resource.

Example

Examples of correct code for the { "ignoreUsingDeclarations": true } option:

/* no-unused-vars: ["error", { "ignoreUsingDeclarations": true }]*/

using resource = getResource();
await using anotherResource = getAnotherResource();

reportUsedIgnorePattern

type: boolean

default: false

The reportUsedIgnorePattern option is a boolean.
Using this option will report variables that match any of the valid
ignore pattern options (varsIgnorePattern, argsIgnorePattern,
caughtErrorsIgnorePattern, or destructuredArrayIgnorePattern) if
they have been used.

Example

Examples of incorrect code for the { "reportUsedIgnorePattern": true } option:

/* no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVarIgnored = 1;
var secondVar = 2;
console.log(firstVarIgnored, secondVar);

Examples of correct code for the { "reportUsedIgnorePattern": true } option:

/* no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVar = 1;
var secondVar = 2;
console.log(firstVar, secondVar);

reportVarsOnlyUsedAsTypes

type: boolean

default: false

The reportVarsOnlyUsedAsTypes option is a boolean.

If true, the rule will also report variables that are only used as types.

Examples

Examples of incorrect code for the { "reportVarsOnlyUsedAsTypes": true } option:

/*  no-unused-vars: ["error", { "reportVarsOnlyUsedAsTypes": true }] */

const myNumber: number = 4;
export type MyNumber = typeof myNumber

Examples of correct code for the { "reportVarsOnlyUsedAsTypes": true } option:

export type MyNumber = number;

Note: even with { "reportVarsOnlyUsedAsTypes": false }, cases where the value is
only used a type within itself will still be reported:

function foo(): typeof foo {}

vars

type: "all" | "local"

Controls how usage of a variable in the global scope is checked.

This option has two settings:

  1. all checks all variables for usage, including those in the global
    scope. This is the default setting.
  2. local checks only that locally-declared variables are used but will
    allow global variables to be unused.

"all"

All variables are checked for usage, including those in the global scope.

"local"

Checks only that locally-declared variables are used but will allow
global variables to be unused.

varsIgnorePattern

Specifies exceptions to this rule for unused variables. Variables whose
names match this pattern will be ignored.

By default, this pattern is ^_ unless options are configured with an
object. In this case it will default to [None]. Note that this
behavior deviates from both ESLint and TypeScript-ESLint, which never
provide a default pattern.

Example

Examples of correct code for this option when the pattern is ^_:

var _a = 10;
var b = 10;
console.log(b);

Copilot AI review requested due to automatic review settings December 20, 2025 21:23
@connorshea connorshea requested a review from camc314 as a code owner December 20, 2025 21:23
@github-actions github-actions bot added A-linter Area - Linter C-docs Category - Documentation. Related to user-facing or internal documentation labels Dec 20, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes and improves the configuration documentation for the no-unused-vars linter rule by enabling full schema generation for previously skipped options and correcting the serialization format for enum values.

Key changes:

  • Removes #[schemars(skip)] attributes from pattern fields (vars_ignore_pattern, args_ignore_pattern, caught_errors_ignore_pattern, destructured_array_ignore_pattern) to generate complete documentation
  • Changes enum serialization from camelCase to kebab-case for VarsOption, ArgsOption, and CaughtErrors to align with the actual parsing logic
  • Adds JsonSchema derive to IgnorePattern enum to support schema generation for pattern fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 20, 2025

CodSpeed Performance Report

Merging #17188 will not alter performance

Comparing docs-for-unused-vars (13976b6) with main (0f63e75)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (b2b87c6) during the generation of this report, so 0f63e75 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 self-assigned this Dec 21, 2025
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Dec 21, 2025
Copy link
Contributor

camc314 commented Dec 21, 2025

Merge activity

…17188)

Previously we were skipping the generation of config schema/docs for several options due to the previous Regex issues we had. Now that those are fixed, we should render the docs fully.

This also renders default values now, and fixes the casing of the values you can pass to the `args` option, which should always use kebab-case. It also fixes `caughtErrors`, which was listed as a boolean despite taking an enum.

The docs are below:

-----

## Configuration

This rule accepts a configuration object with the following properties:

### args

type: `"after-used" | "all" | "none"`

Controls how unused arguments are checked.

This option has three settings:

1. `after-used` - Unused positional arguments that occur before the last
   used argument will not be checked, but all named arguments and all
   positional arguments after the last used argument will be checked.
   This is the default setting.
2. `all` - All named arguments must be used.
3. `none` - Do not check arguments.

#### `"after-used"`

Unused positional arguments that occur before the last used argument
will not be checked, but all named arguments and all positional
arguments after the last used argument will be checked.

#### `"all"`

All named arguments must be used

#### `"none"`

Do not check arguments

### argsIgnorePattern

Specifies exceptions to this rule for unused arguments. Arguments whose
names match this pattern will be ignored.

By default, this pattern is `^_` unless options are configured with an
object. In this case it will default to [`None`]. Note that this
behavior deviates from both ESLint and TypeScript-ESLint, which never
provide a default pattern.

#### Example

Examples of **correct** code for this option when the pattern is `^_`:

```javascript
function foo(_a, b) {
  console.log(b);
}
foo(1, 2);
```

### caughtErrors

type: `"all" | "none"`

Used for `catch` block validation.

It has two settings:

- `none` - do not check error objects. This is the default setting.
- `all` - all named arguments must be used.

`none` corresponds to `false`, while `all` corresponds to `true`.

### caughtErrorsIgnorePattern

Specifies exceptions to this rule for errors caught within a `catch` block.
Variables declared within a `catch` block whose names match this pattern
will be ignored.

#### Example

Examples of **correct** code when the pattern is `^ignore`:

```javascript
try {
  // ...
} catch (ignoreErr) {
  console.error("Error caught in catch block");
}
```

### destructuredArrayIgnorePattern

This option specifies exceptions within destructuring patterns that will
not be checked for usage. Variables declared within array destructuring
whose names match this pattern will be ignored.

By default this pattern is unset.

#### Example

Examples of **correct** code for this option, when the pattern is `^_`:

```javascript
const [a, _b, c] = ["a", "b", "c"];
console.log(a + c);

const {
  x: [_a, foo],
} = bar;
console.log(foo);

let _m, n;
foo.forEach((item) => {
  [_m, n] = item;
  console.log(n);
});
```

### ignoreClassWithStaticInitBlock

type: `boolean`

default: `false`

The `ignoreClassWithStaticInitBlock` option is a boolean. Static
initialization blocks allow you to initialize static variables and
execute code during the evaluation of a class definition, meaning
the static block code is executed without creating a new instance
of the class. When set to `true`, this option ignores classes
containing static initialization blocks.

#### Example

Examples of **incorrect** code for the `{ "ignoreClassWithStaticInitBlock": true }` option

```javascript
/* no-unused-vars: ["error", { "ignoreClassWithStaticInitBlock": true }]*/

class Foo {
  static myProperty = "some string";
  static mymethod() {
    return "some string";
  }
}

class Bar {
  static {
    let baz; // unused variable
  }
}
```

Examples of **correct** code for the `{ "ignoreClassWithStaticInitBlock": true }` option

```javascript
/* no-unused-vars: ["error", { "ignoreClassWithStaticInitBlock": true }]*/

class Foo {
  static {
    let bar = "some string";

    console.log(bar);
  }
}
```

### ignoreRestSiblings

type: `boolean`

default: `false`

Using a Rest property it is possible to "omit" properties from an
object, but by default the sibling properties are marked as "unused".
With this option enabled the rest property's siblings are ignored.

#### Example

Examples of **correct** code when this option is set to `true`:

```js
// 'foo' and 'bar' were ignored because they have a rest property sibling.
var { foo, ...coords } = data;

var bar;
({ bar, ...coords } = data);
```

### ignoreUsingDeclarations

type: `boolean`

default: `false`

When set to `true`, the rule will ignore variables declared with
`using` or `await using` declarations, even if they are unused.

This is useful when working with resources that need to be disposed
via the explicit resource management proposal, where the primary
purpose is the disposal side effect rather than using the resource.

#### Example

Examples of **correct** code for the `{ "ignoreUsingDeclarations": true }` option:

```javascript
/* no-unused-vars: ["error", { "ignoreUsingDeclarations": true }]*/

using resource = getResource();
await using anotherResource = getAnotherResource();
```

### reportUsedIgnorePattern

type: `boolean`

default: `false`

The `reportUsedIgnorePattern` option is a boolean.
Using this option will report variables that match any of the valid
ignore pattern options (`varsIgnorePattern`, `argsIgnorePattern`,
`caughtErrorsIgnorePattern`, or `destructuredArrayIgnorePattern`) if
they have been used.

#### Example

Examples of **incorrect** code for the `{ "reportUsedIgnorePattern": true }` option:

```javascript
/* no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVarIgnored = 1;
var secondVar = 2;
console.log(firstVarIgnored, secondVar);
```

Examples of **correct** code for the `{ "reportUsedIgnorePattern": true }` option:

```javascript
/* no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVar = 1;
var secondVar = 2;
console.log(firstVar, secondVar);
```

### reportVarsOnlyUsedAsTypes

type: `boolean`

default: `false`

The `reportVarsOnlyUsedAsTypes` option is a boolean.

If `true`, the rule will also report variables that are only used as types.

#### Examples

Examples of **incorrect** code for the `{ "reportVarsOnlyUsedAsTypes": true }` option:

```javascript
/*  no-unused-vars: ["error", { "reportVarsOnlyUsedAsTypes": true }] */

const myNumber: number = 4;
export type MyNumber = typeof myNumber
```

Examples of **correct** code for the `{ "reportVarsOnlyUsedAsTypes": true }` option:

```javascript
export type MyNumber = number;
```

Note: even with `{ "reportVarsOnlyUsedAsTypes": false }`, cases where the value is
only used a type within itself will still be reported:

```javascript
function foo(): typeof foo {}
```

### vars

type: `"all" | "local"`

Controls how usage of a variable in the global scope is checked.

This option has two settings:

1. `all` checks all variables for usage, including those in the global
   scope. This is the default setting.
2. `local` checks only that locally-declared variables are used but will
   allow global variables to be unused.

#### `"all"`

All variables are checked for usage, including those in the global scope.

#### `"local"`

Checks only that locally-declared variables are used but will allow
global variables to be unused.

### varsIgnorePattern

Specifies exceptions to this rule for unused variables. Variables whose
names match this pattern will be ignored.

By default, this pattern is `^_` unless options are configured with an
object. In this case it will default to [`None`]. Note that this
behavior deviates from both ESLint and TypeScript-ESLint, which never
provide a default pattern.

#### Example

Examples of **correct** code for this option when the pattern is `^_`:

```javascript
var _a = 10;
var b = 10;
console.log(b);
```
@graphite-app graphite-app bot force-pushed the docs-for-unused-vars branch from 13976b6 to 9b10c80 Compare December 21, 2025 14:05
@graphite-app graphite-app bot merged commit 9b10c80 into main Dec 21, 2025
20 checks passed
@graphite-app graphite-app bot deleted the docs-for-unused-vars branch December 21, 2025 14:10
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-docs Category - Documentation. Related to user-facing or internal documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants