Repository: eslint/eslint (js)

Issue:
prefer-destructuring says "Use destructuring" on "super"
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

    This template is for bug reports. If you are reporting a bug, please continue on. If you are here for another reason, please see below:

    1. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
    2. To request a change: https://eslint.org/docs/developer-guide/contributing/changes
    3. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint

    Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->

**Tell us about your environment**

* **ESLint Version: 4.11.0**
* **Node Version: v9.2.0**
* **npm Version: 5.5.1**

**What parser (default, Babel-ESLint, etc.) are you using?**
default

**Please show your full configuration:**
<details>
<summary>Configuration</summary>

<!-- Paste your configuration below: -->
```js
const config = {
    parserOptions: {
        ecmaVersion: 6,
    },
    rules: {
        'prefer-destructuring': ['warn'],
    },
};
```

</details>

**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**

<!-- Paste the source code below: -->
```js
// eslint-test.js
const code = `
class Node {
    static get inheritance() {
        return ['node'];
    }
}
class Element extends Node {
    static get inheritance() {
        const inheritance = super.inheritance;
        inheritance.push('element');
        return inheritance;
    }
}
console.log(Element.inheritance);
`;
const {Linter} = require('eslint');
const linter = new Linter();
const config = {
    parserOptions: {
        ecmaVersion: 6,
    },
    rules: {
        'prefer-destructuring': ['warn'],
    },
};
const messages = linter.verify(code, config);
for (const message of messages) {
    console.log(message);
}
```

<!-- Paste the command you used to run ESLint: -->
```bash
node ./eslint-test.js
```

**What did you expect to happen?**
I expect `prefer-destructuring` ignores the `const inheritance = super.inheritance;` statement.
`const {inheritance} = super` throws a SyntaxError.

**What actually happened? Please include the actual, raw output from ESLint.**
```
{ ruleId: 'prefer-destructuring',
  severity: 1,
  message: 'Use object destructuring.',
  line: 9,
  column: 15,
  nodeType: 'VariableDeclarator',
  source: '        const inheritance = super.inheritance;',
  endLine: 9,
  endColumn: 40 }
```


Pull request description:
Fix: prefer-destructuring says "Use destructuring" on "super" (#9625)
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[ ] Documentation update
[x] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

This fixes #9625 

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**
- `tests/lib/rules/prefer-destructuring.js`: I added a test to reproduce #9625 
- `lib/rules/prefer-destructuring.js`: I updated a line to fix #9625 

**Is there anything you'd like reviewers to focus on?**
No

Patch:
diff --git a/lib/rules/prefer-destructuring.js b/lib/rules/prefer-destructuring.js
index eeb5e060c..56c348a47 100644
--- a/lib/rules/prefer-destructuring.js
+++ b/lib/rules/prefer-destructuring.js
@@ -145,7 +145,7 @@ module.exports = {
          * @returns {void}
          */
         function performCheck(leftNode, rightNode, reportNode) {
-            if (rightNode.type !== "MemberExpression") {
+            if (rightNode.type !== "MemberExpression" || rightNode.object.type === "Super") {
                 return;
             }
 


Test patch:
diff --git a/tests/lib/rules/prefer-destructuring.js b/tests/lib/rules/prefer-destructuring.js
index 93cf62a3e..e60535e7e 100644
--- a/tests/lib/rules/prefer-destructuring.js
+++ b/tests/lib/rules/prefer-destructuring.js
@@ -130,7 +130,8 @@ ruleTester.run("prefer-destructuring", rule, {
         {
             code: "var foo = object.foo;",
             options: [{ VariableDeclarator: { object: false }, AssignmentExpression: { object: true } }]
-        }
+        },
+        "class Foo extends Bar { static foo() {var foo = super.foo} }"
     ],
 
     invalid: [
@@ -276,6 +277,13 @@ ruleTester.run("prefer-destructuring", rule, {
                 message: "Use object destructuring.",
                 type: "AssignmentExpression"
             }]
+        },
+        {
+            code: "class Foo extends Bar { static foo() {var bar = super.foo.bar} }",
+            errors: [{
+                message: "Use object destructuring.",
+                type: "VariableDeclarator"
+            }]
         }
     ]
 });