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 false positive on string compare #12225
Comments
I am going to take a look at this. |
A workaround in this particular situation could be to use the equivalent /*eslint no-constant-condition: "error"*/
function isDate(ty, tm, td) {
const [y, m, d] = new Date().toISOString().split(/[-T]/).map(x => Number(x));
if (String([y, m, d]) === String([ty, tm, td])) {
return true;
}
return false;
}
console.log(isDate(2019,9,5)); The rule, in general, doesn't assume that a function always returns the same value for the same arguments (even constants), so any function call inside a condition makes the whole condition valid by the logic of this rule. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening this since it's accepted and we have a PR. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
) (eslint#12307) * Fix: no-constant-condition doesn't introspect arrays (fixes eslint#12225) * Update: no-constant-condition allows for narrower scope of varriable arrays * Update: no-constant condition now requires direct parent to be binary expression * Update: no-contant-contidtion now checks parent type before operator, unit tests include more paths
Check out Demo Page for more details
Tell us about your environment
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
No error
What actually happened? Please include the actual, raw output from ESLint.
The text was updated successfully, but these errors were encountered: