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
[no-constant-condition] all literal should be treated like boolean literal #13238
Comments
/*eslint no-constant-condition: "error"*/
if (this.loginpage ||true) {} // error
if (this.loginpage || 1) {} // error
if (this.loginpage || '1') {} // error
if (true || this.loginpage) {} // error
if (1 || this.loginpage) {} // no error
if ('1' || this.loginpage) {} // no error Hi, @Zzzen. :). It seems a bug to me.
so, maybe, it should be fixed rather than adding new options? |
I agree with above comment. if (1 || this.loginpage) {} // this should be an error cause its always truthy
if ('1' || this.loginpage) {} // this should be an error , always truthy |
Because I'm not sure what's the rationale behind these lines. 😂
"if('str' || a){}",
"if('str1' && a){}",
"if(a && 'str'){}",
"if('str' || abc==='str'){}", |
Do we have any rules for |
I think it should be reported as well with an unused condition as |
It would be a big breaking change. |
We don't have such a rule. It might be worth exploring whether an option in |
I believe the only reason to not report In that case,
Even if we add such a rule or option at some point, I don't think that the mentioned overlapping would be a big problem, so I'd vote to accept this issue as a bug and fix it in a semver-minor release. In addition to /* eslint no-constant-condition: error */
if (false && a); // error
if (void null && a); // error!
if (null && a); // no error |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
What rule do you want to change?
no-constant-condition
Does this change cause the rule to produce more or fewer warnings?
More warnings
How will the change be implemented? (New option, new default behavior, etc.)?
New option
Please provide some example code that this change will affect:
What does the rule currently do for this code?
Only the first
if
statement is reportedWhat will the rule do after it's changed?
The second
if
statement will be reported too.Are you willing to submit a pull request to implement this change?
Yes
The text was updated successfully, but these errors were encountered: