Skip to content
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 prevent-abbreviations fixer bug #444

Merged
merged 3 commits into from Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions rules/prevent-abbreviations.js
Expand Up @@ -366,8 +366,17 @@ const shouldFix = variable => {

const isShorthandPropertyIdentifier = identifier => {
return identifier.parent.type === 'Property' &&
identifier.parent.key === identifier &&
identifier.parent.shorthand;
identifier.parent.shorthand &&
(
identifier.parent.key === identifier ||
// In `babel-eslint` parent.key is not reference of identifier
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue about this on babel-eslint? The point of that package is to normalize the AST.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, we might not do this check, I've found other cases also broken, let me have a look at their repo first

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m ok with working around it, but we should always also try to get it fixed upstream.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a code comment with a link to the Babel-eslint issue.

(
identifier.parent.key.type === identifier.type &&
identifier.parent.key.name === identifier.name &&
identifier.parent.key.start === identifier.start &&
fisker marked this conversation as resolved.
Show resolved Hide resolved
identifier.parent.key.end === identifier.end
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much experience on those ASTs, I'm not sure if this is good

);
};

const isAssignmentPatternShorthandPropertyIdentifier = identifier => {
Expand Down
19 changes: 18 additions & 1 deletion test/prevent-abbreviations.js
Expand Up @@ -643,6 +643,12 @@ ruleTester.run('prevent-abbreviations', rule, {
options: customOptions,
errors: createErrors()
},
{
code: 'err => ({err})',
output: 'error => ({err: error})',
options: customOptions,
errors: createErrors()
},
{
code: 'const {err} = foo;',
output: 'const {err: error} = foo;',
Expand Down Expand Up @@ -1389,8 +1395,19 @@ babelRuleTester.run('prevent-abbreviations', rule, {
}
`
],

invalid: [
{
code: '({err}) => err',
output: '({err: error}) => error',
options: customOptions,
errors: createErrors()
},
{
code: 'err => ({err})',
output: 'error => ({err: error})',
options: customOptions,
errors: createErrors()
},
{
code: 'Foo.customProps = {}',
options: checkPropertiesOptions,
Expand Down