Skip to content

Commit

Permalink
Fix prevent-abbreviations fixer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 27, 2019
1 parent 3554c17 commit 49e8010
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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 not reference of identifier
(
identifier.parent.key.type === identifier.type &&
identifier.parent.key.name === identifier.name &&
identifier.parent.key.start === identifier.start &&
identifier.parent.key.end === identifier.end
)
);
};

const isAssignmentPatternShorthandPropertyIdentifier = identifier => {
Expand Down
18 changes: 17 additions & 1 deletion test/prevent-abbreviations.js
Expand Up @@ -643,6 +643,11 @@ ruleTester.run('prevent-abbreviations', rule, {
options: customOptions,
errors: createErrors()
},
{
code: 'err => ({err})',
output: 'error => ({err: error})',
errors: createErrors()
},
{
code: 'const {err} = foo;',
output: 'const {err: error} = foo;',
Expand Down Expand Up @@ -1389,8 +1394,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

0 comments on commit 49e8010

Please sign in to comment.