@@ -24,6 +24,8 @@ The system computes:
24
24
## 📥 Installation
25
25
26
26
``` bash
27
+ pnpm install -D code-health-meter
28
+ yarn install -D code-health-meter
27
29
npm install -D code-health-meter
28
30
```
29
31
@@ -34,12 +36,23 @@ npm install -D code-health-meter
34
36
35
37
---
36
38
39
+ ## ⚡ Quick Start
40
+
41
+ ``` bash
42
+ npx code-health-meter --srcDir " ./tests/mock-project" --format json
43
+ ```
44
+
45
+ ✅ Generates ` CodeComplexityReport.json ` , ` CodeModularityReport.json ` , and ` jscpd-report.json ` under ` tests/output/ ` .
46
+
47
+ ---
48
+
37
49
## 🚦 CLI Usage
38
50
39
51
Run the tool with:
40
52
41
53
``` bash
42
54
npx code-health-meter --srcDir " ./tests/mock-project" --outputDir " ./tests/output" --format html
55
+ pnpm code-health-meter --srcDir " ./tests/mock-project" --outputDir " ./tests/output" --format html
43
56
```
44
57
45
58
Supported formats: ` html ` , ` json ` , or both.
@@ -53,22 +66,22 @@ To replicate the analysis presented in the paper:
53
66
``` bash
54
67
git clone https://github.com/helabenkhalfallah/code-health-meter.git
55
68
cd code-health-meter
56
- npm install
57
- npm run scan --srcDir " ./tests/mock-project" --outputDir " ./tests/output" --format html,json
69
+ pnpm install
70
+ pnpm scan --srcDir " ./tests/mock-project" --outputDir " ./tests/output" --format html
58
71
```
59
72
60
73
### Output:
61
74
62
- 📂 ` tests/mock-json-scan/ `
63
- - ` code-complexity-audit/CodeComplexityReport.json `
64
- - ` code-modularity-audit/CodeModularityReport.json `
65
- - ` code-modularity-audit/CodeModularityReport.svg `
75
+ 📂 ` tests/mock-json-scan/ `
76
+ - ` code-complexity-audit/CodeComplexityReport.json `
77
+ - ` code-modularity-audit/CodeModularityReport.json `
78
+ - ` code-modularity-audit/CodeModularityReport.svg `
66
79
- ` code-duplication-audit/jscpd-report.json `
67
80
68
- 📂 ` tests/mock-html-scan/ `
69
- - ` code-complexity-audit/CodeComplexityReport.html `
70
- - ` code-modularity-audit/CodeModularityReport.html `
71
- - ` code-duplication-audit/html/index.html `
81
+ 📂 ` tests/mock-html-scan/ `
82
+ - ` code-complexity-audit/CodeComplexityReport.html `
83
+ - ` code-modularity-audit/CodeModularityReport.html `
84
+ - ` code-duplication-audit/html/index.html `
72
85
- Additional styled UI in ` styles/ ` and ` js/ `
73
86
74
87
> Note on Scale and Reproducibility: The included tests/mock-project is a simplified version intended for demonstration and functional validation of the Code Health Meter (CHM) framework. The original system evaluated in the TOSEM paper comprises approximately 14,000 lines of JavaScript/TypeScript code across 221 modules. Due to size and licensing constraints, that full system is not distributed as part of this artifact. However, the provided mock-project, along with the structured output reports, fully reproduces the CHM analysis pipeline, including complexity metrics, duplication detection, and graph-based modularity assessments.
@@ -85,6 +98,99 @@ npm run scan --srcDir "./tests/mock-project" --outputDir "./tests/output" --form
85
98
86
99
---
87
100
101
+ ## 🧩 Reusable APIs (Programmatic)
102
+
103
+ > ** Analyzed entries vs raw files** : per-metric builders operate on ** analyzed entries** produced by a single ` inspectDirectory() ` pass (not on raw file paths). The term _ entries_ is used below to make this explicit.
104
+
105
+ ### Complexity — per-metric builders
106
+
107
+ ``` js
108
+ // src/kernel/complexity/CodeComplexityMetrics.js
109
+ import {
110
+ buildMaintainabilityReports , // MI
111
+ buildSLOCReports , // SLOC
112
+ buildCyclomaticReports , // CC
113
+ buildHalsteadMetricReports // Halstead
114
+ } from " ./src/kernel/complexity/CodeComplexityMetrics.js" ;
115
+
116
+ // entries: array produced by a single inspectDirectory() pass
117
+ const reports = [
118
+ ... buildMaintainabilityReports (entries),
119
+ ... buildSLOCReports (entries),
120
+ ... buildCyclomaticReports (entries),
121
+ ... buildHalsteadMetricReports (entries),
122
+ ];
123
+ ```
124
+
125
+ ** Full complexity report (composer):**
126
+
127
+ ``` js
128
+ // src/kernel/complexity/CodeComplexityBuilder.js
129
+ import { buildFullComplexityReport } from " ./src/kernel/complexity/CodeComplexityBuilder.js" ;
130
+
131
+ const { summary , auditReports } = buildFullComplexityReport ({
132
+ entries, // from inspectDirectory()
133
+ metricIds: [" mi" ," sloc" ," cyclo" ," hal" ],
134
+ summaryBase, // aggregates you already computed
135
+ buildAuditStats, // categorization helper
136
+ });
137
+ ```
138
+
139
+ ** Producing analyzed entries:**
140
+
141
+ ``` js
142
+ // src/kernel/complexity/CodeComplexityUtils.js
143
+ import { inspectDirectory } from " ./src/kernel/complexity/CodeComplexityUtils.js" ;
144
+
145
+ const { summary , files: entries } = inspectDirectory ({
146
+ srcDir: " ./tests/mock-project" ,
147
+ options: {/* parser / analyzer options */ }
148
+ });
149
+ ```
150
+
151
+ ### Modularity — graph metrics
152
+
153
+ ``` js
154
+ // src/kernel/modularity/CodeModularityUtils.js, CodeModularityMetrics.js
155
+ import {
156
+ buildDirectoryTree , // Madge: obj() + svg()
157
+ buildLouvainGraph , // Graphology graph (directed)
158
+ } from " ./src/kernel/modularity/CodeModularityUtils.js" ;
159
+ import {
160
+ detectCommunities , // Louvain communities + modularity
161
+ readDensity ,
162
+ readDegreeCentralities
163
+ } from " ./src/kernel/modularity/CodeModularityMetrics.js" ;
164
+
165
+ const { tree , treeVisualization } = await buildDirectoryTree (" ." );
166
+ const graph = await buildLouvainGraph (tree, treeVisualization);
167
+
168
+ const { modularity , communities } = detectCommunities (graph);
169
+ const { density } = readDensity (graph);
170
+ const { degreeCentrality , inDegreeCentrality , outDegreeCentrality } = readDegreeCentralities (graph);
171
+ ```
172
+
173
+ ### Duplication — CLI + JSON output
174
+
175
+ The duplication auditor uses ** jscpd** and writes JSON/HTML to ` code-duplication-audit/ ` . Programmatic consumption can read and parse ` jscpd-report.json ` :
176
+
177
+ ``` js
178
+ import fs from " fs" ;
179
+
180
+ const dup = JSON .parse (
181
+ fs .readFileSync (" ./tests/output/code-duplication-audit/jscpd-report.json" , " utf8" )
182
+ );
183
+
184
+ console .log (" clones:" , dup .total ? .clones || dup .statistics ? .total ? .clones );
185
+ ` ` `
186
+
187
+ #### Duplication — Fixed Reproducibility
188
+
189
+ The duplication module now correctly detects cloned code.
190
+ ✅ In the ` tests/ mock- project` , CHM identifies **1 clone of 6 lines**, matching the expected test results.
191
+
192
+ ---
193
+
88
194
## 📚 Citation
89
195
90
196
` ` ` bibtex
@@ -99,22 +205,38 @@ npm run scan --srcDir "./tests/mock-project" --outputDir "./tests/output" --form
99
205
100
206
---
101
207
208
+ ## 🔍 Notes on Determinism & Reproducibility
209
+
210
+ - The dependency graph is **directed** by default; centralities are computed on this directed graph.
211
+ - Louvain community detection is provided by Graphology; results are stable for a given codebase and toolchain.
212
+ - CHM favors a **single-pass** pipeline for complexity (compute once, reuse entries across metrics).
213
+
214
+ ---
215
+
102
216
## 🤝 Contributing
103
217
104
218
` ` ` bash
105
219
git clone https: // github.com/helabenkhalfallah/code-health-meter.git
106
220
cd code- health- meter
107
- npm install
221
+ pnpm install
108
222
` ` `
109
223
110
224
Run:
111
225
112
226
` ` ` bash
113
- npm run scan --srcDir " ./tests/mock-project" --outputDir " ./tests/output" --format html,json
227
+ pnpm scan -- srcDir " ./tests/mock-project" -- outputDir " ./tests/output" -- format html,json
114
228
` ` `
115
229
116
230
---
117
231
232
+ ## 📝 Response to Reviewers (TOSEM 2025 RCR)
233
+
234
+ - **Functional Badge**: Fixed duplication detection reproducibility (1 clone of 6 lines detected in ` tests/ mock- project` ).
235
+ - **Reusable Badge**: Exposed Cyclomatic Complexity and Halstead metrics as reusable functions. Documented rationale for metrics embedded in higher-level modules.
236
+ - **Documentation**: Expanded test instructions, clarified programmatic APIs, and detailed reproducibility notes.
237
+
238
+ ---
239
+
118
240
## 📜 License
119
241
120
242
Licensed under the MIT License. See the [LICENSE](./LICENSE) file.
0 commit comments