Environment
playground
What parser are you using?
Default (Espree)
What did you do?
Configuration
["warn", { "caughtErrorsIgnorePattern" : "foo" }]
try {
} catch (_) {
_ = 'foo'
}
What did you expect to happen?
'_' is assigned a value but never used. Allowed unused caught errors must match /foo/u
What actually happened?
'_' is assigned a value but never used.
Link to Minimal Reproducible Example
https://eslint.org/play/#eyJ0ZXh0IjoidHJ5IHtcbn0gY2F0Y2ggKF9mKSB7IFxuICBsZXQgXztcbiAgXyA9ICdmb28nXG59Iiwib3B0aW9ucyI6eyJydWxlcyI6eyJuby11bnVzZWQtdmFycyI6WyJ3YXJuIix7ImNhdWdodEVycm9yc0lnbm9yZVBhdHRlcm4iOiJmb28ifV19LCJsYW5ndWFnZU9wdGlvbnMiOnsic291cmNlVHlwZSI6Im1vZHVsZSIsInBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=
Participation
Additional comments
There's just lack of parity between
|
function getDefinedMessageData(unusedVar) { |
|
const def = unusedVar.defs && unusedVar.defs[0]; |
|
let additionalMessageData = ""; |
|
|
|
if (def) { |
|
let pattern; |
|
let variableDescription; |
|
|
|
switch (def.type) { |
|
case "CatchClause": |
|
if (config.caughtErrorsIgnorePattern) { |
|
[variableDescription, pattern] = getVariableDescription("catch-clause"); |
|
} |
|
break; |
|
|
|
case "Parameter": |
|
if (config.argsIgnorePattern) { |
|
[variableDescription, pattern] = getVariableDescription("parameter"); |
|
} |
|
break; |
|
|
|
default: |
|
if (config.varsIgnorePattern) { |
|
[variableDescription, pattern] = getVariableDescription("variable"); |
|
} |
|
break; |
|
} |
|
|
|
if (pattern && variableDescription) { |
|
additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`; |
|
} |
|
} |
|
|
|
return { |
|
varName: unusedVar.name, |
|
action: "defined", |
|
additional: additionalMessageData |
|
}; |
|
} |
, which considers catch clause, and
|
function getAssignedMessageData(unusedVar) { |
|
const def = unusedVar.defs && unusedVar.defs[0]; |
|
let additionalMessageData = ""; |
|
|
|
if (def) { |
|
let pattern; |
|
let variableDescription; |
|
|
|
if (def.name.parent.type === "ArrayPattern" && config.destructuredArrayIgnorePattern) { |
|
[variableDescription, pattern] = getVariableDescription("array-destructure"); |
|
} else if (config.varsIgnorePattern) { |
|
[variableDescription, pattern] = getVariableDescription("variable"); |
|
} |
|
|
|
if (pattern && variableDescription) { |
|
additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`; |
|
} |
|
} |
|
|
|
return { |
|
varName: unusedVar.name, |
|
action: "assigned a value", |
|
additional: additionalMessageData |
|
}; |
|
} |
, which doesn't
See also #18606
Environment
playground
What parser are you using?
Default (Espree)
What did you do?
Configuration
What did you expect to happen?
'_' is assigned a value but never used. Allowed unused caught errors must match /foo/u
What actually happened?
'_' is assigned a value but never used.
Link to Minimal Reproducible Example
https://eslint.org/play/#eyJ0ZXh0IjoidHJ5IHtcbn0gY2F0Y2ggKF9mKSB7IFxuICBsZXQgXztcbiAgXyA9ICdmb28nXG59Iiwib3B0aW9ucyI6eyJydWxlcyI6eyJuby11bnVzZWQtdmFycyI6WyJ3YXJuIix7ImNhdWdodEVycm9yc0lnbm9yZVBhdHRlcm4iOiJmb28ifV19LCJsYW5ndWFnZU9wdGlvbnMiOnsic291cmNlVHlwZSI6Im1vZHVsZSIsInBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=
Participation
Additional comments
There's just lack of parity between
eslint/lib/rules/no-unused-vars.js
Lines 200 to 238 in 97ce45b
, which considers catch clause, and
eslint/lib/rules/no-unused-vars.js
Lines 246 to 270 in 97ce45b
, which doesn't
See also #18606