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.

False positive expected indentation NaN when disabling ObjectExpressions

See original GitHub issue
  • ESLint Version: 4.1.1
  • Node Version: 8.1.3
  • npm Version: 5.3.0 What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration

In a package.json:

  "eslintConfig": {
    "extends": "eslint:recommended",
    "env": {
      "node": true,
      "mocha": true,
      "es6": true
    },
    "rules": {
      "indent": [
        "error",
        2,
        {
          "ObjectExpression": "off"
        }
      ]
    }
  }

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

The above config attempts to disable ESLint indent checks in objects specifically, keeping them for everything else.

function thing(string) {
  const result = where({
    or: [{
      field1: 'value1'
    }, {
      field2: 'value2', field3: 'value3'
    }, {
      field4: 'value4'
    }]
  });
}

What did you expect to happen?

There should be no error messages regarding indentation in the where call.

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

  5:1   error  Expected indentation of NaN spaces but found 4  indent
  7:1   error  Expected indentation of NaN spaces but found 4  indent
  9:1   error  Expected indentation of NaN spaces but found 4  indent

Notably, 4 is the “correct” indentation level without any special rule configuration, so something’s going on with toggling ObjectExpressions “off”. Disabling the if in the ignoreToken function of lib/rules/indent.js turns the NaN into an actual number, but it’s the wrong one and also causes a ton of other false positives so it’s not just that.

I tried disabling ArrayExpressions and CallExpressions as well, to no avail; this is specifically an issue with ObjectExpressions.

Possibly related:

#8552

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Sep 2, 2017

This is working as intended based on https://github.com/eslint/eslint/issues/9194#issuecomment-326638820. To disable checking for this in ESLint 4.5.0+, you should be able to use the ignoredNodes: ["ObjectExpression"] option.

0reactions
dmfaycommented, Sep 1, 2017

Yes – hence trying to disable ObjectExpression/ArrayExpression, so I can get indent checks elsewhere but ignore them inside complex objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[@typescript-eslint/indent] False positive on chained calls in ...
Only the indentation on lines 2-3 seems to trigger the error. Similar indentation used on lines 6-7 does not trigger the error. The...
Read more >
Rules — yamllint 1.28.0 documentation
check-multi-line-strings defines whether to lint indentation in multi-line strings. Set to true to enable, false to disable. Default values (when enabled).
Read more >
yamllint - Read the Docs
Set to true to enable, false to disable. Default values (when enabled) rules: indentation: spaces: consistent indent-sequences ...
Read more >
"NaN" should not be used in comparisons - SonarSource Rules
Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string. Code Smell ...
Read more >
Suppression of false positive warnings - PVS-Studio
This section describes analyzer′s false positives suppression features ... How to enable and disable certain diagnostics for a block of code ...
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