Fix: no-useless-rename invalid autofix with parenthesized identifiers#14032
Merged
Fix: no-useless-rename invalid autofix with parenthesized identifiers#14032
Conversation
nzakas
approved these changes
Jan 28, 2021
btmills
reviewed
Jan 30, 2021
mdjermanovic
commented
Jan 30, 2021
| * 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) { |
Member
Author
There was a problem hiding this comment.
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.
This was referenced Mar 5, 2021
This was referenced Mar 17, 2021
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-renamerule 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";