Skip to content

Commit

Permalink
feat(eslint-plugin): [no-unused-vars] align catch behavior to ESLint 9 (
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Apr 26, 2024
1 parent 21abb00 commit 67fbca5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/eslint-plugin/src/rules/no-unused-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default createRule<Options, MessageIds>({
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
caughtErrors: 'none',
caughtErrors: 'all',
};

if (typeof firstOption === 'string') {
Expand Down Expand Up @@ -245,9 +245,7 @@ export default createRule<Options, MessageIds>({
) {
continue;
}
}

if (def.type === TSESLint.Scope.DefinitionType.Parameter) {
} else if (def.type === TSESLint.Scope.DefinitionType.Parameter) {
// if "args" option is "none", skip any parameter
if (options.args === 'none') {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ foo();
doSomething();
})();
`,
`
{
code: `
try {
} catch (e) {}
`,
`,
options: [{ caughtErrors: 'none' }],
},
'/*global a */ a;',
{
code: `
Expand Down Expand Up @@ -925,7 +928,7 @@ try {
try {
} catch (err) {}
`,
options: [{ vars: 'all', args: 'all' }],
options: [{ vars: 'all', args: 'all', caughtErrors: 'none' }],
},

// Using object rest for variable omission
Expand Down Expand Up @@ -2235,6 +2238,22 @@ try {
definedError('err', '. Allowed unused args must match /^ignore/u'),
],
},
{
code: `
try {
} catch (err) {}
`,
options: [{ caughtErrors: 'all', varsIgnorePattern: '^err' }],
errors: [definedError('err', '. Allowed unused vars must match /^err/u')],
},
{
code: `
try {
} catch (err) {}
`,
options: [{ caughtErrors: 'all', varsIgnorePattern: '^.' }],
errors: [definedError('err', '. Allowed unused vars must match /^./u')],
},

// multiple try catch with one success
{
Expand Down

0 comments on commit 67fbca5

Please sign in to comment.