Bug: no-useless-assignment false positive in try-catch block #19245
Open
Description
opened on Dec 15, 2024
Environment
Node version: v22.11.0
npm version: v10.9.0
Local ESLint version: v9.17.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 24.1.0
What parser are you using?
@typescript-eslint/parser
What did you do?
Configuration
// eslint.config.js
export default [
{
rules: {
"no-useless-assignment": "warn"
},
},
];
async function fn() {
let intermediaryValue;
try {
intermediaryValue = 42;
unsafeFn();
return { error: undefined };
} catch {
return { intermediaryValue };
}
}
function unsafeFn() {
throw new Error();
}
What did you expect to happen?
The intermediaryValue = 42
statement shouldn’t be flagged by the 'no-useless-assignment' rule, as it’s being used in the catch
block.
What actually happened?
intermediaryValue = 42
was flagged as ‘not used in subsequent statements’ by mistake.
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
Metadata
Assignees
Labels
Type
Projects
Status
Ready to Implement
Activity