@boyingliu01/xp-gate 0.38.76 → 0.38.77

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 (104) hide show
  1. package/lib/__tests__/mirror-sync.test.js +387 -5
  2. package/lib/mattpocock-license-verdict.json +1 -1
  3. package/lib/mirror-sync.js +202 -15
  4. package/package.json +1 -1
  5. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  6. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  7. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  8. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  9. package/plugins/dsh/package.json +1 -1
  10. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  11. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  12. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  13. package/plugins/opencode/package.json +1 -1
  14. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/qoder/plugin.json +1 -1
  18. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  19. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  20. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  21. package/scripts/generate-mirrors.cjs +10 -0
  22. package/skills/delphi-review/AGENTS.md +1 -1
  23. package/skills/sprint-flow/AGENTS.md +1 -1
  24. package/skills/test-specification-alignment/AGENTS.md +1 -1
  25. package/mock-policy/__tests__/config.test.ts +0 -292
  26. package/mock-policy/__tests__/gate-m3.test.ts +0 -379
  27. package/mock-policy/__tests__/integration.test.ts +0 -600
  28. package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
  29. package/mock-policy/__tests__/schema.test.ts +0 -239
  30. package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
  31. package/mutation/__tests__/detect-ai-test.test.ts +0 -152
  32. package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
  33. package/mutation/__tests__/gate-m.test.ts +0 -246
  34. package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
  35. package/mutation/__tests__/gremlins-runner.test.ts +0 -167
  36. package/mutation/__tests__/init-baseline.test.ts +0 -347
  37. package/mutation/__tests__/mutation-mirror.test.ts +0 -49
  38. package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
  39. package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
  40. package/mutation/__tests__/pitest-runner.test.ts +0 -574
  41. package/mutation/__tests__/runners-index.test.ts +0 -162
  42. package/mutation/__tests__/stryker-runner.test.ts +0 -455
  43. package/mutation/__tests__/test-filter-parity.test.ts +0 -40
  44. package/mutation/__tests__/update-baseline.test.ts +0 -395
  45. package/principles/__tests__/adapter-metrics.test.ts +0 -292
  46. package/principles/__tests__/analyze-read-failure.test.ts +0 -70
  47. package/principles/__tests__/analyzer.test.ts +0 -367
  48. package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
  49. package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
  50. package/principles/__tests__/baseline-prune.test.ts +0 -399
  51. package/principles/__tests__/baseline-storage.test.ts +0 -188
  52. package/principles/__tests__/baseline.test.ts +0 -330
  53. package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
  54. package/principles/__tests__/boy-scout-integration.test.ts +0 -355
  55. package/principles/__tests__/boy-scout.test.ts +0 -893
  56. package/principles/__tests__/cli-files-separators.test.ts +0 -69
  57. package/principles/__tests__/config-arch-group.test.ts +0 -106
  58. package/principles/__tests__/config-enforcement.test.ts +0 -470
  59. package/principles/__tests__/config-git-timeout.test.ts +0 -66
  60. package/principles/__tests__/config-merge-warnings.test.ts +0 -148
  61. package/principles/__tests__/config.test.ts +0 -78
  62. package/principles/__tests__/direct-execution.test.ts +0 -187
  63. package/principles/__tests__/index.test.ts +0 -94
  64. package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
  65. package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
  66. package/principles/__tests__/lint-baseline.test.ts +0 -314
  67. package/principles/__tests__/many-exports-reexport.test.ts +0 -40
  68. package/principles/__tests__/reporter.test.ts +0 -660
  69. package/principles/__tests__/types.test.ts +0 -103
  70. package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
  71. package/principles/adapters/__tests__/base.test.ts +0 -95
  72. package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
  73. package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
  74. package/principles/adapters/__tests__/cpp.test.ts +0 -290
  75. package/principles/adapters/__tests__/dart.test.ts +0 -84
  76. package/principles/adapters/__tests__/go.test.ts +0 -68
  77. package/principles/adapters/__tests__/java.test.ts +0 -385
  78. package/principles/adapters/__tests__/kotlin.test.ts +0 -76
  79. package/principles/adapters/__tests__/objectivec.test.ts +0 -453
  80. package/principles/adapters/__tests__/python.test.ts +0 -84
  81. package/principles/adapters/__tests__/swift.test.ts +0 -68
  82. package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
  83. package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
  84. package/principles/adapters/__tests__/typescript.test.ts +0 -116
  85. package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
  86. package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
  87. package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
  88. package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
  89. package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
  90. package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
  91. package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
  92. package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
  93. package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
  94. package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
  95. package/principles/rules/__tests__/index.test.ts +0 -49
  96. package/principles/rules/__tests__/solid/dip.test.ts +0 -119
  97. package/principles/rules/__tests__/solid/isp.test.ts +0 -58
  98. package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
  99. package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
  100. package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
  101. package/principles/rules/__tests__/solid/srp.test.ts +0 -87
  102. package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
  103. package/principles/rules/arch/__tests__/naming.test.ts +0 -133
  104. package/principles/rules/arch/__tests__/shared.test.ts +0 -113
