fix!: no-unused-vars varsIgnorePattern behavior with catch arguments#17932
fix!: no-unused-vars varsIgnorePattern behavior with catch arguments#17932mdjermanovic merged 5 commits intoeslint:mainfrom
varsIgnorePattern behavior with catch arguments#17932Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
varsIgnorePattern behaviorvarsIgnorePattern behavior with catch arguments
nzakas
left a comment
There was a problem hiding this comment.
LGTM. Would like @mdjermanovic to review before merging.
|
Oops, one more request: because this is a breaking change, can you please add an entry into migrate-to-9.0.0.md under the "Breaking Changes for Users" section? |
nzakas
left a comment
There was a problem hiding this comment.
Looking good. Just cleaned up the wording on the migration guide with a few suggestions.
| * [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) |
There was a problem hiding this comment.
| * [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) |
|
|
||
| **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 |
There was a problem hiding this comment.
| ## <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. |
There was a problem hiding this comment.
| 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: |
|
|
||
| ``` | ||
|
|
||
| **Related issue(s):** [#17540](https://github.com/eslint/eslint/issues/17540) |
There was a problem hiding this comment.
| **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) |
snitin315
left a comment
There was a problem hiding this comment.
LGTM, thanks!
we could also add
"none"value to vars setting, just like args and catchErrors
The original issue also mentions adding "none" for vars, should we support this?
I think that should be a separate issue. |
varsIgnorePattern behavior with catch argumentsvarsIgnorePattern behavior with catch arguments
Upgrade to eslint v9 flat config. Custom eslint rules have been tested and work in the new config file. Removed unused vars in try catch blocks due to[ breaking change in eslint v9](eslint/eslint#17932). Use [globals](https://www.npmjs.com/package/globals) to include [globals env](https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables)
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Tell us about your environment (
npx eslint --env-info):What parser are you using (place an "X" next to just one item)?
[x]
Default (Espree)[ ]
@typescript-eslint/parser[ ]
@babel/eslint-parser[ ]
vue-eslint-parser[ ]
@angular-eslint/template-parser[ ]
OtherPlease show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
eslint won't ignore the
errargument.What actually happened? Please include the actual, raw output from ESLint.
eslint ignored the
errargument by following thevarsIgnorePattern.Fixes: #17540