Complexity rule prefers and `&&` over or `||`
See original GitHub issue- ESLint Version: 3.19.0
- Node Version: 7.7.3
- npm Version: 4.5.0
What parser (default, Babel-ESLint, etc.) are you using? : babel-eslint
Please show your full configuration:
{
"parser": "babel-eslint",
"rules": {
"complexity": [2, 1]
}
}
What did you do? Please include the actual source code causing the issue.
let foo, bar, baz, bang;
function check(foo, bar, baz, bang) {
if (!bar || !bang) {
baz = foo;
}
}
function check2(foo, bar, baz, bang) {
if (!(bar && bang)) {
baz = foo;
}
}
function check3(foo, bar, baz, bang) {
if (bar && bang) {
baz = foo;
}
}
function check4(foo, bar, baz, bang) {
if (!bar && !bang) {
baz = foo;
}
}
function check5(foo, bar, baz, bang) {
if (bar || bang) {
baz = foo;
}
}
check(foo, bar, baz, bang);
check2(foo, bar, baz, bang);
check3(foo, bar, baz, bang);
check4(foo, bar, baz, bang);
check5(foo, bar, baz, bang);
What did you expect to happen?
All functions check to check5 should have the same complexity
What actually happened? Please include the actual, raw output from ESLint.
3:1 error Function 'check' has a complexity of 3 complexity
8:1 error Function 'check2' has a complexity of 2 complexity
13:1 error Function 'check3' has a complexity of 2 complexity
18:1 error Function 'check4' has a complexity of 2 complexity
23:1 error Function 'check5' has a complexity of 3 complexity
It seems that ||
has more complexity than &&
in the current implementation, but I don’t think that is true. All the check
have a complexity of 3. (That is what http://jsmeter.info/axtsgb/1#results reports)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Complexity Rule Set - Detekt
This rule measures and restricts the complexity of the method through the Cognitive Complexity metric of Sonasource.
Read more >Complexity Bias: Why We Prefer Complicated to Simple
Complexity bias is a logical fallacy that leads us to give undue credence to complex concepts. Faced with two competing hypotheses, we are...
Read more >Preference for Complexity - an overview | ScienceDirect Topics
In visual research, preferences for complexity tend to follow an inverted U-shaped curve, with levels that are too low or too high being...
Read more >Should we prefer cognitive complexity over cyclomatic ...
Cognitive Complexity is about understandability. So if you're trying to put a measurement on this (admittedly inherently subjective) value then ...
Read more >Preference for complexity as a function of schematic ...
Complexity was expressed in terms of the generating rule of the stimuli and the amount that the derived stimuli deviated from that rule....
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 FreeTop 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
Top GitHub Comments
Closing because this seems to be working as intended.
Marking this accepted because I’m also now convinced that this is a bug.