5.0.0 - Crash with prefer-const rule where code contains array destructuring assignment with 'ignored values'
See original GitHub issueThis 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:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Thanks @mjmasn, that makes sense. Would you like to create a PR (maybe with a new test that would trigger the crash)?
should we release a patch
5.0.2
, since seems it was introduced in5.0.0-alpha.4
? cc @eslint/eslint-team