Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Static Analysis & Code Metrics #403
referenced this issue
Apr 21, 2015
I want that in 2.x, but it needs to be specified in more details:
Maintainability Index = MAX(0,(171 - 5.2 * ln(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * ln(Lines of Code))*100 / 171)
Halstead Volume is $V = N \times \log_2 \eta$ where \eta is the number of distinct operators and N is the total number of operators plus the total number of operands - which seems to roughly correspond to tokens.
Assuming number of broken rules stands for code inspection issues found, I don't think I would factor that in, as the code inspections evolve with each new release, and are essentially things we think are worth fixing, not to mention the false positives. Besides, the number of code inspection results ("issues") are already an available figure.
I'd be more than happy to see the 3 metrics above, as an initial release.
Re: Cyclomatic complexity, wikipedia can help us out there.
The attached commit takes a first step towards code metrics. It adds the following:
The CFG doesn't support macros yet. Also errors are not correct 100% (not sure if that's even possible).
The print()-method in the CFG allows output to be visualized with tools like Webgraphviz. E.g. the following code:
Would be represented in the following way:
Which would produce this image:
There are probably still quite a few bugs (just found one while writing this).
What do you guys think?
Peephole optimizations? Maybe there are certain instructions in VBA that should always be replaced by better versions?
#3522 includes "lines" "cyclomatic complexity" and "nesting level". It does not include a maintainability index. The design should be extensible enough to not completely go bonkers when somebody wants to implement it. I think we can close this issue when the PR is merged, though.
On the module level, we could think about adding two instability metrics: