Repository: sindresorhus/eslint-plugin-unicorn (JavaScript)

Issue:
`prevent-abbreviations` should not try to fix variable names when they're being destructured
First off, I think this is a great library with a lot of excellent rules and really appreciate all the work on it.

I was working on implementing some of the rules for my team and I ran an autofix and saw this change in my git diff:

![image](https://user-images.githubusercontent.com/22530815/60280641-f272c600-98c8-11e9-90ef-0c344f5f41bc.png)

In this case, it would definitely introduce a bug since there 's no 'development' variable being passed.

While I think this autofix is generally pretty safe, i think it might be good to check if the current scope includes destructuring and avoid autofixing.

I can look into working on a PR for this myself (i've been interested in learning how to work on eslint rules), just wanted to point this out and see if i can help out.
`prevent-abbreviations` fixer bug on deconstructing
just run `prevent-abbreviations` against a large code base, found two fixer bug

input:

```js
const foo = ({num}) => num;
const bar = num => ({num});
```

fix:

```js
const foo = ({number}) => number;
const bar = number => ({number});
```

expect:

```js
const foo = ({num: number}) => number;
const bar = number => ({num: number});
```





Discussion:
The fix should probably be (or just a warning with no fix):

```
webpack: (config, { dev: development, buildId }) => {
```


Strange, we have a test case which is expected to cover this:
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/c2b8e76fb20f6ec087d3338225a626836d5e3810/test/prevent-abbreviations.js#L577-L578
@futpib I can take a look at that test case and see why my situation might be some weird exception.

@sindresorhus i'll go ahead and start looking into this, if you'd be able to assign this to me that would be great. thank you!

just found #330 is one of these two
only report when using `babel-eslint` parser
another bug, only on `babel-eslint` parser

```js
function unicorn(unicorn) {
  const {prop = {}} = unicorn;
  return prop;
}
```

fix to 

```js
function unicorn(unicorn) {
  const {property = {}} = unicorn;
  return property;
}
```

should be

```js
function unicorn(unicorn) {
  const {prop: property = {}} = unicorn;
  return property;
}
```





Patch:
diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js
index 8c4e43123b..dff5c59090 100644
--- a/rules/prevent-abbreviations.js
+++ b/rules/prevent-abbreviations.js
@@ -364,17 +364,26 @@ const shouldFix = variable => {
 	return !variableIdentifiers(variable).some(isExportedIdentifier);
 };
 
+const isIdentifierKeyOfNode = (identifier, node) =>
+	node.key === identifier ||
+	// In `babel-eslint` parent.key is not reference of identifier
+	// https://github.com/babel/babel-eslint/issues/809
+	(
+		node.key.type === identifier.type &&
+		node.key.name === identifier.name
+	);
+
 const isShorthandPropertyIdentifier = identifier => {
 	return identifier.parent.type === 'Property' &&
-		identifier.parent.key === identifier &&
-		identifier.parent.shorthand;
+		identifier.parent.shorthand &&
+		isIdentifierKeyOfNode(identifier, identifier.parent);
 };
 
 const isAssignmentPatternShorthandPropertyIdentifier = identifier => {
 	return identifier.parent.type === 'AssignmentPattern' &&
 		identifier.parent.left === identifier &&
 		identifier.parent.parent.type === 'Property' &&
-		identifier.parent.parent.key === identifier &&
+		isIdentifierKeyOfNode(identifier, identifier.parent.parent) &&
 		identifier.parent.parent.value === identifier.parent &&
 		identifier.parent.parent.shorthand;
 };


Test patch:
diff --git a/test/prevent-abbreviations.js b/test/prevent-abbreviations.js
index e7724fdd8b..279309cb2b 100644
--- a/test/prevent-abbreviations.js
+++ b/test/prevent-abbreviations.js
@@ -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;',
@@ -1389,8 +1395,34 @@ babelRuleTester.run('prevent-abbreviations', rule, {
 			}
 		`
 	],
-
 	invalid: [
+		{
+			code: outdent`
+				function unicorn(unicorn) {
+					const {prop = {}} = unicorn;
+					return property;
+				}
+			`,
+			output: outdent`
+				function unicorn(unicorn) {
+					const {prop: property = {}} = unicorn;
+					return property;
+				}
+			`,
+			errors: createErrors()
+		},
+		{
+			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,