no-cond-assign analyzes too deep into conditionals
See original GitHub issueWhat version are you using?
3.2.2
What did you do?
const arr = [1, 2, 3];
if (arr.some(val => {
let b = true;
if (val === 2) {
b = false;
}
return b;
})) console.log('returned true');
What happened?
With this eslintrc:
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"no-console": 0,
"no-cond-assign": [2, 'always']
}
};
It signaled:
Unexpected assignment within an 'if' statement no-cond-assign
What did you expect to happen?
It should have ceased to analyze once in the callback of Array.prototype.some
and should not care at all about any assignments within. The purpose of the rule is to avoid mistakenly doing an assignment instead of a comparison within a conditional, not to prevent assignments at all.
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (12 by maintainers)
Top Results From Across the Web
In Too Deep: The Perils of Data Analysis | Lucidchart Blog
In data analytics, one question brings on another. Avoid the slippery slope of data analysis with a proven process for impact-drive research. Learn...
Read more >The Logic of Conditionals - Stanford Encyclopedia of Philosophy
Logics of indicative conditionals, in so far as they are based on truth evaluations, all agree that a conditional is false if its...
Read more >How Can I Create Stronger Analysis? - College of LSA
In the essay, each piece of evidence selected is paired with deep analysis that builds or elaborates on the last until the thesis...
Read more >Content Analysis Method and Examples
A content analysis is a tool for researchers to easily determine the presence of words, themes, or concepts from qualitative data.
Read more >How to Beat 'Analysis Paralysis' and Make All the Decisions
Explore possible causes of overthinking. It often helps to understand why you have trouble making choices. Did a previous decision not pan out ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pmcelhaney That rule is exactly the one that the airbnb config has set: https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/errors.js#L7
The code
doSomething(foo = 5)
whether inside a conditional or not, should produce an error, but not under this rule. Just like a programmer might have mistakenly used an assignment instead of a double or triple equal, the guy writing the above code might have confused the new ES6 default parameter value feature, which is valid for a function declaration but not function invocation.Apologies @nzakas, I hadn’t had time to verify until just now.
Here’s a snippet that repros in the demo:
As discussed earlier in the issue, there is a separate issue (parentheses being too zealously considered) that prevents this from showing up as a bug with the default “except-parens” configuration. But I believe we can accept this bug, unless you disagree.