@@ -1,96 +0,0 @@
1
- /**
2
- * @test REQ-620
3
- * @intent Pin the behaviour of the literal/comment masker before it is
4
- * refactored. The masker is a four-state character scanner (line
5
- * comment, block comment, regex literal, string/template) whose output
6
- * feeds EVERY metric the rule set reads: a masking mistake changes
7
- * reported nesting depth, function length and body text for the whole
8
- * adapter. These cases are the safety net for the CCN-36 split, so they
9
- * assert observable masking outcomes (offsets preserved, literals
10
- * blanked, structure kept) rather than any internal helper shape.
11
- * @covers AC-620-01
12
- *
13
- * Masking contract (from the function's own docblock):
14
- * - every comment / string / template / regex literal becomes spaces
15
- * - offsets and newlines are preserved exactly (length and line count equal)
16
- * - everything else is left byte-identical
17
- */
18
- import { describe, it, expect, vi } from 'vitest';
19
- import { TypeScriptAdapter } from '../typescript';
20
-
21
- vi.mock('fs', () => ({
22
- readFileSync: vi.fn(),
23
- existsSync: vi.fn(() => true),
24
- }));
25
-
26
- import { readFileSync } from 'fs';
27
-
28
- /** Mask a source string by round-tripping it through the adapter's parser. */
29
- function mask(src: string): string {
30
- (readFileSync as unknown as { mockReturnValue: (v: string) => void }).mockReturnValue(src);
31
- const adapter = new TypeScriptAdapter('probe.ts');
32
- const ast = adapter.parseAST() as { masked?: string };
33
- // The adapter exposes the masked source through a getter on the instance.
34
- const masked = (adapter as unknown as { maskedSource?: string }).maskedSource;
35
- return masked ?? ast.masked ?? '';
36
- }
37
-
38
- describe('AC-620-01: literal masking keeps offsets and blanks exactly the non-code', () => {
39
- const cases: Array<[string, string]> = [
40
- ['line comment', 'const a = 1; // hidden\nconst b = 2;'],
41
- ['block comment', 'const a = 1; /* hidden\nstill hidden */ const b = 2;'],
42
- ['single-quoted string', "const s = 'hidden text';"],
43
- ['double-quoted string', 'const s = "hidden text";'],
44
- ['template literal', 'const s = `hidden ${x} text`;'],
45
- ['regex literal', 'const re = /hid+den/g;'],
46
- ['escaped quote in string', "const s = 'it\\'s hidden';"],
47
- ];
48
-
49
- for (const [label, src] of cases) {
50
- it(`preserves length and line count for a ${label}`, () => {
51
- const out = mask(src);
52
- expect(out.length).toBe(src.length);
53
- expect(out.split('\n').length).toBe(src.split('\n').length);
54
- });
55
- }
56
-
57
- it('blanks a line comment but keeps the code before it', () => {
58
- const out = mask('const a = 1; // hidden');
59
- expect(out).toContain('const a = 1;');
60
- expect(out).not.toContain('hidden');
61
- });
62
-
63
- it('blanks a block comment across lines without eating the newline', () => {
64
- const src = '/* a\nb */\nconst keep = 1;';
65
- const out = mask(src);
66
- expect(out).not.toContain('a\nb');
67
- expect(out.split('\n').length).toBe(3);
68
- expect(out).toContain('const keep = 1;');
69
- });
70
-
71
- it('blanks string contents and keeps the code around them', () => {
72
- const out = mask('const s = "hidden"; const n = 42;');
73
- expect(out).not.toContain('hidden');
74
- expect(out).toContain('const s =');
75
- expect(out).toContain('const n = 42;');
76
- });
77
-
78
- it('blanks a template literal including its interpolations', () => {
79
- const out = mask('const s = `before ${x} after`;');
80
- expect(out).not.toContain('before');
81
- expect(out).not.toContain('after');
82
- expect(out).toContain('const s =');
83
- });
84
-
85
- it('does not treat a division slash as the start of a regex literal', () => {
86
- // `a / b` is division: the slash must not swallow the rest of the line.
87
- const out = mask('const r = a / b; const keep = 1;');
88
- expect(out).toContain('const keep = 1;');
89
- expect(out).toContain('a / b');
90
- });
91
-
92
- it('leaves code with no literals byte-identical', () => {
93
- const src = 'function f(a, b) {\n return a + b;\n}';
94
- expect(mask(src)).toBe(src);
95
- });
96
- });
@@ -1,116 +0,0 @@
1
- import { describe, it, expect, vi, type Mock } from 'vitest';;
2
- import { TypeScriptAdapter } from '../typescript';
3
-
4
- vi.mock('fs', () => ({
5
- readFileSync: vi.fn(),
6
- existsSync: vi.fn(() => true),
7
- }));
8
-
9
- import { readFileSync } from 'fs';
10
-
11
- describe('TypeScriptAdapter', () => {
12
-
13
- it('should implement the Adapter interface', () => {
14
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
15
- const adapter = new TypeScriptAdapter('test.ts');
16
-
17
- expect(adapter).toHaveProperty('detectLanguage');
18
- expect(adapter).toHaveProperty('parseAST');
19
- expect(adapter).toHaveProperty('extractFunctions');
20
- expect(adapter).toHaveProperty('extractClasses');
21
- expect(adapter).toHaveProperty('countLines');
22
- });
23
-
24
- it('should detect language as typescript for .ts files', () => {
25
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
26
- const adapter = new TypeScriptAdapter('test.ts');
27
- const detected = adapter.detectLanguage();
28
- expect(detected).toBe('typescript');
29
- });
30
-
31
- it('should detect language as typescript for .tsx files', () => {
32
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
33
- const adapter = new TypeScriptAdapter('test.tsx');
34
- const detected = adapter.detectLanguage();
35
- expect(detected).toBe('typescript');
36
- });
37
-
38
- it('should parse TypeScript file AST correctly', () => {
39
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
40
- const adapter = new TypeScriptAdapter('test.ts');
41
- const ast = adapter.parseAST();
42
- expect(ast).toHaveProperty('content');
43
- expect(ast).toHaveProperty('language');
44
- expect(ast).toHaveProperty('filePath');
45
- expect((ast as { language: unknown }).language).toBe('typescript');
46
- });
47
-
48
- it('should extract functions from TypeScript AST', () => {
49
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
50
- const adapter = new TypeScriptAdapter('test.ts');
51
- const functions = adapter.extractFunctions();
52
- expect(Array.isArray(functions)).toBe(true);
53
- expect(functions.some(fn => (fn as {name: string}).name === 'testFn')).toBe(true);
54
- });
55
-
56
- it('should extract classes from TypeScript AST', () => {
57
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nclass TestClass {}');
58
- const adapter = new TypeScriptAdapter('test.ts');
59
- const classes = adapter.extractClasses();
60
- expect(Array.isArray(classes)).toBe(true);
61
- expect(classes.some(cls => (cls as {name: string}).name === 'TestClass')).toBe(true);
62
- });
63
-
64
- it('should count TypeScript file physical lines', () => {
65
- (readFileSync as Mock).mockReturnValue('export function testFn() {}\nexport function testFn2() {}');
66
- const adapter = new TypeScriptAdapter('test.ts');
67
- const lineCount = adapter.countLines();
68
- expect(lineCount).toBe(2);
69
- });
70
-
71
- it('should handle TypeScript-specific syntax correctly', () => {
72
- (readFileSync as Mock).mockReturnValue(`
73
- export async function asyncFn() {}
74
- export function* generatorFn() {}
75
- class MyClass {
76
- method() {}
77
- }
78
- interface MyInterface {}
79
- type MyType = string;
80
- `);
81
-
82
- const adapter = new TypeScriptAdapter('test.ts');
83
-
84
- const functions = adapter.extractFunctions();
85
- expect(Array.isArray(functions)).toBe(true);
86
-
87
- const classes = adapter.extractClasses();
88
- expect(Array.isArray(classes)).toBe(true);
89
-
90
- expect(adapter.detectLanguage()).toBe('typescript');
91
- });
92
-
93
- it('should throw error when file cannot be read', () => {
94
- (readFileSync as Mock).mockImplementation(() => {
95
- throw new Error('Could not read file');
96
- });
97
-
98
- expect(() => {
99
- new TypeScriptAdapter('nonexistent-file.ts');
100
- }).toThrow('Could not read file:');
101
- });
102
-
103
- it('should fall back to super.detectLanguage for non-ts/non-tsx extensions', () => {
104
- (readFileSync as Mock).mockReturnValue('content');
105
- const adapter = new TypeScriptAdapter('test.py');
106
- expect(adapter.detectLanguage()).toBe('python');
107
- });
108
-
109
- it('should extract re-export declarations', () => {
110
- (readFileSync as Mock).mockReturnValue('export { Foo };\nexport { Bar };\nexport function baz() {}');
111
- const adapter = new TypeScriptAdapter('test.ts');
112
- const exports = adapter.extractExports();
113
- const reExports = exports.filter(ex => (ex as {type: string}).type === 're-export');
114
- expect(reExports.length).toBe(2);
115
- });
116
- });
@@ -1,85 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { codeDuplicationRule } from '../../clean-code/code-duplication';
3
-
4
- const mockAdapter = {
5
- detectLanguage: () => 'typescript',
6
- parseAST: () => undefined,
7
- extractFunctions: () => [],
8
- extractClasses: () => [],
9
- countLines: () => 0
10
- };
11
-
12
- describe('code-duplication.ts - Code Duplication Rule', () => {
13
- it('should detect high duplication percentage above threshold', () => {
14
- const mockAdapterWithDuplication = {
15
- ...mockAdapter,
16
- duplicationPercentage: 25
17
- };
18
-
19
- const violations = codeDuplicationRule.check('test.ts', mockAdapterWithDuplication as never);
20
-
21
- expect(violations.length).toBe(1);
22
- expect(violations[0].ruleId).toBe('clean-code.code-duplication');
23
- expect(violations[0].message).toContain('25%');
24
- });
25
-
26
- it('should pass for low duplication percentage below threshold', () => {
27
- const mockAdapterWithLowDuplication = {
28
- ...mockAdapter,
29
- duplicationPercentage: 10
30
- };
31
-
32
- const violations = codeDuplicationRule.check('test.ts', mockAdapterWithLowDuplication as never);
33
-
34
- expect(violations.length).toBe(0);
35
- });
36
-
37
- it('should pass for duplication exactly at threshold (15%)', () => {
38
- const mockAdapterAtThreshold = {
39
- ...mockAdapter,
40
- duplicationPercentage: 15
41
- };
42
-
43
- const violations = codeDuplicationRule.check('test.ts', mockAdapterAtThreshold as never);
44
-
45
- expect(violations.length).toBe(0);
46
- });
47
-
48
- it('should use threshold and severity from config', () => {
49
- expect(codeDuplicationRule.threshold).toBe(15);
50
- expect(codeDuplicationRule.severity).toBe('warning');
51
- });
52
-
53
- it('should return empty array when adapter.duplicationPercentage is undefined', () => {
54
- const violations = codeDuplicationRule.check('test.ts', mockAdapter as never);
55
-
56
- expect(violations).toEqual([]);
57
- });
58
-
59
- it('should propagate adapter errors (no empty catch, #392)', () => {
60
- // #392-#4: the rule no longer swallows adapter errors in an empty catch, so
61
- // a throwing adapter getter must bubble up to analyzer.runRuleOnFile().
62
- const mockAdapterThrowing = Object.defineProperty(
63
- { ...mockAdapter },
64
- 'duplicationPercentage',
65
- { get: () => { throw new Error('jscpd error'); } }
66
- );
67
-
68
- expect(() => codeDuplicationRule.check('test.ts', mockAdapterThrowing as never)).toThrow('jscpd error');
69
- });
70
-
71
- it('should handle multiple files with duplication', () => {
72
- const mockAdapterWithDuplication = {
73
- ...mockAdapter,
74
- duplicationPercentage: 30,
75
- duplicatedBlocks: [
76
- { lines: 10, tokens: 50, files: ['test.ts', 'other.ts'] }
77
- ]
78
- };
79
-
80
- const violations = codeDuplicationRule.check('test.ts', mockAdapterWithDuplication as never);
81
-
82
- expect(violations.length).toBe(1);
83
- expect(violations[0].message).toContain('30%');
84
- });
85
- });
@@ -1,73 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { deepNestingRule } from '../../clean-code/deep-nesting';
3
-
4
- const mockAdapter = {
5
- detectLanguage: () => 'typescript',
6
- parseAST: () => undefined,
7
- extractFunctions: () => [],
8
- extractClasses: () => [],
9
- countLines: () => 0
10
- };
11
-
12
- describe('deep-nesting.ts - Deep Nesting Rule', () => {
13
- it('should detect function with nesting deeper than 4 levels', () => {
14
- const mockAdapterWithDeepNesting = {
15
- ...mockAdapter,
16
- extractFunctions: () => [{
17
- name: 'deeplyNested',
18
- startLine: 1,
19
- code: `
20
- function deeplyNested() {
21
- if (a) {
22
- if (b) {
23
- if (c) {
24
- if (d) {
25
- if (e) {
26
- return true;
27
- }
28
- }
29
- }
30
- }
31
- }
32
- }
33
- `,
34
- nestingDepth: 5
35
- }]
36
- };
37
-
38
- const violations = deepNestingRule.check('test.ts', mockAdapterWithDeepNesting as never);
39
-
40
- expect(violations.length).toBe(1);
41
- expect(violations[0].ruleId).toBe('clean-code.deep-nesting');
42
- });
43
-
44
- it('should pass for function with acceptable nesting', () => {
45
- const mockAdapterWithNormalNesting = {
46
- ...mockAdapter,
47
- extractFunctions: () => [{
48
- name: 'normalNesting',
49
- startLine: 1,
50
- nestingDepth: 3
51
- }]
52
- };
53
-
54
- const violations = deepNestingRule.check('test.ts', mockAdapterWithNormalNesting as never);
55
-
56
- expect(violations.length).toBe(0);
57
- });
58
-
59
- it('should use threshold from config', () => {
60
- expect(deepNestingRule.threshold).toBe(4);
61
- expect(deepNestingRule.severity).toBe('warning');
62
- });
63
-
64
- it('should propagate adapter errors (no empty catch, #392)', () => {
65
- const mockAdapterThatThrows = {
66
- ...mockAdapter,
67
- extractFunctions: () => { throw new Error('Adapter failed'); }
68
- };
69
-
70
- // Rule errors must bubble up to analyzer.runRuleOnFile(), not be swallowed.
71
- expect(() => deepNestingRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
72
- });
73
- });
@@ -1,109 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { godClassRule } from '../../clean-code/god-class';
3
-
4
- const mockAdapter = {
5
- detectLanguage: () => 'typescript',
6
- parseAST: () => undefined,
7
- extractFunctions: () => [],
8
- extractClasses: () => [],
9
- countLines: () => 0
10
- };
11
-
12
- describe('god-class.ts - God Class Rule', () => {
13
- it('should detect class with more than 15 methods', () => {
14
- const mockAdapterWithGodClass = {
15
- ...mockAdapter,
16
- extractClasses: () => [{
17
- name: 'GodClass',
18
- line: 1,
19
- code: `
20
- class GodClass {
21
- method1() {}
22
- method2() {}
23
- method3() {}
24
- method4() {}
25
- method5() {}
26
- method6() {}
27
- method7() {}
28
- method8() {}
29
- method9() {}
30
- method10() {}
31
- method11() {}
32
- method12() {}
33
- method13() {}
34
- method14() {}
35
- method15() {}
36
- method16() {}
37
- }
38
- `
39
- }]
40
- };
41
-
42
- const violations = godClassRule.check('test.ts', mockAdapterWithGodClass as never);
43
-
44
- expect(violations.length).toBe(1);
45
- expect(violations[0].ruleId).toBe('clean-code.god-class');
46
- expect(violations[0].message).toContain('GodClass');
47
- expect(violations[0].message).toContain('16');
48
- });
49
-
50
- it('should pass for class with fewer than threshold methods', () => {
51
- const mockAdapterWithSmallClass = {
52
- ...mockAdapter,
53
- extractClasses: () => [{
54
- name: 'SmallClass',
55
- line: 1,
56
- code: `
57
- class SmallClass {
58
- method1() {}
59
- method2() {}
60
- method3() {}
61
- }
62
- `
63
- }]
64
- };
65
-
66
- const violations = godClassRule.check('test.ts', mockAdapterWithSmallClass as never);
67
-
68
- expect(violations.length).toBe(0);
69
- });
70
-
71
- it('should exclude getters and setters from count', () => {
72
- const mockAdapterWithGetters = {
73
- ...mockAdapter,
74
- extractClasses: () => [{
75
- name: 'DataClass',
76
- line: 1,
77
- code: `
78
- class DataClass {
79
- get name() { return this._name; }
80
- set name(value) { this._name = value; }
81
- get age() { return this._age; }
82
- set age(value) { this._age = value; }
83
- method1() {}
84
- method2() {}
85
- method3() {}
86
- }
87
- `
88
- }]
89
- };
90
-
91
- const violations = godClassRule.check('test.ts', mockAdapterWithGetters as never);
92
-
93
- expect(violations.length).toBe(0);
94
- });
95
-
96
- it('should use threshold from config', () => {
97
- expect(godClassRule.threshold).toBe(15);
98
- expect(godClassRule.severity).toBe('warning');
99
- });
100
-
101
- it('should propagate adapter errors (no empty catch, #392)', () => {
102
- const mockAdapterThatThrows = {
103
- ...mockAdapter,
104
- extractClasses: () => { throw new Error('Adapter failed'); }
105
- };
106
-
107
- expect(() => godClassRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
108
- });
109
- });
@@ -1,73 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { largeFileRule } from '../../clean-code/large-file';
3
-
4
- // Mock adapter for testing
5
- const mockAdapter = {
6
- detectLanguage: () => 'typescript',
7
- parseAST: () => undefined,
8
- extractFunctions: () => [],
9
- extractClasses: () => [],
10
- extractExports: () => [],
11
- countLines: (_fileName: string) => 10, // Default to small file
12
- getDuplication: () => ({ percentage: 0, blocks: [] }), declaresRuleCoverage: true
13
- };
14
-
15
- describe('largeFileRule', () => {
16
- it('should return an empty array when file has fewer than threshold lines', () => {
17
- const shortFileAdapter = {
18
- ...mockAdapter,
19
- countLines: () => 499
20
- } as never;
21
-
22
- const violations = largeFileRule.check('test-short.ts', shortFileAdapter);
23
- expect(violations).toHaveLength(0);
24
- });
25
-
26
- it('should detect files exceeding 1150 lines', () => {
27
- const largeFileAdapter = {
28
- ...mockAdapter,
29
- countLines: () => 1151
30
- };
31
-
32
- const violations = largeFileRule.check('test-large.ts', largeFileAdapter);
33
- expect(violations).toHaveLength(1);
34
- expect(violations[0]).toEqual({
35
- file: 'test-large.ts',
36
- line: 1,
37
- ruleId: 'clean-code.large-file',
38
- message: 'File is too large: 1151 lines (maximum: 1150)',
39
- severity: 'warning'
40
- });
41
- });
42
-
43
- it('should handle exactly threshold lines as not violating', () => {
44
- const thresholdFileAdapter = {
45
- ...mockAdapter,
46
- countLines: () => 1150
47
- };
48
-
49
- const violations = largeFileRule.check('test-threshold.ts', thresholdFileAdapter);
50
- expect(violations).toHaveLength(0);
51
- });
52
-
53
- it('should use the correct rule identifier', () => {
54
- expect(largeFileRule.id).toEqual('clean-code.large-file');
55
- });
56
-
57
- it('should have the correct severity', () => {
58
- expect(largeFileRule.severity).toEqual('warning');
59
- });
60
-
61
- it('should use the correct threshold', () => {
62
- expect(largeFileRule.threshold).toEqual(1150);
63
- });
64
-
65
- it('should propagate adapter errors (no empty catch, #392)', () => {
66
- const mockAdapterThatThrows = {
67
- ...mockAdapter,
68
- countLines: () => { throw new Error('Adapter failed'); }
69
- };
70
-
71
- expect(() => largeFileRule.check('test.ts', mockAdapterThatThrows)).toThrow('Adapter failed');
72
- });
73
- });
@@ -1,81 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { longFunctionRule } from '../../clean-code/long-function';
3
-
4
- // Mock adapter for testing
5
- const mockAdapter = {
6
- detectLanguage: () => 'typescript',
7
- parseAST: () => undefined,
8
- extractFunctions: () => [],
9
- extractClasses: () => [],
10
- countLines: (content: string) => content.split('\n').length
11
- };
12
-
13
- describe('longFunctionRule', () => {
14
- it('should return an empty array when no long function is detected', () => {
15
- const mockShortAdapter = {
16
- ...mockAdapter,
17
- extractFunctions: () => [
18
- { name: 'shortFunction', startLine: 1, endLine: 40, length: 40 }
19
- ]
20
- };
21
-
22
- const violations = longFunctionRule.check('test.ts', mockShortAdapter as never);
23
- expect(violations).toHaveLength(0);
24
- });
25
-
26
- it('should detect long functions exceeding 50 lines', () => {
27
- const mockLongAdapter = {
28
- ...mockAdapter,
29
- extractFunctions: () => [
30
- { name: 'veryLongFunction', startLine: 1, endLine: 55, length: 55 }
31
- ]
32
- };
33
-
34
- const violations = longFunctionRule.check('test.ts', mockLongAdapter as never);
35
- expect(violations).toHaveLength(1);
36
- expect(violations[0]).toEqual({
37
- file: 'test.ts',
38
- line: 1,
39
- ruleId: 'clean-code.long-function',
40
- message: 'Function "veryLongFunction" is too long: 55 lines (maximum: 50)',
41
- severity: 'warning'
42
- });
43
- });
44
-
45
- it('should handle multiple functions in a file', () => {
46
- const mockMultiAdapter = {
47
- ...mockAdapter,
48
- extractFunctions: () => [
49
- { name: 'shortFunction', startLine: 1, endLine: 4, length: 4 },
50
- { name: 'alsoLongFunction', startLine: 6, endLine: 62, length: 57 }
51
- ]
52
- };
53
-
54
- const violations = longFunctionRule.check('test.ts', mockMultiAdapter as never);
55
- expect(violations).toHaveLength(1);
56
- expect(violations[0].ruleId).toEqual('clean-code.long-function');
57
- expect(violations[0].message).toContain('alsoLongFunction');
58
- expect(violations[0].message).toContain('57 lines');
59
- });
60
-
61
- it('should use the correct rule identifier', () => {
62
- expect(longFunctionRule.id).toEqual('clean-code.long-function');
63
- });
64
-
65
- it('should have the correct severity', () => {
66
- expect(longFunctionRule.severity).toEqual('warning');
67
- });
68
-
69
- it('should use the correct threshold', () => {
70
- expect(longFunctionRule.threshold).toEqual(50);
71
- });
72
-
73
- it('should propagate adapter errors (no empty catch, #392)', () => {
74
- const mockAdapterThatThrows = {
75
- ...mockAdapter,
76
- extractFunctions: () => { throw new Error('Adapter failed'); }
77
- };
78
-
79
- expect(() => longFunctionRule.check('test.ts', mockAdapterThatThrows as never)).toThrow('Adapter failed');
80
- });
81
- });