-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Environment
Node version: v18.13.0
npm version: v8.19.3
Local ESLint version: v8.33.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 22.2.0
What parser are you using?
Default (Espree)
What did you do?
Configuration
{
"parserOptions": {
"ecmaVersion": 2015
},
"rules": {
"no-extra-parens": [
"error"
]
}
}
let foo, bar;
(foo) = function () { };
(bar) = class { };
console.log(foo.name + bar.name);
What did you expect to happen?
ESLint should not remove the parentheses in (foo)
and (bar)
automatically. The parentheses are required to prevent the class or function from having its name
property set to the name of the variable.
What actually happened?
The parentheses around foo
and bar
are removed by the autofix. The resulting code prints foobar
instead of an empty string like the original code.
Participation
- I am willing to submit a pull request for this issue.
Additional comments
My suggestion is to disable the autofix for parentheses around a single identifier on the left side of an assignment when the right side contains an anonymous class or anonymous function. This would avoid unexpected changes in program behavior in some edge cases.
I can't decide if keeping the warning in the first place would be good or not.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status