@aiready/consistency 0.6.12 → 0.6.13

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @aiready/consistency@0.6.12 build /Users/pengcao/projects/aiready/packages/consistency
3
+ > @aiready/consistency@0.6.13 build /Users/pengcao/projects/aiready/packages/consistency
4
4
  > tsup src/index.ts src/cli.ts --format cjs,esm --dts
5
5
 
6
6
  CLI Building entry: src/cli.ts, src/index.ts
@@ -9,16 +9,16 @@
9
9
  CLI Target: es2020
10
10
  CJS Build start
11
11
  ESM Build start
12
- CJS dist/index.js 47.29 KB
13
- CJS dist/cli.js 46.80 KB
14
- CJS ⚡️ Build success in 215ms
15
12
  ESM dist/cli.mjs 8.76 KB
13
+ ESM dist/index.mjs 12.69 KB
16
14
  ESM dist/chunk-7PHHJOGC.mjs 36.87 KB
17
- ESM dist/index.mjs 9.40 KB
18
- ESM ⚡️ Build success in 215ms
15
+ ESM ⚡️ Build success in 167ms
16
+ CJS dist/index.js 50.65 KB
17
+ CJS dist/cli.js 46.80 KB
18
+ CJS ⚡️ Build success in 167ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 1940ms
20
+ DTS ⚡️ Build success in 2088ms
21
21
  DTS dist/cli.d.ts 20.00 B
22
- DTS dist/index.d.ts 2.99 KB
22
+ DTS dist/index.d.ts 3.38 KB
23
23
  DTS dist/cli.d.mts 20.00 B
24
- DTS dist/index.d.mts 2.99 KB
24
+ DTS dist/index.d.mts 3.38 KB
@@ -1,51 +1,61 @@
1
1
 
2
2
  
3
- > @aiready/consistency@0.6.12 test /Users/pengcao/projects/aiready/packages/consistency
3
+ > @aiready/consistency@0.6.13 test /Users/pengcao/projects/aiready/packages/consistency
4
4
  > vitest run
5
5
 
6
6
 
7
7
   RUN  v2.1.9 /Users/pengcao/projects/aiready/packages/consistency
8
8
 
