diff --git a/README.md b/README.md index 7edc63e..1475926 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,21 @@ function main(a) { As code grows, and I'm sure we've all seen it, algorithms can take on a life of their own and grow to contain numerous linear paths that all have to be maintained and amount to the cognitive overhead of a given algorithm. -This library provides any JS library the ability to analyze the Cyclomatic Complexity of their functions with a dependency solely on the [abstract-syntax-tree](https://www.npmjs.com/package/abstract-syntax-tree) \ No newline at end of file +This library provides any JS library the ability to analyze the Cyclomatic Complexity of their functions with a dependency solely on the [abstract-syntax-tree](https://www.npmjs.com/package/abstract-syntax-tree) + +# How to Use + +CyclomaticJS has one named export: `calculateComplexity` + +This function takes a `filename` and calculates the logical complexity of a file's contents. + +```javascript +import { calculateComplexity } from 'cyclomatic-js' + +const complexity = calculateComplexity('somefile.js') + +``` + +# Supported Source Code + +CyclomaticJS supports both CommonJS and ESModules. Please raise an issue if there are problems with either module loading systems. \ No newline at end of file diff --git a/src/index.js b/src/index.js index 6ba09e9..b25fa1f 100644 --- a/src/index.js +++ b/src/index.js @@ -85,12 +85,11 @@ function determineLogicalComplexity(bodyInput) { } } } - function findDeclarations(node, complexity) { + function findDeclarations(node) { if (node.declaration) return processNodes([node.declaration]) if (!node.declarations) return for (const declaration of node.declarations) { - const isFunction = !!declaration.init?.body?.body if (declaration.init?.body?.body) { processNodes(declaration.init.body.body) }