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

Setting "ArrayExpression": "off" in indent rule causes eslint to crash #9157

Closed
gpascale opened this issue Aug 25, 2017 · 3 comments
Closed
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 indent Relates to the `indent` rule rule Relates to ESLint's core rules

Comments

@gpascale
Copy link

Tell us about your environment

  • ESLint Version: 4.5.0 (tested various versions back to 4.0.0 and saw same issue)
  • Node Version: 6.9.1
  • npm Version: 3.10.8

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

default

Please show your full configuration:

Configuration
{
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "react",
    "json"
  ],
  "rules": {
    // want to add "ArrayExpression": "first" but eslint has a bug
    "indent": [ "error", 2, { "SwitchCase": 1, "flatTernaryExpressions": true, "ArrayExpression": "off", "ObjectExpression": "off" } ],
    "linebreak-style": [ "error", "unix" ],
    "quotes": [ "error", "single" ],
    "semi": [ "error", "always" ],
    "react/jsx-uses-vars": 1,
    "no-unused-vars": [ "warn", { "vars": "all" } ],
    "brace-style": [ "error", "stroustrup", { "allowSingleLine": true } ]
  }
}

What did you do? Please include the actual source code causing the issue.

I'm just running eslint on my small/medium sized node/react/es6 codebase. I can't tell exactly what part of my code is causing the problem because an error is happening in eslint itself.

What did you expect to happen?

The linter to run normally

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

Cannot read property 'range' of null
TypeError: Cannot read property 'range' of null
at SourceCode.getTokenBefore (/home/git/myproject/node_modules/eslint/lib/token-store/index.js:303:17)
at getFirstToken (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:784:40)
at elements.forEach (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:806:41)
at Array.forEach (native)
at addElementListIndent (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:804:22)
at Object.ArrayExpression, ArrayPattern [as listener] (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:965:17)
at Program:exit.listenerCallQueue.filter.forEach.nodeInfo (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:1444:55)
at Array.forEach (native)
at Linter.Program:exit (/home/git/myproject/node_modules/eslint/lib/rules/indent.js:1444:26)
at emitOne (events.js:101:20)
at Linter.emit (events.js:188:7)

NOTE:
The culprit here seems to be setting "ArrayExpression": "off". If I omit it or set it to "first", the linter runs as expected.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 25, 2017
@not-an-aardvark
Copy link
Member

Thanks for the report. This seems like it might be a bug, but it's hard to tell without having an example of code that causes the issue. The ArrayExpression: off option certainly works for some code, so I can't reproduce the problem based on the information you've provided.

If you add the --debug flag when running ESLint, it will print out some messages when it lints each file. If you look at the last few messages that get printed before the crash, it should be possible to determine which file was being linted when the crash occurred.

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion indent Relates to the `indent` rule rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 25, 2017
@gpascale
Copy link
Author

Thanks for the tip. Using --debug I was able to find the file where it was crashing and ultimately narrow it down to a single line. I verified that running eslint on a file containing nothing but this line will trigger the error.

const [, ...myArrayMinusOne] = myArray;

It's possible (read: probable) that I don't have eslint properly configured for all my babel/eswhatever nonsense, but regardless, it would of course be better if it didn't crash.

@not-an-aardvark
Copy link
Member

Thanks, I was able to reproduce this issue.

@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 Aug 27, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 26, 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 Feb 26, 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 indent Relates to the `indent` rule rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants