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.

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:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Jun 3, 2017

Closing because this seems to be working as intended.

0reactions
not-an-aardvarkcommented, Nov 3, 2017

Marking this accepted because I’m also now convinced that this is a bug.

Read more comments on GitHub >

github_iconTop 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 >

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