33> Measure the churn/complexity score. Higher scores reveal hotspots where
44> refactorings should happen.
55
6- [ ![ Build Status] [ travis-image ]] [ travis-url ]
7- [ ![ Coverage Status] [ coverage-image ]] [ coverage-url ]
86[ ![ Style Status] [ style-image ]] [ style-url ]
97[ ![ NPM Version] [ npm-image ]] [ npm-url ]
108
@@ -15,7 +13,7 @@ view, using information from our version control systems, we can get a better
1513sense of the effects of our refactoring efforts.*
1614
1715Note: ` code-complexity ` currently measures complexity using either:
18- - lines of code count (all languages)
16+ - lines of code count (for most languages)
1917- cyclomatic complexity (JavaScript/TypeScript)
2018- halstead complexity (JavaScript/TypeScript)
2119
@@ -58,6 +56,32 @@ $ code-complexity . --since=2021-04-01 --until=2021-07-01
5856$ code-complexity . --max-buffer 64000000
5957```
6058
59+ ## Which strategy should you choose?
60+
61+ Currently, ` code-complexity ` supports three strategies:
62+ - ` sloc `
63+ - ` cyclomatic ` (JavaScript/TypeScript only)
64+ - ` halstead ` (JavaScript/TypeScript only)
65+
66+ ` sloc ` is the default strategy since it works on pretty much any language.
67+ It's a basic source code line count. One could think that it's not super helpful, but I have found that length is a
68+ decent starting point.
69+
70+ ` cyclomatic ` is a more advanced strategy that uses the [ cyclomatic complexity] [ cyclomatic ]
71+ of functions. Basically, the more nesting you have, the more complex your function is.
72+
73+ ` halstead ` is a more advanced strategy that uses the [ halstead complexity] [ halstead ] `.
74+ It will evaluate complexity based on the number of operands, operators and operands per operator.
75+ Basically, the more diverse operators you have, the more complex your function is.
76+
77+ None is better than the other ;)
78+
79+ My own workflow is usually to poke around with one of them, look at the underlying
80+ code and then decide if the complexity is worth refactoring.
81+
82+ [ cyclomatic ] : https://en.wikipedia.org/wiki/Cyclomatic_complexity
83+ [ halstead ] : https://en.wikipedia.org/wiki/Halstead_complexity_measures
84+
6185## Output
6286
6387``` sh
0 commit comments