Closed abelbraaksma closed 7 years ago
We just use FSharpLint library for this, please report your issue here https://github.com/fsprojects/FSharpLint
@vasily-kirichenko could we update the linter? This rule no longer exists + the default config is now much saner
The last scenario (+2) looks like a bug, but the first and and second scenarios look as expected, examples like this is why the rule is gone ;)
@duckmatt ok, I will update everything.
this is why the rule is gone ;)
Do you mean to say that this rule is supposed to be off by default? Or permanently switched off?
but the first and and second scenarios look as expected,
From your reference doc I understand that a || b && c || d
should be 3. But I don't understand why:
let a = b || c
let d = e || f
a && d
also counts as 3. As I'd say there are three blocks of code here, each with a complexity of 1. But as can be seen in my 2nd example, the count just counts up.
But it is true that I have misunderstood, at least in part, what cyclomatic complexity is supposed to mean. I thought it dealt with inter-function or class dependencies (aka as coupling), but I was wrong to assume that.
Do you mean to say that this rule is supposed to be off by default? Or permanently switched off?
The most recent version of the linter contains no implementation of the rule
The cyclomatic complexity was being counted on a per function basis, so you're right in that each block would have a CC of 1, but the linter would add the three blocks together to get the CC of the function. The rule you thought it was sounds useful :)
@vasily-kirichenko thank you
Version 2.5.4 was just released with fresh FSharpLint.
I've often wondered why my code had a lot of orange squigglies with "This binding has a cyclomatic complexity of X, expecting a cyclomatic complexity of less than 10". I just thought I had a lot of dependencies, but then it occurred to me that these warnings occur on code that have zero dependencies.
Since I now have a repro, I decided to share it.
Repro steps
Here's an example that, when you copy it in VS 2015, shows a cyclomatic complexity of 73 (yes, it is ugly, it is autogenerated, but it helps as an example):
I suspected that the count of 73 had to do with the number of
||
in the boolean expression, so I wondered what'd happen if I split it up:Still shows 73. If I remove any of the
||
the complexity goes down with one.If I rewrite it as follows, the warning drops from 73 to a complexity level of 13, which is surprising, because one could argue that there actually is a higher cyclomatic complexity than before (though i would argue it is 2 in this case). Note that again the
||
and&&
counted towards the complexity, not the|> orAnd
. Remove them and the complexity count becomes 1.Even more suprisingly (or maybe not, I don't know), if you use the following syntax, the complexity goes up again:
Expected behavior
There is no cyclomatic complexity in this case, it should be 1.
Actual behavior
As can be seen above: the cyclomatic complexity is calculated way too high.
Known workarounds
None that I know of, unless of course to write the code differently. While the above is an extreme example, I am wondering how the calculation is done, because this warning happens a lot even in cases where there are no (inter)dependencies within the code.
Sometimes it gets it right as well, of course, in which case it is a good warning too have.
Related information
Tested with VS 2015 Update 3 and latest version of F# PowerPack.