question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linter wants previously declared variable destructured during assignment

See original GitHub issue

Tell us about your environment Windows 10

  • ESLint Version: v4.12.0
  • Node Version: v8.9.1
  • npm Version: 5.5.

What parser (default, Babel-ESLint, etc.) are you using? eslint

Please show your full configuration:

Configuration
{
  "env": {
    "es6": true,
    "node": true,
    "browser": true
  },
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": 8
  },
  "rules": {
    "prefer-destructuring": ["error", {
      "VariableDeclarator": {
        "array": true,
        "object": true
      },
      "AssignmentExpression": {
        "array": true,
        "object": true
      }
    }, {
      "enforceForRenamedProperties": false
    }]
  }
}

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

function potato(b) {
  let a;
  if(b) {
    a = b.a;
  }

  doThing(a); //Where a being undefined or not affects the downstream.
}

eslint .

What did you expect to happen? No error or warning.

What actually happened? Please include the actual, raw output from ESLint.

..path...\test.js
  5:5  error  Use object destructuring  prefer-destructuring

✖ 1 problem (1 error, 0 warnings)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Nov 28, 2017

Unfortunately, since that’s a parsing error, the lint rules can’t even run at that point. I’m not aware of a good way to catch that and report a user-friendly message explaining the need for parentheses… Sorry.

On Nov 28, 2017 10:08 AM, “Krishna Glick” notifications@github.com wrote:

Ah, that fixed it. Is there a linting rule to yell about that, or more a don’t be dumb kinda thing? 😃

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/9661#issuecomment-347573287, or mute the thread https://github.com/notifications/unsubscribe-auth/AARWeoXgan2EnTplZjLHGbEsou0qXtieks5s7DASgaJpZM4QtdgW .

0reactions
krishnaglickcommented, Nov 28, 2017

Ah, that fixed it. Is there a linting rule to yell about that, or more a don't be dumb kinda thing? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prefer destructuring - already exisiting variable - Stack Overflow
Is there any ways to use destructuration when the variable already exists? Using let again : const data = { status: 'example', }; ......
Read more >
prefer-destructuring - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
Each destructured property is assigned to a target of assignment — which may either be declared beforehand with var or let , or...
Read more >
Many ways to use Destructuring in Modern JavaScript - Medium
It's main purpose is to improve your code and simplify it at the ... Before Destructuring if we wanted to create a variable...
Read more >
CoffeeScript
In that case, we want to convert modern JavaScript into older JavaScript that will ... Since CoffeeScript takes care of all variable declaration,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found