9
- [?25l · src/__tests__/analyzer.test.ts (18)
10
- [?25l · src/__tests__/analyzer.test.ts (18)
11
- · src/__tests__/language-filter.test.ts (3)
12
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
13
- ❯ analyzeConsistency (2)
14
- ⠙ should analyze naming issues
15
- · should detect minimum severity filtering
16
- · analyzeNaming (8)
17
- · analyzePatterns (3)
18
- · consistency scoring (2)
19
- · recommendations (3)
20
- · src/__tests__/language-filter.test.ts (3)
21
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
9
+ [?25l · src/__tests__/scoring.test.ts (8)
10
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
11
+ [?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ✓ src/__tests__/scoring.test.ts (8)
12
+ ✓ src/__tests__/language-filter.test.ts (3)
13
+ [?25l[?25l ✓ src/__tests__/scoring.test.ts (8)
14
+ · src/__tests__/analyzer.test.ts (18)
15
+ ✓ src/__tests__/language-filter.test.ts (3)
16
+ [?25l[?25l[?25l[?25l[?25l[?25l[?25l ✓ src/__tests__/scoring.test.ts (8)
17
+ ❯ src/__tests__/analyzer.test.ts (18)
22
18
  ❯ analyzeConsistency (2)
23
- ⠹ should analyze naming issues
24
- · should detect minimum severity filtering
19
+ ✓ should analyze naming issues
20
+ ⠙ should detect minimum severity filtering
25
21
  · analyzeNaming (8)
26
22
  · analyzePatterns (3)
27
23
  · consistency scoring (2)
28
24
  · recommendations (3)
29
- · src/__tests__/language-filter.test.ts (3)
30
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
25
+ ✓ src/__tests__/language-filter.test.ts (3)
26
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
27
+ ❯ src/__tests__/analyzer.test.ts (18)
31
28
  ❯ analyzeConsistency (2)
32
- ⠸ should analyze naming issues
33
- · should detect minimum severity filtering
29
+ ✓ should analyze naming issues
30
+ ⠹ should detect minimum severity filtering
34
31
  · analyzeNaming (8)
35
32
  · analyzePatterns (3)
36
33
  · consistency scoring (2)
37
34
  · recommendations (3)
38
- · src/__tests__/language-filter.test.ts (3)
39
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
40
- ❯ analyzeConsistency (2)
35
+ ✓ src/__tests__/language-filter.test.ts (3)
36
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
37
+ ✓ src/__tests__/analyzer.test.ts (18)
38
+ ✓ src/__tests__/language-filter.test.ts (3)
39
+  ✓ src/__tests__/analyzer.test.ts (18)
40
+ ✓ src/__tests__/language-filter.test.ts (3)
41
+ ✓ src/__tests__/scoring.test.ts (8)
42
+
43
+  Test Files  3 passed (3)
44
+  Tests  29 passed (29)
45
+  Start at  16:05:50
46
+  Duration  2.20s (transform 335ms, setup 0ms, collect 2.05s, tests 167ms, environment 0ms, prepare 750ms)
47
+
48
+ [?25h[?25h
49
+ 
41
50
  ⠼ should analyze naming issues
42
51
  · should detect minimum severity filtering
43
52
  · analyzeNaming (8)
44
53
  · analyzePatterns (3)
45
54
  · consistency scoring (2)
46
55
  · recommendations (3)
47
- · src/__tests__/language-filter.test.ts (3)
48
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
56
+ ✓ src/__tests__/language-filter.test.ts (3)
57
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
58
+ ❯ src/__tests__/analyzer.test.ts (18)
49
59
  ❯ analyzeConsistency (2)
50
60
  ⠴ should analyze naming issues
51
61
  · should detect minimum severity filtering
@@ -53,8 +63,9 @@
53
63
  · analyzePatterns (3)
54
64
  · consistency scoring (2)
55
65
  · recommendations (3)
56
- · src/__tests__/language-filter.test.ts (3)
57
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
66
+ ✓ src/__tests__/language-filter.test.ts (3)
67
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
68
+ ❯ src/__tests__/analyzer.test.ts (18)
58
69
  ❯ analyzeConsistency (2)
59
70
  ⠦ should analyze naming issues
60
71
  · should detect minimum severity filtering
@@ -62,8 +73,9 @@
62
73
  · analyzePatterns (3)
63
74
  · consistency scoring (2)
64
75
  · recommendations (3)
65
- · src/__tests__/language-filter.test.ts (3)
66
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
76
+ ✓ src/__tests__/language-filter.test.ts (3)
77
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
78
+ ❯ src/__tests__/analyzer.test.ts (18)
67
79
  ❯ analyzeConsistency (2)
68
80
  ⠧ should analyze naming issues
69
81
  · should detect minimum severity filtering
@@ -72,7 +84,8 @@
72
84
  · consistency scoring (2)
73
85
  · recommendations (3)
74
86
  ✓ src/__tests__/language-filter.test.ts (3)
75
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
87
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
88
+ ❯ src/__tests__/analyzer.test.ts (18)
76
89
  ❯ analyzeConsistency (2)
77
90
  ⠇ should analyze naming issues
78
91
  · should detect minimum severity filtering
@@ -81,7 +94,8 @@
81
94
  · consistency scoring (2)
82
95
  · recommendations (3)
83
96
  ✓ src/__tests__/language-filter.test.ts (3)
84
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
97
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
98
+ ❯ src/__tests__/analyzer.test.ts (18)
85
99
  ❯ analyzeConsistency (2)
86
100
  ⠏ should analyze naming issues
87
101
  · should detect minimum severity filtering
@@ -90,7 +104,8 @@
90
104
  · consistency scoring (2)
91
105
  · recommendations (3)
92
106
  ✓ src/__tests__/language-filter.test.ts (3)
93
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
107
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
108
+ ❯ src/__tests__/analyzer.test.ts (18)
94
109
  ❯ analyzeConsistency (2)
95
110
  ⠋ should analyze naming issues
96
111
  · should detect minimum severity filtering
@@ -99,7 +114,8 @@
99
114
  · consistency scoring (2)
100
115
  · recommendations (3)
101
116
  ✓ src/__tests__/language-filter.test.ts (3)
102
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
117
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
118
+ ❯ src/__tests__/analyzer.test.ts (18)
103
119
  ❯ analyzeConsistency (2)
104
120
  ⠙ should analyze naming issues
105
121
  · should detect minimum severity filtering
@@ -108,7 +124,8 @@
108
124
  · consistency scoring (2)
109
125
  · recommendations (3)
110
126
  ✓ src/__tests__/language-filter.test.ts (3)
111
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
127
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
128
+ ❯ src/__tests__/analyzer.test.ts (18)
112
129
  ❯ analyzeConsistency (2)
113
130
  ⠹ should analyze naming issues
114
131
  · should detect minimum severity filtering
@@ -117,183 +134,88 @@
117
134
  · consistency scoring (2)
118
135
  · recommendations (3)
119
136
  ✓ src/__tests__/language-filter.test.ts (3)
120
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
137
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
138
+ ❯ src/__tests__/analyzer.test.ts (18)
121
139
  ❯ analyzeConsistency (2)
122
- ⠸ should analyze naming issues
123
- · should detect minimum severity filtering
124
- · analyzeNaming (8)
125
- · analyzePatterns (3)
126
- · consistency scoring (2)
127
- · recommendations (3)
128
- ❯ analyzeConsistency (2)
129
- ⠼ should analyze naming issues
130
- · should detect minimum severity filtering
131
- · analyzeNaming (8)
132
- · analyzePatterns (3)
133
- · consistency scoring (2)
134
- · recommendations (3)
135
- ✓ src/__tests__/language-filter.test.ts (3)
136
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
137
- ❯ analyzeConsistency (2)
138
- ⠴ should analyze naming issues
139
- · should detect minimum severity filtering
140
- · analyzeNaming (8)
141
- · analyzePatterns (3)
142
- · consistency scoring (2)
143
- · recommendations (3)
144
- ✓ src/__tests__/language-filter.test.ts (3)
145
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
146
- ❯ analyzeConsistency (2)
147
- ⠦ should analyze naming issues
148
- · should detect minimum severity filtering
149
- · analyzeNaming (8)
150
- · analyzePatterns (3)
151
- · consistency scoring (2)
152
- · recommendations (3)
153
- ✓ src/__tests__/language-filter.test.ts (3)
154
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
155
- ❯ analyzeConsistency (2)
156
- ⠧ should analyze naming issues
157
- · should detect minimum severity filtering
158
- · analyzeNaming (8)
159
- · analyzePatterns (3)
160
- · consistency scoring (2)
161
- · recommendations (3)
162
- ✓ src/__tests__/language-filter.test.ts (3)
163
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
164
- ❯ analyzeConsistency (2)
165
- ✓ should analyze naming issues 312ms
140
+ ✓ should analyze naming issues
166
141
  ⠙ should detect minimum severity filtering
167
142
  · analyzeNaming (8)
168
143
  · analyzePatterns (3)
169
144
  · consistency scoring (2)
170
145
  · recommendations (3)
171
146
  ✓ src/__tests__/language-filter.test.ts (3)
172
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
147
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
148
+ ❯ src/__tests__/analyzer.test.ts (18)
173
149
  ❯ analyzeConsistency (2)
174
- ✓ should analyze naming issues 312ms
150
+ ✓ should analyze naming issues
175
151
  ⠹ should detect minimum severity filtering
176
152
  · analyzeNaming (8)
177
153
  · analyzePatterns (3)
178
154
  · consistency scoring (2)
179
155
  · recommendations (3)
180
156
  ✓ src/__tests__/language-filter.test.ts (3)
181
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
157
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
158
+ ❯ src/__tests__/analyzer.test.ts (18)
182
159
  ❯ analyzeConsistency (2)
183
- ✓ should analyze naming issues 312ms
160
+ ✓ should analyze naming issues
184
161
  ⠸ should detect minimum severity filtering
185
162
  · analyzeNaming (8)
186
163
  · analyzePatterns (3)
187
164
  · consistency scoring (2)
188
165
  · recommendations (3)
189
166
  ✓ src/__tests__/language-filter.test.ts (3)
190
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
191
- ❯ analyzeConsistency (2)
192
- ✓ should analyze naming issues 312ms
193
- ⠼ should detect minimum severity filtering
194
- · analyzeNaming (8)
195
- · analyzePatterns (3)
196
- · consistency scoring (2)
197
- · recommendations (3)
198
- ✓ src/__tests__/language-filter.test.ts (3)
199
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
200
- ❯ analyzeConsistency (2)
201
- ✓ should analyze naming issues 312ms
202
- ⠴ should detect minimum severity filtering
203
- · analyzeNaming (8)
204
- · analyzePatterns (3)
205
- · consistency scoring (2)
206
- · recommendations (3)
207
- ✓ src/__tests__/language-filter.test.ts (3)
208
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
209
- ❯ analyzeConsistency (2)
210
- ✓ should analyze naming issues 312ms
211
- ⠦ should detect minimum severity filtering
212
- · analyzeNaming (8)
213
- · analyzePatterns (3)
214
- · consistency scoring (2)
215
- · recommendations (3)
216
- ✓ src/__tests__/language-filter.test.ts (3)
217
-  ✓ src/__tests__/analyzer.test.ts (18) 415ms
218
- ✓ src/__tests__/language-filter.test.ts (3)
219
-
220
-  Test Files  2 passed (2)
221
-  Tests  21 passed (21)
222
-  Start at  18:01:20
223
-  Duration  2.38s (transform 742ms, setup 0ms, collect 2.26s, tests 425ms, environment 0ms, prepare 531ms)
224
-
225
- [?25h[?25h
226
- ms
227
- ✓ analyzeNaming (8)
228
- ✓ analyzePatterns (3)
229
- ✓ consistency scoring (2)
230
- ❯ recommendations (3)
231
- ⠙ should generate relevant recommendations
232
- · should suggest standardizing error handling
233
- · should suggest using async/await consistently
167
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
168
+ ✓ src/__tests__/analyzer.test.ts (18)
234
169
  ✓ src/__tests__/language-filter.test.ts (3)
235
-  ✓ src/__tests__/analyzer.test.ts (18) 451ms
170
+  ✓ src/__tests__/analyzer.test.ts (18)
236
171
  ✓ src/__tests__/language-filter.test.ts (3)
172
+ ✓ src/__tests__/scoring.test.ts (8)
237
173
 
238
-  Test Files  2 passed (2)
239
-  Tests  21 passed (21)
240
-  Start at  18:01:19
241
-  Duration  2.72s (transform 1.07s, setup 0ms, collect 3.76s, tests 456ms, environment 0ms, prepare 214ms)
174
+  Test Files  3 passed (3)
175
+  Tests  29 passed (29)
176
+  Start at  16:05:50
177
+  Duration  2.46s (transform 373ms, setup 0ms, collect 2.05s, tests 286ms, environment 0ms, prepare 1.01s)
242
178
 
243
179
  [?25h[?25h
244
- st.ts (3)
245
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
180
+ ❯ src/__tests__/analyzer.test.ts (18)
246
181
  ❯ analyzeConsistency (2)
247
182
  ✓ should analyze naming issues
248
- ⠹ should detect minimum severity filtering
249
- · analyzeNaming (8)
250
- · analyzePatterns (3)
251
- · consistency scoring (2)
252
- · recommendations (3)
253
- ✓ src/__tests__/language-filter.test.ts (3)
254
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
255
- ❯ analyzeConsistency (2)
256
- ✓ should analyze naming issues
257
- ⠸ should detect minimum severity filtering
183
+ ⠙ should detect minimum severity filtering
258
184
  · analyzeNaming (8)
259
185
  · analyzePatterns (3)
260
186
  · consistency scoring (2)
261
187
  · recommendations (3)
262
188
  ✓ src/__tests__/language-filter.test.ts (3)
263
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
189
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
190
+ ❯ src/__tests__/analyzer.test.ts (18)
264
191
  ❯ analyzeConsistency (2)
265
192
  ✓ should analyze naming issues
266
- ⠼ should detect minimum severity filtering
193
+ ⠹ should detect minimum severity filtering
267
194
  · analyzeNaming (8)
268
195
  · analyzePatterns (3)
269
196
  · consistency scoring (2)
270
197
  · recommendations (3)
271
198
  ✓ src/__tests__/language-filter.test.ts (3)
272
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
199
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
200
+ ❯ src/__tests__/analyzer.test.ts (18)
273
201
  ❯ analyzeConsistency (2)
274
202
  ✓ should analyze naming issues
275
- ⠴ should detect minimum severity filtering
203
+ ⠸ should detect minimum severity filtering
276
204
  · analyzeNaming (8)
277
205
  · analyzePatterns (3)
278
206
  · consistency scoring (2)
279
207
  · recommendations (3)
280
208
  ✓ src/__tests__/language-filter.test.ts (3)
281
- [?25l ❯ src/__tests__/analyzer.test.ts (18)
282
- ✓ analyzeConsistency (2) 553ms
283
- ✓ analyzeNaming (8)
284
- ✓ analyzePatterns (3)
285
- ✓ consistency scoring (2)
286
- ❯ recommendations (3)
287
- ⠙ should generate relevant recommendations
288
- · should suggest standardizing error handling
289
- · should suggest using async/await consistently
209
+ [?25l ✓ src/__tests__/scoring.test.ts (8)
210
+ ✓ src/__tests__/analyzer.test.ts (18) 370ms
290
211
  ✓ src/__tests__/language-filter.test.ts (3)
291
-  ✓ src/__tests__/analyzer.test.ts (18) 596ms
212
+  ✓ src/__tests__/analyzer.test.ts (18) 370ms
292
213
  ✓ src/__tests__/language-filter.test.ts (3)
214
+ ✓ src/__tests__/scoring.test.ts (8)
293
215
 
294
-  Test Files  2 passed (2)
295
-  Tests  21 passed (21)
296
-  Start at  18:01:19
297
-  Duration  2.68s (transform 1.41s, setup 0ms, collect 2.94s, tests 724ms, environment 0ms, prepare 693ms)
216
+  Test Files  3 passed (3)
217
+  Tests  29 passed (29)
218
+  Start at  16:05:50
219
+  Duration  2.65s (transform 1.05s, setup 0ms, collect 3.33s, tests 464ms, environment 0ms, prepare 765ms)
298
220
 
299
221
  [?25h[?25h
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ScanOptions, AnalysisResult, Issue } from '@aiready/core';
1
+ import { ScanOptions, AnalysisResult, Issue, ToolScoringOutput } from '@aiready/core';
2
2
 
3
3
  interface ConsistencyOptions extends ScanOptions {
4
4
  /** Check naming conventions and quality */
@@ -86,4 +86,14 @@ declare function detectNamingConventions(files: string[], allIssues: Array<{
86
86
  */
87
87
  declare function analyzePatterns(files: string[]): Promise<PatternIssue[]>;
88
88
 
89
- export { type ArchitectureIssue, type ConsistencyIssue, type ConsistencyOptions, type ConsistencyReport, type NamingIssue, type PatternIssue, analyzeConsistency, analyzeNaming, analyzeNamingAST, analyzePatterns, detectNamingConventions };
89
+ /**
90
+ * Calculate AI Readiness Score for code consistency (0-100)
91
+ *
92
+ * Based on:
93
+ * - Issue density (issues per file)
94
+ * - Weighted severity (critical: 10pts, major: 3pts, minor: 0.5pts)
95
+ * - Pattern consistency across codebase
96
+ */
97
+ declare function calculateConsistencyScore(issues: ConsistencyIssue[], totalFilesAnalyzed: number): ToolScoringOutput;
98
+
99
+ export { type ArchitectureIssue, type ConsistencyIssue, type ConsistencyOptions, type ConsistencyReport, type NamingIssue, type PatternIssue, analyzeConsistency, analyzeNaming, analyzeNamingAST, analyzePatterns, calculateConsistencyScore, detectNamingConventions };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ScanOptions, AnalysisResult, Issue } from '@aiready/core';
1
+ import { ScanOptions, AnalysisResult, Issue, ToolScoringOutput } from '@aiready/core';
2
2
 
3
3
  interface ConsistencyOptions extends ScanOptions {
4
4
  /** Check naming conventions and quality */
@@ -86,4 +86,14 @@ declare function detectNamingConventions(files: string[], allIssues: Array<{
86
86
  */
87
87
  declare function analyzePatterns(files: string[]): Promise<PatternIssue[]>;
88
88
 
89
- export { type ArchitectureIssue, type ConsistencyIssue, type ConsistencyOptions, type ConsistencyReport, type NamingIssue, type PatternIssue, analyzeConsistency, analyzeNaming, analyzeNamingAST, analyzePatterns, detectNamingConventions };
89
+ /**
90
+ * Calculate AI Readiness Score for code consistency (0-100)
91
+ *
92
+ * Based on:
93
+ * - Issue density (issues per file)
94
+ * - Weighted severity (critical: 10pts, major: 3pts, minor: 0.5pts)
95
+ * - Pattern consistency across codebase
96
+ */
97
+ declare function calculateConsistencyScore(issues: ConsistencyIssue[], totalFilesAnalyzed: number): ToolScoringOutput;
98
+
99
+ export { type ArchitectureIssue, type ConsistencyIssue, type ConsistencyOptions, type ConsistencyReport, type NamingIssue, type PatternIssue, analyzeConsistency, analyzeNaming, analyzeNamingAST, analyzePatterns, calculateConsistencyScore, detectNamingConventions };
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  analyzeNaming: () => analyzeNaming,
25
25
  analyzeNamingAST: () => analyzeNamingAST,
26
26
  analyzePatterns: () => analyzePatterns,
27
+ calculateConsistencyScore: () => calculateConsistencyScore2,
27
28
  detectNamingConventions: () => detectNamingConventions
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
@@ -1573,11 +1574,103 @@ function analyzeFileNaming(file, content, customAbbreviations, customShortWords,
1573
1574
  });
1574
1575
  return issues;
1575
1576
  }
1577
+
1578
+ // src/scoring.ts
1579
+ function calculateConsistencyScore2(issues, totalFilesAnalyzed) {
1580
+ const criticalIssues = issues.filter((i) => i.severity === "critical").length;
1581
+ const majorIssues = issues.filter((i) => i.severity === "major").length;
1582
+ const minorIssues = issues.filter((i) => i.severity === "minor").length;
1583
+ const totalIssues = issues.length;
1584
+ const issuesPerFile = totalFilesAnalyzed > 0 ? totalIssues / totalFilesAnalyzed : 0;
1585
+ const densityPenalty = Math.min(50, issuesPerFile * 15);
1586
+ const weightedCount = criticalIssues * 10 + majorIssues * 3 + minorIssues * 0.5;
1587
+ const avgWeightedIssuesPerFile = totalFilesAnalyzed > 0 ? weightedCount / totalFilesAnalyzed : 0;
1588
+ const severityPenalty = Math.min(50, avgWeightedIssuesPerFile * 2);
1589
+ const rawScore = 100 - densityPenalty - severityPenalty;
1590
+ const score = Math.max(0, Math.min(100, Math.round(rawScore)));
1591
+ const factors = [
1592
+ {
1593
+ name: "Issue Density",
1594
+ impact: -Math.round(densityPenalty),
1595
+ description: `${issuesPerFile.toFixed(2)} issues per file ${issuesPerFile < 1 ? "(excellent)" : issuesPerFile < 3 ? "(acceptable)" : "(high)"}`
1596
+ }
1597
+ ];
1598
+ if (criticalIssues > 0) {
1599
+ const criticalImpact = Math.min(30, criticalIssues * 10);
1600
+ factors.push({
1601
+ name: "Critical Issues",
1602
+ impact: -criticalImpact,
1603
+ description: `${criticalIssues} critical consistency issue${criticalIssues > 1 ? "s" : ""} (high AI confusion risk)`
1604
+ });
1605
+ }
1606
+ if (majorIssues > 0) {
1607
+ const majorImpact = Math.min(20, Math.round(majorIssues * 3));
1608
+ factors.push({
1609
+ name: "Major Issues",
1610
+ impact: -majorImpact,
1611
+ description: `${majorIssues} major issue${majorIssues > 1 ? "s" : ""} (moderate AI confusion risk)`
1612
+ });
1613
+ }
1614
+ if (minorIssues > 0 && minorIssues >= totalFilesAnalyzed) {
1615
+ const minorImpact = -Math.round(minorIssues * 0.5);
1616
+ factors.push({
1617
+ name: "Minor Issues",
1618
+ impact: minorImpact,
1619
+ description: `${minorIssues} minor issue${minorIssues > 1 ? "s" : ""} (slight AI confusion risk)`
1620
+ });
1621
+ }
1622
+ const recommendations = [];
1623
+ if (criticalIssues > 0) {
1624
+ const estimatedImpact = Math.min(30, criticalIssues * 10);
1625
+ recommendations.push({
1626
+ action: "Fix critical naming/pattern inconsistencies (highest AI confusion risk)",
1627
+ estimatedImpact,
1628
+ priority: "high"
1629
+ });
1630
+ }
1631
+ if (majorIssues > 5) {
1632
+ const estimatedImpact = Math.min(15, Math.round(majorIssues / 2));
1633
+ recommendations.push({
1634
+ action: "Standardize naming conventions across codebase",
1635
+ estimatedImpact,
1636
+ priority: "medium"
1637
+ });
1638
+ }
1639
+ if (issuesPerFile > 3) {
1640
+ recommendations.push({
1641
+ action: "Establish and enforce coding style guide to reduce inconsistencies",
1642
+ estimatedImpact: 12,
1643
+ priority: "medium"
1644
+ });
1645
+ }
1646
+ if (totalIssues > 20 && minorIssues / totalIssues > 0.7) {
1647
+ recommendations.push({
1648
+ action: "Enable linter/formatter to automatically fix minor style issues",
1649
+ estimatedImpact: 8,
1650
+ priority: "low"
1651
+ });
1652
+ }
1653
+ return {
1654
+ toolName: "consistency",
1655
+ score,
1656
+ rawMetrics: {
1657
+ totalIssues,
1658
+ criticalIssues,
1659
+ majorIssues,
1660
+ minorIssues,
1661
+ issuesPerFile: Math.round(issuesPerFile * 100) / 100,
1662
+ avgWeightedIssuesPerFile: Math.round(avgWeightedIssuesPerFile * 100) / 100
1663
+ },
1664
+ factors,
1665
+ recommendations
1666
+ };
1667
+ }
1576
1668
  // Annotate the CommonJS export names for ESM import in node:
1577
1669
  0 && (module.exports = {
1578
1670
  analyzeConsistency,
1579
1671
  analyzeNaming,
1580
1672
  analyzeNamingAST,
1581
1673
  analyzePatterns,
1674
+ calculateConsistencyScore,
1582
1675
  detectNamingConventions
1583
1676
  });
package/dist/index.mjs CHANGED
@@ -186,10 +186,102 @@ function analyzeFileNaming(file, content, customAbbreviations, customShortWords,
186
186
  });
187
187
  return issues;
188
188
  }
189
+
190
+ // src/scoring.ts
191
+ function calculateConsistencyScore(issues, totalFilesAnalyzed) {
192
+ const criticalIssues = issues.filter((i) => i.severity === "critical").length;
193
+ const majorIssues = issues.filter((i) => i.severity === "major").length;
194
+ const minorIssues = issues.filter((i) => i.severity === "minor").length;
195
+ const totalIssues = issues.length;
196
+ const issuesPerFile = totalFilesAnalyzed > 0 ? totalIssues / totalFilesAnalyzed : 0;
197
+ const densityPenalty = Math.min(50, issuesPerFile * 15);
198
+ const weightedCount = criticalIssues * 10 + majorIssues * 3 + minorIssues * 0.5;
199
+ const avgWeightedIssuesPerFile = totalFilesAnalyzed > 0 ? weightedCount / totalFilesAnalyzed : 0;
200
+ const severityPenalty = Math.min(50, avgWeightedIssuesPerFile * 2);
201
+ const rawScore = 100 - densityPenalty - severityPenalty;
202
+ const score = Math.max(0, Math.min(100, Math.round(rawScore)));
203
+ const factors = [
204
+ {
205
+ name: "Issue Density",
206
+ impact: -Math.round(densityPenalty),
207
+ description: `${issuesPerFile.toFixed(2)} issues per file ${issuesPerFile < 1 ? "(excellent)" : issuesPerFile < 3 ? "(acceptable)" : "(high)"}`
208
+ }
209
+ ];
210
+ if (criticalIssues > 0) {
211
+ const criticalImpact = Math.min(30, criticalIssues * 10);
212
+ factors.push({
213
+ name: "Critical Issues",
214
+ impact: -criticalImpact,
215
+ description: `${criticalIssues} critical consistency issue${criticalIssues > 1 ? "s" : ""} (high AI confusion risk)`
216
+ });
217
+ }
218
+ if (majorIssues > 0) {
219
+ const majorImpact = Math.min(20, Math.round(majorIssues * 3));
220
+ factors.push({
221
+ name: "Major Issues",
222
+ impact: -majorImpact,
223
+ description: `${majorIssues} major issue${majorIssues > 1 ? "s" : ""} (moderate AI confusion risk)`
224
+ });
225
+ }
226
+ if (minorIssues > 0 && minorIssues >= totalFilesAnalyzed) {
227
+ const minorImpact = -Math.round(minorIssues * 0.5);
228
+ factors.push({
229
+ name: "Minor Issues",
230
+ impact: minorImpact,
231
+ description: `${minorIssues} minor issue${minorIssues > 1 ? "s" : ""} (slight AI confusion risk)`
232
+ });
233
+ }
234
+ const recommendations = [];
235
+ if (criticalIssues > 0) {
236
+ const estimatedImpact = Math.min(30, criticalIssues * 10);
237
+ recommendations.push({
238
+ action: "Fix critical naming/pattern inconsistencies (highest AI confusion risk)",
239
+ estimatedImpact,
240
+ priority: "high"
241
+ });
242
+ }
243
+ if (majorIssues > 5) {
244
+ const estimatedImpact = Math.min(15, Math.round(majorIssues / 2));
245
+ recommendations.push({
246
+ action: "Standardize naming conventions across codebase",
247
+ estimatedImpact,
248
+ priority: "medium"
249
+ });
250
+ }
251
+ if (issuesPerFile > 3) {
252
+ recommendations.push({
253
+ action: "Establish and enforce coding style guide to reduce inconsistencies",
254
+ estimatedImpact: 12,
255
+ priority: "medium"
256
+ });
257
+ }
258
+ if (totalIssues > 20 && minorIssues / totalIssues > 0.7) {
259
+ recommendations.push({
260
+ action: "Enable linter/formatter to automatically fix minor style issues",
261
+ estimatedImpact: 8,
262
+ priority: "low"
263
+ });
264
+ }
265
+ return {
266
+ toolName: "consistency",
267
+ score,
268
+ rawMetrics: {
269
+ totalIssues,
270
+ criticalIssues,
271
+ majorIssues,
272
+ minorIssues,
273
+ issuesPerFile: Math.round(issuesPerFile * 100) / 100,
274
+ avgWeightedIssuesPerFile: Math.round(avgWeightedIssuesPerFile * 100) / 100
275
+ },
276
+ factors,
277
+ recommendations
278
+ };
279
+ }
189
280
  export {
190
281
  analyzeConsistency,
191
282
  analyzeNaming,
192
283
  analyzeNamingAST,
193
284
  analyzePatterns,
285
+ calculateConsistencyScore,
194
286
  detectNamingConventions
195
287
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/consistency",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "description": "Detects consistency issues in naming, patterns, and architecture that confuse AI models",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -43,7 +43,7 @@
43
43
  "@typescript-eslint/typescript-estree": "^8.53.0",
44
44
  "chalk": "^5.3.0",
45
45
  "commander": "^12.1.0",
46
- "@aiready/core": "0.7.9"
46
+ "@aiready/core": "0.7.10"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^22.10.5",
@@ -0,0 +1,150 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { calculateConsistencyScore } from '../scoring';
3
+ import type { ConsistencyIssue } from '../types';
4
+
5
+ describe('Consistency Scoring', () => {
6
+ describe('calculateConsistencyScore', () => {
7
+ it('should return perfect score for no issues', () => {
8
+ const result = calculateConsistencyScore([], 100);
9
+
10
+ expect(result.score).toBe(100);
11
+ expect(result.toolName).toBe('consistency');
12
+ expect(result.rawMetrics.totalIssues).toBe(0);
13
+ expect(result.recommendations).toHaveLength(0);
14
+ });
15
+
16
+ it('should penalize high issue density', () => {
17
+ const issues: ConsistencyIssue[] = Array(50).fill({
18
+ severity: 'minor',
19
+ category: 'naming',
20
+ message: 'Test issue',
21
+ location: { file: 'test.ts', line: 1 },
22
+ } as ConsistencyIssue);
23
+
24
+ // 50 issues / 10 files = 5 issues per file
25
+ // densityPenalty = min(50, 5 * 15) = 50
26
+ const result = calculateConsistencyScore(issues, 10);
27
+
28
+ expect(result.score).toBeLessThan(60);
29
+ expect(result.rawMetrics.issuesPerFile).toBe(5);
30
+ });
31
+
32
+ it('should heavily penalize critical issues', () => {
33
+ const issues: ConsistencyIssue[] = [
34
+ {
35
+ severity: 'critical',
36
+ category: 'naming',
37
+ message: 'Critical naming issue',
38
+ location: { file: 'test.ts', line: 1 },
39
+ } as ConsistencyIssue,
40
+ {
41
+ severity: 'critical',
42
+ category: 'naming',
43
+ message: 'Another critical issue',
44
+ location: { file: 'test.ts', line: 10 },
45
+ } as ConsistencyIssue,
46
+ ];
47
+
48
+ const result = calculateConsistencyScore(issues, 10);
49
+
50
+ // 2 issues / 10 files = 0.2 issues/file → densityPenalty = 3
51
+ // weightedCount = 2*10 = 20, avgWeighted = 2.0 → severityPenalty = 4
52
+ // score = 100 - 3 - 4 = 93
53
+ expect(result.score).toBe(93);
54
+ expect(result.rawMetrics.criticalIssues).toBe(2);
55
+ expect(result.factors.some(f => f.name === 'Critical Issues')).toBe(true);
56
+ expect(result.recommendations.some(r => r.priority === 'high')).toBe(true);
57
+ });
58
+
59
+ it('should apply weighted severity penalties', () => {
60
+ const issues: ConsistencyIssue[] = [
61
+ ...Array(5).fill({ severity: 'critical' } as ConsistencyIssue),
62
+ ...Array(10).fill({ severity: 'major' } as ConsistencyIssue),
63
+ ...Array(20).fill({ severity: 'minor' } as ConsistencyIssue),
64
+ ];
65
+
66
+ const result = calculateConsistencyScore(
67
+ issues.map((i, idx) => ({
68
+ ...i,
69
+ category: 'naming',
70
+ message: 'test',
71
+ location: { file: 'test.ts', line: idx },
72
+ })) as ConsistencyIssue[],
73
+ 50
74
+ );
75
+
76
+ expect(result.rawMetrics.criticalIssues).toBe(5);
77
+ expect(result.rawMetrics.majorIssues).toBe(10);
78
+ expect(result.rawMetrics.minorIssues).toBe(20);
79
+ // 35 issues / 50 files = 0.7 issues/file → densityPenalty = 10.5
80
+ // weightedCount = 50+30+10 = 90, avgWeighted = 1.8 → severityPenalty = 3.6
81
+ // score = 100 - 10.5 - 3.6 = 85.9 → 86
82
+ expect(result.score).toBe(86);
83
+ });
84
+
85
+ it('should generate appropriate recommendations', () => {
86
+ const issues: ConsistencyIssue[] = [
87
+ ...Array(3).fill({ severity: 'critical', category: 'naming' } as ConsistencyIssue),
88
+ ...Array(10).fill({ severity: 'major', category: 'patterns' } as ConsistencyIssue),
89
+ ];
90
+
91
+ const result = calculateConsistencyScore(
92
+ issues.map((i, idx) => ({
93
+ ...i,
94
+ message: 'test',
95
+ location: { file: 'test.ts', line: idx },
96
+ })) as ConsistencyIssue[],
97
+ 5
98
+ );
99
+
100
+ expect(result.recommendations.length).toBeGreaterThan(0);
101
+ expect(result.recommendations.some(r => r.action.includes('critical'))).toBe(true);
102
+ expect(result.recommendations.some(r => r.action.includes('naming'))).toBe(true);
103
+ });
104
+
105
+ it('should handle edge case of zero files', () => {
106
+ const issues: ConsistencyIssue[] = [];
107
+
108
+ const result = calculateConsistencyScore(issues, 0);
109
+
110
+ expect(result.score).toBe(100);
111
+ expect(result.rawMetrics.issuesPerFile).toBe(0);
112
+ });
113
+
114
+ it('should recommend linter for many minor issues', () => {
115
+ const issues: ConsistencyIssue[] = Array(30).fill({
116
+ severity: 'minor',
117
+ category: 'naming',
118
+ message: 'Minor style issue',
119
+ location: { file: 'test.ts', line: 1 },
120
+ } as ConsistencyIssue);
121
+
122
+ const result = calculateConsistencyScore(issues, 10);
123
+
124
+ expect(result.recommendations.some(r => r.action.includes('linter'))).toBe(true);
125
+ });
126
+
127
+ it('should combine all penalty types', () => {
128
+ const issues: ConsistencyIssue[] = [
129
+ ...Array(10).fill({ severity: 'critical', category: 'naming' } as ConsistencyIssue),
130
+ ...Array(20).fill({ severity: 'major', category: 'patterns' } as ConsistencyIssue),
131
+ ...Array(40).fill({ severity: 'minor', category: 'naming' } as ConsistencyIssue),
132
+ ];
133
+
134
+ const result = calculateConsistencyScore(
135
+ issues.map((i, idx) => ({
136
+ ...i,
137
+ message: 'test',
138
+ location: { file: 'test.ts', line: idx },
139
+ })) as ConsistencyIssue[],
140
+ 10
141
+ );
142
+
143
+ // 70 issues / 10 files = 7 issues/file
144
+ // High density + critical issues + weighted severity
145
+ expect(result.score).toBeLessThan(30);
146
+ expect(result.factors.length).toBeGreaterThan(2);
147
+ expect(result.recommendations.length).toBeGreaterThan(0);
148
+ });
149
+ });
150
+ });
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export { analyzeNamingAST } from './analyzers/naming-ast';
3
3
  export { analyzeNaming } from './analyzers/naming'; // Legacy regex version
4
4
  export { detectNamingConventions } from './analyzers/naming-constants';
5
5
  export { analyzePatterns } from './analyzers/patterns';
6
+ export { calculateConsistencyScore } from './scoring';
6
7
  export type {
7
8
  ConsistencyOptions,
8
9
  ConsistencyReport,
package/src/scoring.ts ADDED
@@ -0,0 +1,128 @@
1
+ import type { ToolScoringOutput } from '@aiready/core';
2
+ import type { ConsistencyIssue } from './types';
3
+
4
+ /**
5
+ * Calculate AI Readiness Score for code consistency (0-100)
6
+ *
7
+ * Based on:
8
+ * - Issue density (issues per file)
9
+ * - Weighted severity (critical: 10pts, major: 3pts, minor: 0.5pts)
10
+ * - Pattern consistency across codebase
11
+ */
12
+ export function calculateConsistencyScore(
13
+ issues: ConsistencyIssue[],
14
+ totalFilesAnalyzed: number
15
+ ): ToolScoringOutput {
16
+ const criticalIssues = issues.filter(i => i.severity === 'critical').length;
17
+ const majorIssues = issues.filter(i => i.severity === 'major').length;
18
+ const minorIssues = issues.filter(i => i.severity === 'minor').length;
19
+ const totalIssues = issues.length;
20
+
21
+ // Issue density penalty (0-50 points)
22
+ // Ideal: 0 issues/file = 0 penalty
23
+ // Acceptable: <1 issue/file = 10 penalty
24
+ // High: 1-3 issues/file = 10-40 penalty
25
+ // Critical: >3 issues/file = 40-50 penalty
26
+ const issuesPerFile = totalFilesAnalyzed > 0 ? totalIssues / totalFilesAnalyzed : 0;
27
+ const densityPenalty = Math.min(50, issuesPerFile * 15);
28
+
29
+ // Weighted severity penalty (0-50 points)
30
+ // Each critical: 10 points
31
+ // Each major: 3 points
32
+ // Each minor: 0.5 points
33
+ const weightedCount = (criticalIssues * 10) + (majorIssues * 3) + (minorIssues * 0.5);
34
+ const avgWeightedIssuesPerFile = totalFilesAnalyzed > 0 ? weightedCount / totalFilesAnalyzed : 0;
35
+ const severityPenalty = Math.min(50, avgWeightedIssuesPerFile * 2);
36
+
37
+ // Calculate final score
38
+ const rawScore = 100 - densityPenalty - severityPenalty;
39
+ const score = Math.max(0, Math.min(100, Math.round(rawScore)));
40
+
41
+ // Build factors array
42
+ const factors: ToolScoringOutput['factors'] = [
43
+ {
44
+ name: 'Issue Density',
45
+ impact: -Math.round(densityPenalty),
46
+ description: `${issuesPerFile.toFixed(2)} issues per file ${issuesPerFile < 1 ? '(excellent)' : issuesPerFile < 3 ? '(acceptable)' : '(high)'}`,
47
+ },
48
+ ];
49
+
50
+ if (criticalIssues > 0) {
51
+ const criticalImpact = Math.min(30, criticalIssues * 10);
52
+ factors.push({
53
+ name: 'Critical Issues',
54
+ impact: -criticalImpact,
55
+ description: `${criticalIssues} critical consistency issue${criticalIssues > 1 ? 's' : ''} (high AI confusion risk)`,
56
+ });
57
+ }
58
+
59
+ if (majorIssues > 0) {
60
+ const majorImpact = Math.min(20, Math.round(majorIssues * 3));
61
+ factors.push({
62
+ name: 'Major Issues',
63
+ impact: -majorImpact,
64
+ description: `${majorIssues} major issue${majorIssues > 1 ? 's' : ''} (moderate AI confusion risk)`,
65
+ });
66
+ }
67
+
68
+ if (minorIssues > 0 && minorIssues >= totalFilesAnalyzed) {
69
+ const minorImpact = -Math.round(minorIssues * 0.5);
70
+ factors.push({
71
+ name: 'Minor Issues',
72
+ impact: minorImpact,
73
+ description: `${minorIssues} minor issue${minorIssues > 1 ? 's' : ''} (slight AI confusion risk)`,
74
+ });
75
+ }
76
+
77
+ // Generate recommendations
78
+ const recommendations: ToolScoringOutput['recommendations'] = [];
79
+
80
+ if (criticalIssues > 0) {
81
+ const estimatedImpact = Math.min(30, criticalIssues * 10);
82
+ recommendations.push({
83
+ action: 'Fix critical naming/pattern inconsistencies (highest AI confusion risk)',
84
+ estimatedImpact,
85
+ priority: 'high',
86
+ });
87
+ }
88
+
89
+ if (majorIssues > 5) {
90
+ const estimatedImpact = Math.min(15, Math.round(majorIssues / 2));
91
+ recommendations.push({
92
+ action: 'Standardize naming conventions across codebase',
93
+ estimatedImpact,
94
+ priority: 'medium',
95
+ });
96
+ }
97
+
98
+ if (issuesPerFile > 3) {
99
+ recommendations.push({
100
+ action: 'Establish and enforce coding style guide to reduce inconsistencies',
101
+ estimatedImpact: 12,
102
+ priority: 'medium',
103
+ });
104
+ }
105
+
106
+ if (totalIssues > 20 && minorIssues / totalIssues > 0.7) {
107
+ recommendations.push({
108
+ action: 'Enable linter/formatter to automatically fix minor style issues',
109
+ estimatedImpact: 8,
110
+ priority: 'low',
111
+ });
112
+ }
113
+
114
+ return {
115
+ toolName: 'consistency',
116
+ score,
117
+ rawMetrics: {
118
+ totalIssues,
119
+ criticalIssues,
120
+ majorIssues,
121
+ minorIssues,
122
+ issuesPerFile: Math.round(issuesPerFile * 100) / 100,
123
+ avgWeightedIssuesPerFile: Math.round(avgWeightedIssuesPerFile * 100) / 100,
124
+ },
125
+ factors,
126
+ recommendations,
127
+ };
128
+ }