Skip to content

Commit

Permalink
fix: clean files and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
offgriddev committed Nov 1, 2023
1 parent 8bddecf commit ce84890
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ce84890

Please sign in to comment.