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.

5.0.0 - Crash with prefer-const rule where code contains array destructuring assignment with 'ignored values'

See original GitHub issue

This is a minimal reproduction for a bug I’ve found in eslint@5.0.0. As far as I can tell the example code below is valid JavaScript (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Ignoring_some_returned_values).

Tell us about your environment

  • ESLint Version: 5.0.0
  • Node Version: 8.11.0
  • npm Version: 5.6.0
  • yarn Version: 1.7.0

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

Please show your full configuration:

{
    "parserOptions": {
        "ecmaVersion": 2018
    },
    "rules": {
      "prefer-const": 1
    }
}

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

const b = [1, 2];
let a;

[, a] = b;

cd eslint-5-array-destructuring-assignment-bug
yarn eslint .

What did you expect to happen? eslint would lint my project

What actually happened? Please include the actual, raw output from ESLint. eslint did not lint my project and threw a TypeError from one of its built-in rules (prefer-const)

Cannot read property 'name' of null
TypeError: Cannot read property 'name' of null
    at elements.map.element (/node_modules/eslint/lib/rules/prefer-const.js:173:49)
    at Array.map (<anonymous>)
    at getIdentifierIfShouldBeConst (/node_modules/eslint/lib/rules/prefer-const.js:173:26)
    at groupByDestructuring (/node_modules/eslint/lib/rules/prefer-const.js:227:28)
    at Program:exit (/node_modules/eslint/lib/rules/prefer-const.js:362:17)
    at listeners.(anonymous function).forEach.listener (/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/node_modules/eslint/lib/util/node-event-generator.js:280:22)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jun 25, 2018

Thanks @mjmasn, that makes sense. Would you like to create a PR (maybe with a new test that would trigger the crash)?

0reactions
aladdin-addcommented, Jun 26, 2018

should we release a patch 5.0.2, since seems it was introduced in 5.0.0-alpha.4? cc @eslint/eslint-team

Read more comments on GitHub >

github_iconTop Results From Across the Web

Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
How to fix Eslint error "prefer-destructuring"? - Stack Overflow
It's an ES6 feature used to unpack variables from arrays or objects. this syntax create an array from variables: var x = [y,...
Read more >
eslint/CHANGELOG.md - UNPKG
88, * 601a5c4 Fix: Prefer-const rule crashing on array destructuring (fixes ... 106, * 4c823bd Docs: Fix max-lines-per-function correct code's max value ......
Read more >
node_modules/eslint/CHANGELOG.md · master - PLMlab
Repository · c5c7086 Fix: ignore aligning single line in key-spacing (fixes #11414) (#12652) (YeonJuan) · 9986d9e Chore: add object option test ...
Read more >
node_modules/eslint-plugin-react/CHANGELOG.md · master ...
jsx-no-constructed-context-values : avoid a crash with as X TS code (#2894 ... destructuring-assignment : fix a false positive for local prop named context ......
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