Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate Cyclomatic Complexity for Javascript [closed]

Are there any tools available for calculating Cyclomatic Complexity in Javascript?

I've found it a very helpful metric in the past while working on server side code, and would like to be able to use it for the client side Javascript I write.

like image 897
Karl Avatar asked Sep 19 '08 09:09

Karl


People also ask

What is the formula for calculating cyclomatic complexity?

3) Cyclomatic complexity V(G) = P +1 V (G) = 2 + 1 = 3 Where P is predicate nodes (node 1 and node 2) are predicate nodes because from these nodes only the decision of which path is to be followed is taken.

What is cyclomatic complexity and how it is calculated?

Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors. It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent paths through a program module.

How is cyclomatic complexity calculated in white box testing?

Cyclomatic Complexity: It is a measure of the logical complexity of the software and is used to define the number of independent paths. For a graph G, V(G) is its cyclomatic complexity. Calculating V(G): V(G) = P + 1, where P is the number of predicate nodes in the flow graph.


1 Answers

I helped write a tool to perform software complexity analysis on JavaScript projects:

complexity-report

It reports a bunch of different complexity metrics: lines of code, number of parameters, cyclomatic complexity, cyclomatic density, Halstead complexity measures, the maintainability index, first-order density, change cost and core size.

It is released under the MIT license and built using Node.js and the Esprima JavaScript parser. It can be installed via npm, like so:

npm i -g complexity-report 
like image 168
Phil Booth Avatar answered Oct 02 '22 16:10

Phil Booth