complexity-guard 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +21 -11
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -24,10 +24,13 @@ complexity-guard src/
24
24
  src/auth/login.ts
25
25
  42:0 ✓ ok Function 'validateCredentials' cyclomatic 3 cognitive 2
26
26
  67:0 ⚠ warning Function 'processLoginFlow' cyclomatic 12 cognitive 18
27
+ [halstead vol 843 diff 14.1 effort 11886] [length 34 params 3 depth 4]
27
28
  89:2 ✗ error Method 'handleComplexAuthFlow' cyclomatic 25 cognitive 32
29
+ [halstead vol 1244 diff 18.6 effort 23135 bugs 0.41] [length 62 params 4 depth 6]
28
30
 
29
31
  Analyzed 12 files, 47 functions
30
32
  Found 3 warnings, 1 errors
33
+ Health: 73
31
34
 
32
35
  Top cyclomatic hotspots:
33
36
  1. handleComplexAuthFlow (src/auth/login.ts:89) complexity 25
@@ -37,15 +40,23 @@ Top cognitive hotspots:
37
40
  1. handleComplexAuthFlow (src/auth/login.ts:89) complexity 32
38
41
  2. processLoginFlow (src/auth/login.ts:67) complexity 18
39
42
 
43
+ Top Halstead volume hotspots:
44
+ 1. handleComplexAuthFlow (src/auth/login.ts:89) volume 1244
45
+ 2. processLoginFlow (src/auth/login.ts:67) volume 843
46
+
40
47
  ✗ 4 problems (1 errors, 3 warnings)
41
48
  ```
42
49
 
43
50
  ## Features
44
51
 
45
- - **Cognitive Complexity**: SonarSource-based metric measuring code *understandability* with nesting depth penalties
46
- - **Cyclomatic Complexity**: McCabe metric with ESLint-aligned counting rules, complementary to cognitive complexity
52
+ - **Cyclomatic Complexity**: McCabe metric counting independent code paths measures testability
53
+ - **Cognitive Complexity**: SonarSource-based metric with nesting depth penalties measures understandability
54
+ - **Halstead Metrics**: Information-theoretic vocabulary density, volume, difficulty, effort, and estimated bugs
55
+ - **Structural Metrics**: Function length, parameter count, nesting depth, file length, and export count
56
+ - **Composite Health Score**: Single 0–100 score combining all metric families with configurable weights — enforce in CI with `--fail-health-below`
47
57
  - **Console + JSON Output**: Human-readable terminal display and machine-readable JSON for CI integration
48
- - **Configurable Thresholds**: Warning and error levels for both metrics, customizable per project via config file
58
+ - **Configurable Thresholds**: Warning and error levels for all four metric families, customizable per project
59
+ - **Selective Metrics**: Use `--metrics cyclomatic,halstead` to compute only specific families
49
60
  - **Zero Config**: Works out of the box with sensible defaults, optional `.complexityguard.json` for customization
50
61
  - **Single Binary**: No runtime dependencies, runs offline, fast startup
51
62
  - **Error-Tolerant Parsing**: Tree-sitter based parser handles syntax errors gracefully, continues analysis on remaining files
@@ -61,14 +72,13 @@ Create a `.complexityguard.json` file in your project root to customize behavior
61
72
  "exclude": ["**/*.test.ts", "**/*.spec.ts", "node_modules/**"]
62
73
  },
63
74
  "thresholds": {
64
- "cyclomatic": {
65
- "warning": 10,
66
- "error": 20
67
- },
68
- "cognitive": {
69
- "warning": 15,
70
- "error": 25
71
- }
75
+ "cyclomatic": { "warning": 10, "error": 20 },
76
+ "cognitive": { "warning": 15, "error": 25 },
77
+ "halstead_volume": { "warning": 500, "error": 1000 },
78
+ "halstead_effort": { "warning": 5000, "error": 10000 },
79
+ "function_length": { "warning": 25, "error": 50 },
80
+ "params": { "warning": 3, "error": 6 },
81
+ "nesting": { "warning": 3, "error": 5 }
72
82
  },
73
83
  "counting_rules": {
74
84
  "logical_operators": true,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "Ben van de Sande",
5
5
  "email": "info@getlean.digital"
6
6
  },
7
- "version": "0.2.1",
7
+ "version": "0.4.0",
8
8
  "description": "Fast complexity analysis for TypeScript/JavaScript — single static binary",
9
9
  "bin": {
10
10
  "complexity-guard": "bin/complexity-guard.js"
@@ -13,11 +13,11 @@
13
13
  "bin/"
14
14
  ],
15
15
  "optionalDependencies": {
16
- "@complexity-guard/darwin-arm64": "0.2.1",
17
- "@complexity-guard/darwin-x64": "0.2.1",
18
- "@complexity-guard/linux-arm64": "0.2.1",
19
- "@complexity-guard/linux-x64": "0.2.1",
20
- "@complexity-guard/windows-x64": "0.2.1"
16
+ "@complexity-guard/darwin-arm64": "0.4.0",
17
+ "@complexity-guard/darwin-x64": "0.4.0",
18
+ "@complexity-guard/linux-arm64": "0.4.0",
19
+ "@complexity-guard/linux-x64": "0.4.0",
20
+ "@complexity-guard/windows-x64": "0.4.0"
21
21
  },
22
22
  "license": "MIT",
23
23
  "repository": {