Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { analyzeComplexity, analyzeDiffComplexity } from 'indent-complexity';

// Pass any code snippet, function of complete file to get complexity assessment:
const codeComplexity = analyzeComplexity(codeSnippet);
console.log(codeComplexity.score)
console.log(codeComplexity.score);

// Also supports `git diff` output to evaluate complexity for added lines (by default):
const diffComplexity = analyzeDiffComplexity(gitDiff);
console.log(diffComplexity.score)
console.log(diffComplexity.score);
```

## The Score
Expand All @@ -28,28 +28,29 @@ Unfortunately none of the researchers suggests a single-metric similar to how Cy
Σ(depth²) / lineCount
```

Deeper nesting contributes exponentially more to the score. Default thresholds:
I chose depth squared weighting because:

| Level | Score |
|----------|-----------|
| `low` | < 4 |
| `medium` | 4 - 10 |
| `high` | ≥ 10 |

We chose depth squared weighting because:
- Mirrors cognitive complexity principles (nested code is harder to understand)
- Normalized by line count for cross-file comparison
- Shallow-but-wide code scores low; deep code scores high

Default thresholds:

| Level | Score |
| -------- | ------ |
| `low` | < 4 |
| `medium` | 4 - 10 |
| `high` | ≥ 10 |

`verbose: true` returns all research-backed metrics for you to experiment and explore:

| Metric | Description |
|--------|-------------|
| `variance` | Correlates with McCabe cyclomatic complexity |
| `max` | Deepest nesting level |
| `mean` | Average depth per line |
| `lineCount` | Lines analyzed (excluding comments/blanks) |
| `depthHistogram` | Distribution of depths |
| Metric | Description |
| ---------------- | -------------------------------------------- |
| `variance` | Correlates with McCabe cyclomatic complexity |
| `max` | Deepest nesting level |
| `mean` | Average depth per line |
| `lineCount` | Lines analyzed (excluding comments/blanks) |
| `depthHistogram` | Distribution of depths |

## License

Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ export type {
AnalyzeOptions,
DiffOptions,
} from './types.js';