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

prefer-destructuring says "Use destructuring" on "super" #9625

Closed
gjbkz opened this issue Nov 15, 2017 · 3 comments · Fixed by #9626
Closed

prefer-destructuring says "Use destructuring" on "super" #9625

gjbkz opened this issue Nov 15, 2017 · 3 comments · Fixed by #9626
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@gjbkz
Copy link
Contributor

gjbkz commented Nov 15, 2017

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:

Configuration
const config = {
    parserOptions: {
        ecmaVersion: 6,
    },
    rules: {
        'prefer-destructuring': ['warn'],
    },
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

// 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);
}
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 }
@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 15, 2017
@aladdin-add aladdin-add added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Nov 15, 2017
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 15, 2017
@not-an-aardvark
Copy link
Member

Thanks for reporting, I can reproduce this issue.

@igidas
Copy link

igidas commented Nov 19, 2017

Also I get "ESlint: Use array destructing. (prefer-destructing)" error with 'this':
this.searchType = this.searchOptions[0];

@gjbkz
Copy link
Contributor Author

gjbkz commented Nov 20, 2017

@igidas [this.searchType] = this.searchOptions is valid syntax and prefer-destructuring's suggestion is right.
Here's an example: https://runkit.com/kei-ito/destructuring-assignment

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 19, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants