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.

no-constant-condition reported error range is too broad

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.8.0
  • Node Version: 8.3.0
  • npm Version: 5.3.0

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

Please show your full configuration:

Configuration
{
  "rules": {
    "no-constant-condition": "error"
  }
}

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

if (true) {
  something();
}

something(true ? 1 : 0);

What did you expect to happen?

The reported error ranges should only include the constant conditions themselves. In the above cases, the words “true”.

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

The reported error ranges include the entire statement/expression that the constant condition is part of.

$ eslint test.js --format json | jq
[
  {
    "filePath": "/home/lydell/bugs/eslint/test.js",
    "messages": [
      {
        "ruleId": "no-constant-condition",
        "severity": 2,
        "message": "Unexpected constant condition.",
        "line": 1,
        "column": 1,
        "nodeType": "IfStatement",
        "source": "if (true) {",
        "endLine": 3,
        "endColumn": 2
      },
      {
        "ruleId": "no-constant-condition",
        "severity": 2,
        "message": "Unexpected constant condition.",
        "line": 5,
        "column": 11,
        "nodeType": "ConditionalExpression",
        "source": "something(true ? 1 : 0);",
        "endLine": 5,
        "endColumn": 23
      }
    ],
    "errorCount": 2,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "source": "if (true) {\n  something();\n}\n\nsomething(true ? 1 : 0);\n"
  }
]

Expected:

@@ -7,11 +7,11 @@
         "severity": 2,
         "message": "Unexpected constant condition.",
         "line": 1,
-        "column": 1,
+        "column": 5,
         "nodeType": "IfStatement",
         "source": "if (true) {",
-        "endLine": 3,
-        "endColumn": 2
+        "endLine": 1,
+        "endColumn": 9
       },
       {
         "ruleId": "no-constant-condition",
@@ -22,7 +22,7 @@
         "nodeType": "ConditionalExpression",
         "source": "something(true ? 1 : 0);",
         "endLine": 5,
-        "endColumn": 23
+        "endColumn": 15
       }
     ],
     "errorCount": 2,

Note: I don’t know how the reported "source" properties are supposed to work, so I can’t tell whether they are correct or not.

Visual representation of the problem:

screenshot from 2017-10-07 14-53-15

Notice how much more than the constant conditions are underlined.

See also: https://github.com/steelbrain/linter-ui-default/issues/398#issuecomment-331632791 and onwards.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Oct 12, 2017

We can just report node.test as the node, and then all of that information will be automatically added to the report.

0reactions
VictorHomcommented, Oct 12, 2017

would the ideal case be: just reporting the position of the constant condition (so the true)?

so for the IfStatement, can we report with the loc: {start: {line:nodestartPosition, column:node.test.range[0]}, end: {line:nodestartPosition, column:node.test.range[1]}}?

haven’t checked if there is a case that catches the correct position across the board, but I imagine they might be similar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JS Build Error, Lint Error no-constant-condition - Stack Overflow
Im getting error Unexpected constant condition no-constant-condition when trying to build this code. (Error is on line indicated with >>>).
Read more >
Regression model constant causes multicollinearity warning ...
1. The threshold for the condition number warning has been increased to 1000, which is still low if the large condition number comes...
Read more >
How to avoid broken formulas - Microsoft Support
Formulas can sometimes result in error values in addition to returning unintended results. Learn about best practices to avoid those problems.
Read more >
How to Interpret the Constant (Y Intercept) in Regression ...
The constant (y-intercept) is the value where the regression line crosses the y-axis. You can't usually interpret the constant but it is vital...
Read more >
Confidence Intervals - SPH - Boston University
The margin of error is very small here because of the large sample size ... the sample indicates having the condition or characteristic...
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