diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js index 8c4e43123b..d616f23c68 100644 --- a/rules/prevent-abbreviations.js +++ b/rules/prevent-abbreviations.js @@ -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 + ( + 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 => { diff --git a/test/prevent-abbreviations.js b/test/prevent-abbreviations.js index e7724fdd8b..e96cac6d83 100644 --- a/test/prevent-abbreviations.js +++ b/test/prevent-abbreviations.js @@ -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;', @@ -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,