Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: no-unused-vars varsIgnorePattern behavior with catch arguments #17932

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/src/use/migrate-to-9.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The lists below are ordered roughly by the number of users each change is expect
* [Case-sensitive flags in `no-invalid-regexp`](#no-invalid-regexp)
* [Stricter `/* exported */` parsing](#exported-parsing)
* [`"eslint:recommended"` and `"eslint:all"` strings no longer accepted in flat config](#string-config)
* [Behavior of `varsIgnorePattern` option of `no-unused-vars` rule with catch arguments](#vars-ignore-pattern)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [Behavior of `varsIgnorePattern` option of `no-unused-vars` rule with catch arguments](#vars-ignore-pattern)
* [`varsIgnorePattern` option of `no-unused-vars` no longer applies to catch arguments](#vars-ignore-pattern)


### Breaking changes for plugin developers

Expand Down Expand Up @@ -236,6 +237,25 @@ export default [

**Related issue(s):** [#17488](https://github.com/eslint/eslint/issues/17488)

## <a name="vars-ignore-pattern"></a> Behavior of `varsIgnorePattern` option of `no-unused-vars` rule with catch arguments
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## <a name="vars-ignore-pattern"></a> Behavior of `varsIgnorePattern` option of `no-unused-vars` rule with catch arguments
## <a name="vars-ignore-pattern"></a> `varsIgnorePattern` option of `no-unused-vars` no longer applies to catch arguments


In previous versions of ESLint, `varsIgnorePattern` option of `no-unused-vars`, that is used to restrict some specified variable to be reported, used to ignore all variables that machtes the specified pattern except `function` arguments because there is a seperate option to ignore them called `argsIgnorePattern` and same was expected for `caughtErrorsIgnorePattern` option but `varsIgnorePattern` was also ignoring `catch` block arguments.

This behavior has been fixed in ESLint v9.0.0, that means `varsIgnorePattern` option don't get applied to both `function` and `catch` block arguments.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In previous versions of ESLint, `varsIgnorePattern` option of `no-unused-vars`, that is used to restrict some specified variable to be reported, used to ignore all variables that machtes the specified pattern except `function` arguments because there is a seperate option to ignore them called `argsIgnorePattern` and same was expected for `caughtErrorsIgnorePattern` option but `varsIgnorePattern` was also ignoring `catch` block arguments.
This behavior has been fixed in ESLint v9.0.0, that means `varsIgnorePattern` option don't get applied to both `function` and `catch` block arguments.
In previous versions of ESLint, the `varsIgnorePattern` option of `no-unused-vars` incorrectly ignored errors specified in a `catch` clause. In ESLint v9.0.0, `varsIgnorePattern` no longer applies to errors in `catch` clauses. For example:


```js
/*eslint no-unused-vars: ["error", { "caughtErrors": "all", "varsIgnorePattern": "^err" }]*/

try {
//...
} catch (err) { // 'err' will be reported.
console.error("errors");
}

```

**Related issue(s):** [#17540](https://github.com/eslint/eslint/issues/17540)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
**Related issue(s):** [#17540](https://github.com/eslint/eslint/issues/17540)
**To address:** If you want to specify ignore patterns for `catch` clause variable names, use the `caughtErrorsIgnorePattern` option in addition to `varsIgnorePattern`.
**Related issue(s):** [#17540](https://github.com/eslint/eslint/issues/17540)


## <a name="removed-context-methods"></a> Removed multiple `context` methods

ESLint v9.0.0 removes multiple deprecated methods from the `context` object and moves them onto the `SourceCode` object:
Expand Down