@boyingliu01/xp-gate 0.38.34 → 0.38.36
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.
- package/adapters/powershell.sh +2 -0
- package/adapters/shell.sh +7 -0
- package/adapters/typescript.sh +51 -1
- package/hooks/gate-entries/gate-2-entry.sh +16 -0
- package/hooks/gate-entries/gate-5-entry.sh +181 -16
- package/hooks/lib/jscpd-run.sh +53 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/principles/__tests__/analyzer.test.ts +1 -1
- package/principles/__tests__/config-enforcement.test.ts +1 -1
- package/principles/__tests__/reporter.test.ts +175 -347
- package/principles/__tests__/types.test.ts +1 -1
- package/principles/adapters/base.ts +26 -0
- package/principles/adapters/csharp.ts +7 -0
- package/principles/adapters/java.ts +7 -0
- package/principles/adapters/typescript.ts +7 -0
- package/principles/analyzer.ts +70 -13
- package/principles/reporter.ts +29 -1
- package/principles/rules/__tests__/clean-code/large-file.test.ts +1 -1
- package/principles/types.ts +29 -0
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -8,42 +8,89 @@ import { describe, it, expect } from 'vitest';
|
|
|
8
8
|
import { formatConsole, formatJSON, formatSARIF, formatSummary } from '../reporter';
|
|
9
9
|
import { AnalysisResult, Violation } from '../analyzer';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Build an AnalysisResult summary.
|
|
13
|
+
*
|
|
14
|
+
* Extracted because these fixtures were written out in full 25 times, which the
|
|
15
|
+
* clean-code.code-duplication rule scored at 44.2% (threshold 15%) and the Boy
|
|
16
|
+
* Scout gate then blocked. The counts are positional rather than a params object
|
|
17
|
+
* because every call site already reads as one line of counts, and a named-field
|
|
18
|
+
* object per fixture would be longer than the literal it replaces.
|
|
19
|
+
*
|
|
20
|
+
* `unanalysedLanguages` defaults to empty: no fixture here exercises the
|
|
21
|
+
* not-analysed notice, and tests that do set it explicitly via the options and
|
|
22
|
+
* assert on it there.
|
|
23
|
+
*/
|
|
24
|
+
function summaryOf(
|
|
25
|
+
totalViolations: number,
|
|
26
|
+
errorCount: number,
|
|
27
|
+
warningCount: number,
|
|
28
|
+
infoCount: number,
|
|
29
|
+
filesChecked: number,
|
|
30
|
+
rulesRun: number,
|
|
31
|
+
unanalysedLanguages: string[] = []
|
|
32
|
+
): AnalysisResult['summary'] {
|
|
33
|
+
return {
|
|
34
|
+
totalViolations,
|
|
35
|
+
errorCount,
|
|
36
|
+
warningCount,
|
|
37
|
+
infoCount,
|
|
38
|
+
filesChecked,
|
|
39
|
+
rulesRun,
|
|
40
|
+
unanalysedLanguages,
|
|
19
41
|
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The empty `fileResults` / `ruleResults` / `errors` set plus a duration.
|
|
46
|
+
*
|
|
47
|
+
* These lines appeared verbatim in 14 fixtures -- the remainder of the
|
|
48
|
+
* duplication the `summaryOf` extraction above did not reach (`errors: []` alone
|
|
49
|
+
* accounted for 21 of the repeated 3-line windows). Kept separate from summaryOf
|
|
50
|
+
* because the two vary independently: several tests supply real ruleResults, and
|
|
51
|
+
* one supplies a NaN errorCount.
|
|
52
|
+
*/
|
|
53
|
+
function emptyResults(executionTimeMs: number): Pick<
|
|
54
|
+
AnalysisResult,
|
|
55
|
+
'fileResults' | 'ruleResults' | 'executionTimeMs' | 'errors'
|
|
56
|
+
> {
|
|
57
|
+
return { fileResults: {}, ruleResults: {}, executionTimeMs, errors: [] };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Build a Violation.
|
|
62
|
+
*
|
|
63
|
+
* These were written out as five-to-six line object literals 17 times, which the
|
|
64
|
+
* clean-code.code-duplication rule scored well above its 15% threshold and the
|
|
65
|
+
* Boy Scout gate blocked. Named fields would be longer than the literal they
|
|
66
|
+
* replace and would bury the one thing each fixture is really saying -- which
|
|
67
|
+
* file, which rule, which message -- so the two axes stay positional here.
|
|
68
|
+
*
|
|
69
|
+
* `column` is optional because only the first fixture asserts on it.
|
|
70
|
+
*/
|
|
71
|
+
function violation(
|
|
72
|
+
file: string,
|
|
73
|
+
line: number,
|
|
74
|
+
ruleId: string,
|
|
75
|
+
message: string,
|
|
76
|
+
severity: Violation['severity'],
|
|
77
|
+
column?: number
|
|
78
|
+
): Violation {
|
|
79
|
+
return column === undefined
|
|
80
|
+
? { file, line, ruleId, message, severity }
|
|
81
|
+
: { file, line, column, ruleId, message, severity };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('reporter.ts - Output Formatting', () => {
|
|
85
|
+
const sampleViolation: Violation = violation("src/test.ts", 10, "clean-code.long-function", "Function \"processData\" is too long: 65 lines (maximum: 50)", "warning", 5);
|
|
20
86
|
|
|
21
87
|
const sampleResult: AnalysisResult = {
|
|
22
88
|
violations: [
|
|
23
89
|
sampleViolation,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
line: 1,
|
|
27
|
-
ruleId: 'clean-code.large-file',
|
|
28
|
-
message: 'File is too large: 600 lines (maximum: 500)',
|
|
29
|
-
severity: 'warning'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
file: 'src/api.ts',
|
|
33
|
-
line: 20,
|
|
34
|
-
ruleId: 'solid.dip',
|
|
35
|
-
message: 'Direct instantiation detected: new UserRepository()',
|
|
36
|
-
severity: 'warning'
|
|
37
|
-
}
|
|
90
|
+
violation("src/utils.ts", 1, "clean-code.large-file", "File is too large: 600 lines (maximum: 500)", "warning"),
|
|
91
|
+
violation("src/api.ts", 20, "solid.dip", "Direct instantiation detected: new UserRepository()", "warning")
|
|
38
92
|
],
|
|
39
|
-
summary:
|
|
40
|
-
totalViolations: 3,
|
|
41
|
-
errorCount: 0,
|
|
42
|
-
warningCount: 3,
|
|
43
|
-
infoCount: 0,
|
|
44
|
-
filesChecked: 3,
|
|
45
|
-
rulesRun: 3
|
|
46
|
-
},
|
|
93
|
+
summary: summaryOf(3, 0, 3, 0, 3, 3),
|
|
47
94
|
fileResults: {
|
|
48
95
|
'src/test.ts': { violations: [sampleViolation], ruleIds: ['clean-code.long-function'] }
|
|
49
96
|
},
|
|
@@ -89,18 +136,8 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
89
136
|
it('should handle empty violations', () => {
|
|
90
137
|
const emptyResult: AnalysisResult = {
|
|
91
138
|
violations: [],
|
|
92
|
-
summary:
|
|
93
|
-
|
|
94
|
-
errorCount: 0,
|
|
95
|
-
warningCount: 0,
|
|
96
|
-
infoCount: 0,
|
|
97
|
-
filesChecked: 5,
|
|
98
|
-
rulesRun: 3
|
|
99
|
-
},
|
|
100
|
-
fileResults: {},
|
|
101
|
-
ruleResults: {},
|
|
102
|
-
executionTimeMs: 50,
|
|
103
|
-
errors: []
|
|
139
|
+
summary: summaryOf(0, 0, 0, 0, 5, 3),
|
|
140
|
+
...emptyResults(50),
|
|
104
141
|
};
|
|
105
142
|
|
|
106
143
|
const output = formatConsole(emptyResult);
|
|
@@ -163,21 +200,63 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
163
200
|
expect(output).toContain('FAIL');
|
|
164
201
|
});
|
|
165
202
|
|
|
203
|
+
it('should not read a missing summary as FAIL (NaN must not decide the verdict)', () => {
|
|
204
|
+
// Round 3 of the Delphi review, three seats independently: `undefined + 0`
|
|
205
|
+
// is NaN, and `NaN === 0` is false, so an incomplete summary would make
|
|
206
|
+
// this report FAIL unconditionally -- the exact symptom the info fix
|
|
207
|
+
// removed, reintroduced through a different door. formatSummary is
|
|
208
|
+
// exported, so it cannot assume its caller honoured the type.
|
|
209
|
+
const noSummary = {
|
|
210
|
+
violations: [],
|
|
211
|
+
...emptyResults(1),
|
|
212
|
+
} as unknown as AnalysisResult;
|
|
213
|
+
|
|
214
|
+
const output = formatSummary(noSummary);
|
|
215
|
+
expect(output).toContain('PASS');
|
|
216
|
+
expect(output).not.toContain('NaN');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should flag a malformed summary instead of silently treating it as clean', () => {
|
|
220
|
+
// Round 5, three seats independently: zeroing a non-numeric count stops the
|
|
221
|
+
// permanent-FAIL bug but also swallows an upstream defect -- a corrupted
|
|
222
|
+
// summary would read as "nothing to report". Keep the non-blocking verdict
|
|
223
|
+
// (crashing the reporter would be worse) but say so in the output.
|
|
224
|
+
const corrupted = {
|
|
225
|
+
violations: [],
|
|
226
|
+
summary: summaryOf(1, Number.NaN, 0, 0, 1, 1),
|
|
227
|
+
...emptyResults(1),
|
|
228
|
+
} as unknown as AnalysisResult;
|
|
229
|
+
|
|
230
|
+
const output = formatSummary(corrupted);
|
|
231
|
+
expect(output).toMatch(/malformed|invalid|corrupt/i);
|
|
232
|
+
// The damaged field must be named, so a reader can tell WHICH count is
|
|
233
|
+
// untrustworthy. Echoing the raw value is the point of the diagnostic --
|
|
234
|
+
// only the verdict must never be decided by it.
|
|
235
|
+
expect(output).toContain('errorCount');
|
|
236
|
+
expect(output).toContain('PASS');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should show PASS when the only findings are info (info is log-only)', () => {
|
|
240
|
+
// AGENTS.md: info = "log only". An info finding is how a rule says "I
|
|
241
|
+
// could not judge this file" (the arch layout diagnostic), so treating it
|
|
242
|
+
// as a failure would block a commit for a blind spot rather than a defect.
|
|
243
|
+
const infoOnly: AnalysisResult = {
|
|
244
|
+
violations: [
|
|
245
|
+
violation("java/com/acme/UserController.java", 1, "arch.controller", "Skipped: no recognisable Java source root", "info")
|
|
246
|
+
],
|
|
247
|
+
summary: summaryOf(1, 0, 0, 1, 1, 1),
|
|
248
|
+
...emptyResults(1),
|
|
249
|
+
};
|
|
250
|
+
const output = formatSummary(infoOnly);
|
|
251
|
+
expect(output).toContain('PASS');
|
|
252
|
+
expect(output).not.toContain('FAIL');
|
|
253
|
+
});
|
|
254
|
+
|
|
166
255
|
it('should show PASS when no violations', () => {
|
|
167
256
|
const emptyResult: AnalysisResult = {
|
|
168
257
|
violations: [],
|
|
169
|
-
summary:
|
|
170
|
-
|
|
171
|
-
errorCount: 0,
|
|
172
|
-
warningCount: 0,
|
|
173
|
-
infoCount: 0,
|
|
174
|
-
filesChecked: 5,
|
|
175
|
-
rulesRun: 3
|
|
176
|
-
},
|
|
177
|
-
fileResults: {},
|
|
178
|
-
ruleResults: {},
|
|
179
|
-
executionTimeMs: 50,
|
|
180
|
-
errors: []
|
|
258
|
+
summary: summaryOf(0, 0, 0, 0, 5, 3),
|
|
259
|
+
...emptyResults(50),
|
|
181
260
|
};
|
|
182
261
|
|
|
183
262
|
const output = formatSummary(emptyResult);
|
|
@@ -188,26 +267,10 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
188
267
|
it('should show error count when severity has errors', () => {
|
|
189
268
|
const errorResult: AnalysisResult = {
|
|
190
269
|
violations: [
|
|
191
|
-
|
|
192
|
-
file: 'src/auth.ts',
|
|
193
|
-
line: 5,
|
|
194
|
-
ruleId: 'solid.srp',
|
|
195
|
-
message: 'Class handles both auth and logging',
|
|
196
|
-
severity: 'error'
|
|
197
|
-
}
|
|
270
|
+
violation("src/auth.ts", 5, "solid.srp", "Class handles both auth and logging", "error")
|
|
198
271
|
],
|
|
199
|
-
summary:
|
|
200
|
-
|
|
201
|
-
errorCount: 1,
|
|
202
|
-
warningCount: 0,
|
|
203
|
-
infoCount: 0,
|
|
204
|
-
filesChecked: 1,
|
|
205
|
-
rulesRun: 1
|
|
206
|
-
},
|
|
207
|
-
fileResults: {},
|
|
208
|
-
ruleResults: {},
|
|
209
|
-
executionTimeMs: 30,
|
|
210
|
-
errors: []
|
|
272
|
+
summary: summaryOf(1, 1, 0, 0, 1, 1),
|
|
273
|
+
...emptyResults(30),
|
|
211
274
|
};
|
|
212
275
|
|
|
213
276
|
const output = formatSummary(errorResult);
|
|
@@ -221,14 +284,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
221
284
|
it('should return valid SARIF JSON with version 2.1.0', () => {
|
|
222
285
|
const result: AnalysisResult = {
|
|
223
286
|
violations: [sampleViolation],
|
|
224
|
-
summary:
|
|
225
|
-
totalViolations: 1,
|
|
226
|
-
errorCount: 0,
|
|
227
|
-
warningCount: 1,
|
|
228
|
-
infoCount: 0,
|
|
229
|
-
filesChecked: 1,
|
|
230
|
-
rulesRun: 1
|
|
231
|
-
},
|
|
287
|
+
summary: summaryOf(1, 0, 1, 0, 1, 1),
|
|
232
288
|
fileResults: {},
|
|
233
289
|
ruleResults: {
|
|
234
290
|
'clean-code.long-function': { violationCount: 1, filesChecked: 1 }
|
|
@@ -247,14 +303,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
247
303
|
it('should include runs array with tool driver info', () => {
|
|
248
304
|
const result: AnalysisResult = {
|
|
249
305
|
violations: [sampleViolation],
|
|
250
|
-
summary:
|
|
251
|
-
totalViolations: 1,
|
|
252
|
-
errorCount: 0,
|
|
253
|
-
warningCount: 1,
|
|
254
|
-
infoCount: 0,
|
|
255
|
-
filesChecked: 3,
|
|
256
|
-
rulesRun: 2
|
|
257
|
-
},
|
|
306
|
+
summary: summaryOf(1, 0, 1, 0, 3, 2),
|
|
258
307
|
fileResults: {},
|
|
259
308
|
ruleResults: {
|
|
260
309
|
'clean-code.long-function': { violationCount: 1, filesChecked: 3 }
|
|
@@ -275,37 +324,11 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
275
324
|
it('should map violations to SARIF results with correct levels', () => {
|
|
276
325
|
const result: AnalysisResult = {
|
|
277
326
|
violations: [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
column: 10,
|
|
282
|
-
ruleId: 'solid.srp',
|
|
283
|
-
message: 'Multiple responsibilities',
|
|
284
|
-
severity: 'error'
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
file: 'src/utils.ts',
|
|
288
|
-
line: 20,
|
|
289
|
-
ruleId: 'clean-code.long-function',
|
|
290
|
-
message: 'Function too long',
|
|
291
|
-
severity: 'warning'
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
file: 'src/config.ts',
|
|
295
|
-
line: 3,
|
|
296
|
-
ruleId: 'clean-code.magic-numbers',
|
|
297
|
-
message: 'Magic number 42',
|
|
298
|
-
severity: 'info'
|
|
299
|
-
}
|
|
327
|
+
violation("src/auth.ts", 5, "solid.srp", "Multiple responsibilities", "error", 10),
|
|
328
|
+
violation("src/utils.ts", 20, "clean-code.long-function", "Function too long", "warning"),
|
|
329
|
+
violation("src/config.ts", 3, "clean-code.magic-numbers", "Magic number 42", "info")
|
|
300
330
|
],
|
|
301
|
-
summary:
|
|
302
|
-
totalViolations: 3,
|
|
303
|
-
errorCount: 1,
|
|
304
|
-
warningCount: 1,
|
|
305
|
-
infoCount: 1,
|
|
306
|
-
filesChecked: 3,
|
|
307
|
-
rulesRun: 3
|
|
308
|
-
},
|
|
331
|
+
summary: summaryOf(3, 1, 1, 1, 3, 3),
|
|
309
332
|
fileResults: {},
|
|
310
333
|
ruleResults: {
|
|
311
334
|
'solid.srp': { violationCount: 1, filesChecked: 1 },
|
|
@@ -329,23 +352,9 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
329
352
|
it('should include file, line, and column in result locations', () => {
|
|
330
353
|
const result: AnalysisResult = {
|
|
331
354
|
violations: [
|
|
332
|
-
|
|
333
|
-
file: 'src/api.ts',
|
|
334
|
-
line: 42,
|
|
335
|
-
column: 15,
|
|
336
|
-
ruleId: 'clean-code.deep-nesting',
|
|
337
|
-
message: 'Nesting depth 6 exceeds threshold 4',
|
|
338
|
-
severity: 'warning'
|
|
339
|
-
}
|
|
355
|
+
violation("src/api.ts", 42, "clean-code.deep-nesting", "Nesting depth 6 exceeds threshold 4", "warning", 15)
|
|
340
356
|
],
|
|
341
|
-
summary:
|
|
342
|
-
totalViolations: 1,
|
|
343
|
-
errorCount: 0,
|
|
344
|
-
warningCount: 1,
|
|
345
|
-
infoCount: 0,
|
|
346
|
-
filesChecked: 1,
|
|
347
|
-
rulesRun: 1
|
|
348
|
-
},
|
|
357
|
+
summary: summaryOf(1, 0, 1, 0, 1, 1),
|
|
349
358
|
fileResults: {},
|
|
350
359
|
ruleResults: {
|
|
351
360
|
'clean-code.deep-nesting': { violationCount: 1, filesChecked: 1 }
|
|
@@ -366,22 +375,9 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
366
375
|
it('should default column to 1 when violation has no column', () => {
|
|
367
376
|
const result: AnalysisResult = {
|
|
368
377
|
violations: [
|
|
369
|
-
|
|
370
|
-
file: 'src/big.ts',
|
|
371
|
-
line: 500,
|
|
372
|
-
ruleId: 'clean-code.large-file',
|
|
373
|
-
message: 'File too large',
|
|
374
|
-
severity: 'warning'
|
|
375
|
-
}
|
|
378
|
+
violation("src/big.ts", 500, "clean-code.large-file", "File too large", "warning")
|
|
376
379
|
],
|
|
377
|
-
summary:
|
|
378
|
-
totalViolations: 1,
|
|
379
|
-
errorCount: 0,
|
|
380
|
-
warningCount: 1,
|
|
381
|
-
infoCount: 0,
|
|
382
|
-
filesChecked: 1,
|
|
383
|
-
rulesRun: 1
|
|
384
|
-
},
|
|
380
|
+
summary: summaryOf(1, 0, 1, 0, 1, 1),
|
|
385
381
|
fileResults: {},
|
|
386
382
|
ruleResults: {
|
|
387
383
|
'clean-code.large-file': { violationCount: 1, filesChecked: 1 }
|
|
@@ -400,14 +396,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
400
396
|
it('should include ruleDescriptors for all rules in ruleResults', () => {
|
|
401
397
|
const result: AnalysisResult = {
|
|
402
398
|
violations: [sampleViolation],
|
|
403
|
-
summary:
|
|
404
|
-
totalViolations: 1,
|
|
405
|
-
errorCount: 0,
|
|
406
|
-
warningCount: 1,
|
|
407
|
-
infoCount: 0,
|
|
408
|
-
filesChecked: 2,
|
|
409
|
-
rulesRun: 2
|
|
410
|
-
},
|
|
399
|
+
summary: summaryOf(1, 0, 1, 0, 2, 2),
|
|
411
400
|
fileResults: {},
|
|
412
401
|
ruleResults: {
|
|
413
402
|
'clean-code.long-function': { violationCount: 1, filesChecked: 2 },
|
|
@@ -431,14 +420,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
431
420
|
it('should include execution properties (filesChecked, rulesRun, executionTimeMs)', () => {
|
|
432
421
|
const result: AnalysisResult = {
|
|
433
422
|
violations: [],
|
|
434
|
-
summary:
|
|
435
|
-
totalViolations: 0,
|
|
436
|
-
errorCount: 0,
|
|
437
|
-
warningCount: 0,
|
|
438
|
-
infoCount: 0,
|
|
439
|
-
filesChecked: 10,
|
|
440
|
-
rulesRun: 5
|
|
441
|
-
},
|
|
423
|
+
summary: summaryOf(0, 0, 0, 0, 10, 5),
|
|
442
424
|
fileResults: {},
|
|
443
425
|
ruleResults: {
|
|
444
426
|
'clean-code.long-function': { violationCount: 0, filesChecked: 10 }
|
|
@@ -459,14 +441,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
459
441
|
it('should return empty results array when no violations', () => {
|
|
460
442
|
const result: AnalysisResult = {
|
|
461
443
|
violations: [],
|
|
462
|
-
summary:
|
|
463
|
-
totalViolations: 0,
|
|
464
|
-
errorCount: 0,
|
|
465
|
-
warningCount: 0,
|
|
466
|
-
infoCount: 0,
|
|
467
|
-
filesChecked: 5,
|
|
468
|
-
rulesRun: 3
|
|
469
|
-
},
|
|
444
|
+
summary: summaryOf(0, 0, 0, 0, 5, 3),
|
|
470
445
|
fileResults: {},
|
|
471
446
|
ruleResults: {
|
|
472
447
|
'clean-code.long-function': { violationCount: 0, filesChecked: 5 }
|
|
@@ -484,23 +459,9 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
484
459
|
it('should map DIP violation to error level when violation severity is error', () => {
|
|
485
460
|
const result: AnalysisResult = {
|
|
486
461
|
violations: [
|
|
487
|
-
|
|
488
|
-
file: 'src/service.ts',
|
|
489
|
-
line: 8,
|
|
490
|
-
column: 1,
|
|
491
|
-
ruleId: 'solid.dip',
|
|
492
|
-
message: 'Direct instantiation detected',
|
|
493
|
-
severity: 'error'
|
|
494
|
-
}
|
|
462
|
+
violation("src/service.ts", 8, "solid.dip", "Direct instantiation detected", "error", 1)
|
|
495
463
|
],
|
|
496
|
-
summary:
|
|
497
|
-
totalViolations: 1,
|
|
498
|
-
errorCount: 1,
|
|
499
|
-
warningCount: 0,
|
|
500
|
-
infoCount: 0,
|
|
501
|
-
filesChecked: 1,
|
|
502
|
-
rulesRun: 1
|
|
503
|
-
},
|
|
464
|
+
summary: summaryOf(1, 1, 0, 0, 1, 1),
|
|
504
465
|
fileResults: {},
|
|
505
466
|
ruleResults: {
|
|
506
467
|
'solid.dip': { violationCount: 1, filesChecked: 1 }
|
|
@@ -518,14 +479,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
518
479
|
it('should include ruleDescriptors with defaultConfiguration levels', () => {
|
|
519
480
|
const result: AnalysisResult = {
|
|
520
481
|
violations: [],
|
|
521
|
-
summary:
|
|
522
|
-
totalViolations: 0,
|
|
523
|
-
errorCount: 0,
|
|
524
|
-
warningCount: 0,
|
|
525
|
-
infoCount: 0,
|
|
526
|
-
filesChecked: 1,
|
|
527
|
-
rulesRun: 3
|
|
528
|
-
},
|
|
482
|
+
summary: summaryOf(0, 0, 0, 0, 1, 3),
|
|
529
483
|
fileResults: {},
|
|
530
484
|
ruleResults: {
|
|
531
485
|
'solid.srp': { violationCount: 0, filesChecked: 1 },
|
|
@@ -554,27 +508,10 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
554
508
|
it('should show error severity with ✗ icon', () => {
|
|
555
509
|
const errorResult: AnalysisResult = {
|
|
556
510
|
violations: [
|
|
557
|
-
|
|
558
|
-
file: 'src/auth.ts',
|
|
559
|
-
line: 5,
|
|
560
|
-
column: 1,
|
|
561
|
-
ruleId: 'solid.srp',
|
|
562
|
-
message: 'Multiple responsibilities',
|
|
563
|
-
severity: 'error'
|
|
564
|
-
}
|
|
511
|
+
violation("src/auth.ts", 5, "solid.srp", "Multiple responsibilities", "error", 1)
|
|
565
512
|
],
|
|
566
|
-
summary:
|
|
567
|
-
|
|
568
|
-
errorCount: 1,
|
|
569
|
-
warningCount: 0,
|
|
570
|
-
infoCount: 0,
|
|
571
|
-
filesChecked: 1,
|
|
572
|
-
rulesRun: 1
|
|
573
|
-
},
|
|
574
|
-
fileResults: {},
|
|
575
|
-
ruleResults: {},
|
|
576
|
-
executionTimeMs: 30,
|
|
577
|
-
errors: []
|
|
513
|
+
summary: summaryOf(1, 1, 0, 0, 1, 1),
|
|
514
|
+
...emptyResults(30),
|
|
578
515
|
};
|
|
579
516
|
|
|
580
517
|
const output = formatConsole(errorResult);
|
|
@@ -586,27 +523,10 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
586
523
|
it('should show info severity with ℹ icon', () => {
|
|
587
524
|
const infoResult: AnalysisResult = {
|
|
588
525
|
violations: [
|
|
589
|
-
|
|
590
|
-
file: 'src/config.ts',
|
|
591
|
-
line: 3,
|
|
592
|
-
column: 10,
|
|
593
|
-
ruleId: 'clean-code.magic-numbers',
|
|
594
|
-
message: 'Magic number 42',
|
|
595
|
-
severity: 'info'
|
|
596
|
-
}
|
|
526
|
+
violation("src/config.ts", 3, "clean-code.magic-numbers", "Magic number 42", "info", 10)
|
|
597
527
|
],
|
|
598
|
-
summary:
|
|
599
|
-
|
|
600
|
-
errorCount: 0,
|
|
601
|
-
warningCount: 0,
|
|
602
|
-
infoCount: 1,
|
|
603
|
-
filesChecked: 1,
|
|
604
|
-
rulesRun: 1
|
|
605
|
-
},
|
|
606
|
-
fileResults: {},
|
|
607
|
-
ruleResults: {},
|
|
608
|
-
executionTimeMs: 20,
|
|
609
|
-
errors: []
|
|
528
|
+
summary: summaryOf(1, 0, 0, 1, 1, 1),
|
|
529
|
+
...emptyResults(20),
|
|
610
530
|
};
|
|
611
531
|
|
|
612
532
|
const output = formatConsole(infoResult);
|
|
@@ -618,26 +538,10 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
618
538
|
it('should handle violations without column number', () => {
|
|
619
539
|
const noColumnResult: AnalysisResult = {
|
|
620
540
|
violations: [
|
|
621
|
-
|
|
622
|
-
file: 'src/big.ts',
|
|
623
|
-
line: 600,
|
|
624
|
-
ruleId: 'clean-code.large-file',
|
|
625
|
-
message: 'File is too large: 600 lines (maximum: 500)',
|
|
626
|
-
severity: 'warning'
|
|
627
|
-
}
|
|
541
|
+
violation("src/big.ts", 600, "clean-code.large-file", "File is too large: 600 lines (maximum: 500)", "warning")
|
|
628
542
|
],
|
|
629
|
-
summary:
|
|
630
|
-
|
|
631
|
-
errorCount: 0,
|
|
632
|
-
warningCount: 1,
|
|
633
|
-
infoCount: 0,
|
|
634
|
-
filesChecked: 1,
|
|
635
|
-
rulesRun: 1
|
|
636
|
-
},
|
|
637
|
-
fileResults: {},
|
|
638
|
-
ruleResults: {},
|
|
639
|
-
executionTimeMs: 25,
|
|
640
|
-
errors: []
|
|
543
|
+
summary: summaryOf(1, 0, 1, 0, 1, 1),
|
|
544
|
+
...emptyResults(25),
|
|
641
545
|
};
|
|
642
546
|
|
|
643
547
|
const output = formatConsole(noColumnResult);
|
|
@@ -649,26 +553,10 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
649
553
|
it('should include analysis errors only when violations exist', () => {
|
|
650
554
|
const resultWithErrors: AnalysisResult = {
|
|
651
555
|
violations: [
|
|
652
|
-
|
|
653
|
-
file: 'src/test.ts',
|
|
654
|
-
line: 5,
|
|
655
|
-
column: 1,
|
|
656
|
-
ruleId: 'clean-code.long-function',
|
|
657
|
-
message: 'Function too long',
|
|
658
|
-
severity: 'warning'
|
|
659
|
-
}
|
|
556
|
+
violation("src/test.ts", 5, "clean-code.long-function", "Function too long", "warning", 1)
|
|
660
557
|
],
|
|
661
|
-
summary:
|
|
662
|
-
|
|
663
|
-
errorCount: 0,
|
|
664
|
-
warningCount: 1,
|
|
665
|
-
infoCount: 0,
|
|
666
|
-
filesChecked: 2,
|
|
667
|
-
rulesRun: 1
|
|
668
|
-
},
|
|
669
|
-
fileResults: {},
|
|
670
|
-
ruleResults: {},
|
|
671
|
-
executionTimeMs: 50,
|
|
558
|
+
summary: summaryOf(1, 0, 1, 0, 2, 1),
|
|
559
|
+
...emptyResults(50),
|
|
672
560
|
errors: [
|
|
673
561
|
'Rule clean-code.long-function failed on src/corrupt.ts: Parse error',
|
|
674
562
|
'Rule solid.srp failed on src/broken.ts: Timeout'
|
|
@@ -685,18 +573,8 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
685
573
|
it('should not show analysis errors section when errors array is empty', () => {
|
|
686
574
|
const emptyResult: AnalysisResult = {
|
|
687
575
|
violations: [],
|
|
688
|
-
summary:
|
|
689
|
-
|
|
690
|
-
errorCount: 0,
|
|
691
|
-
warningCount: 0,
|
|
692
|
-
infoCount: 0,
|
|
693
|
-
filesChecked: 5,
|
|
694
|
-
rulesRun: 3
|
|
695
|
-
},
|
|
696
|
-
fileResults: {},
|
|
697
|
-
ruleResults: {},
|
|
698
|
-
executionTimeMs: 50,
|
|
699
|
-
errors: []
|
|
576
|
+
summary: summaryOf(0, 0, 0, 0, 5, 3),
|
|
577
|
+
...emptyResults(50),
|
|
700
578
|
};
|
|
701
579
|
|
|
702
580
|
const output = formatConsole(emptyResult);
|
|
@@ -707,18 +585,8 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
707
585
|
it('should show files checked in empty violations output', () => {
|
|
708
586
|
const emptyResult: AnalysisResult = {
|
|
709
587
|
violations: [],
|
|
710
|
-
summary:
|
|
711
|
-
|
|
712
|
-
errorCount: 0,
|
|
713
|
-
warningCount: 0,
|
|
714
|
-
infoCount: 0,
|
|
715
|
-
filesChecked: 15,
|
|
716
|
-
rulesRun: 8
|
|
717
|
-
},
|
|
718
|
-
fileResults: {},
|
|
719
|
-
ruleResults: {},
|
|
720
|
-
executionTimeMs: 75,
|
|
721
|
-
errors: []
|
|
588
|
+
summary: summaryOf(0, 0, 0, 0, 15, 8),
|
|
589
|
+
...emptyResults(75),
|
|
722
590
|
};
|
|
723
591
|
|
|
724
592
|
const output = formatConsole(emptyResult);
|
|
@@ -731,34 +599,11 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
731
599
|
it('should include summary section with violation details', () => {
|
|
732
600
|
const mixedResult: AnalysisResult = {
|
|
733
601
|
violations: [
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
line: 5,
|
|
737
|
-
column: 1,
|
|
738
|
-
ruleId: 'solid.srp',
|
|
739
|
-
message: 'SRP violation',
|
|
740
|
-
severity: 'error'
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
file: 'src/b.ts',
|
|
744
|
-
line: 10,
|
|
745
|
-
ruleId: 'clean-code.long-function',
|
|
746
|
-
message: 'Too long',
|
|
747
|
-
severity: 'warning'
|
|
748
|
-
}
|
|
602
|
+
violation("src/a.ts", 5, "solid.srp", "SRP violation", "error", 1),
|
|
603
|
+
violation("src/b.ts", 10, "clean-code.long-function", "Too long", "warning")
|
|
749
604
|
],
|
|
750
|
-
summary:
|
|
751
|
-
|
|
752
|
-
errorCount: 1,
|
|
753
|
-
warningCount: 1,
|
|
754
|
-
infoCount: 0,
|
|
755
|
-
filesChecked: 2,
|
|
756
|
-
rulesRun: 2
|
|
757
|
-
},
|
|
758
|
-
fileResults: {},
|
|
759
|
-
ruleResults: {},
|
|
760
|
-
executionTimeMs: 60,
|
|
761
|
-
errors: []
|
|
605
|
+
summary: summaryOf(2, 1, 1, 0, 2, 2),
|
|
606
|
+
...emptyResults(60),
|
|
762
607
|
};
|
|
763
608
|
|
|
764
609
|
const output = formatConsole(mixedResult);
|
|
@@ -775,18 +620,8 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
775
620
|
it('should include empty arrays for no violations', () => {
|
|
776
621
|
const emptyResult: AnalysisResult = {
|
|
777
622
|
violations: [],
|
|
778
|
-
summary:
|
|
779
|
-
|
|
780
|
-
errorCount: 0,
|
|
781
|
-
warningCount: 0,
|
|
782
|
-
infoCount: 0,
|
|
783
|
-
filesChecked: 5,
|
|
784
|
-
rulesRun: 3
|
|
785
|
-
},
|
|
786
|
-
fileResults: {},
|
|
787
|
-
ruleResults: {},
|
|
788
|
-
executionTimeMs: 30,
|
|
789
|
-
errors: []
|
|
623
|
+
summary: summaryOf(0, 0, 0, 0, 5, 3),
|
|
624
|
+
...emptyResults(30),
|
|
790
625
|
};
|
|
791
626
|
|
|
792
627
|
const output = formatJSON(emptyResult);
|
|
@@ -800,14 +635,7 @@ describe('reporter.ts - Output Formatting', () => {
|
|
|
800
635
|
it('should include all fields: violations, summary, fileResults, ruleResults, executionTimeMs, errors', () => {
|
|
801
636
|
const result: AnalysisResult = {
|
|
802
637
|
violations: [sampleViolation],
|
|
803
|
-
summary:
|
|
804
|
-
totalViolations: 1,
|
|
805
|
-
errorCount: 0,
|
|
806
|
-
warningCount: 1,
|
|
807
|
-
infoCount: 0,
|
|
808
|
-
filesChecked: 3,
|
|
809
|
-
rulesRun: 2
|
|
810
|
-
},
|
|
638
|
+
summary: summaryOf(1, 0, 1, 0, 3, 2),
|
|
811
639
|
fileResults: {
|
|
812
640
|
'src/test.ts': { violations: [sampleViolation], ruleIds: ['clean-code.long-function'] }
|
|
813
641
|
},
|