New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: no-useless-rename invalid autofix with parenthesized identifiers #14032
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/** | ||
* Properties using shorthand syntax and rest elements can not be renamed. | ||
* If the property is computed, we have no idea if a rename is useless or not. | ||
*/ | ||
if (property.shorthand || property.type === "RestElement" || property.computed) { | ||
if (property.type !== "Property" || property.shorthand || property.computed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change to be consistent with the condition in fix()
(where it expects only Property
or module specifiers), so checking for ExperimentalRestProperty
above became unnecessary.
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 autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Tell us about your environment
What parser (default,
@babel/eslint-parser
,@typescript-eslint/parser
, etc.) are you using?Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
Online Demo
What did you expect to happen?
2 errors, but not an invalid autofix.
What actually happened? Please include the actual, raw output from ESLint.
2 errors and autofix to:
{ a) }
is obviously a syntax error.{ (a) = 1 }
is also a syntax error, those parentheses are not allowed in shorthand properties.What changes did you make? (Give an overview)
Changed the
no-useless-rename
rule to correctly fix code such as{ a: (a) }
and avoid autofixing code such as{ a: (a) = 1 }
.Is there anything you'd like reviewers to focus on?
This change should be also helpful for future syntax tc39/ecma262#2154, like
export { "a b" as "a b" } from "foo";