Skip to content

Commit 8b22cfb

Browse files
committed
feat(angular-mcp-server): separate reporter for single violation
1 parent 18a65d7 commit 8b22cfb

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

packages/angular-mcp-server/src/lib/tools/ds/report-violations/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export { reportAllViolationsTools } from './report-all-violations.tool.js';
44
export type {
55
ViolationEntry,
66
ComponentViolationReport,
7+
AllViolationsEntry,
8+
AllViolationsComponentReport,
79
AllViolationsReport,
810
ComponentViolationInFile,
911
FileViolationReport,

packages/angular-mcp-server/src/lib/tools/ds/report-violations/models/types.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
// JSON output types
1+
// Types for report-violations (single component, no replacement field needed)
22
export interface ViolationEntry {
33
file: string;
44
lines: number[];
55
violation: string;
6-
replacement: string;
76
}
87

98
export interface ComponentViolationReport {
109
component: string;
1110
violations: ViolationEntry[];
1211
}
1312

13+
// Types for report-all-violations (multiple components, replacement field needed)
14+
export interface AllViolationsEntry {
15+
file: string;
16+
lines: number[];
17+
violation: string;
18+
replacement: string;
19+
}
20+
21+
export interface AllViolationsComponentReport {
22+
component: string;
23+
violations: AllViolationsEntry[];
24+
}
25+
1426
export interface AllViolationsReport {
15-
components: ComponentViolationReport[];
27+
components: AllViolationsComponentReport[];
1628
}
1729

18-
// File-grouped output types
30+
// File-grouped output types for report-all-violations
1931
export interface ComponentViolationInFile {
2032
component: string;
2133
lines: number[];

packages/angular-mcp-server/src/lib/tools/ds/report-violations/report-all-violations.tool.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
import type { BaseViolationAudit } from '../shared/violation-analysis/types.js';
1818
import { loadAndValidateDsComponentsFile } from '../../../validation/ds-components-file-loader.validation.js';
1919
import {
20-
AllViolationsReport,
21-
ComponentViolationReport,
22-
ViolationEntry,
20+
AllViolationsReport,
21+
AllViolationsComponentReport,
22+
AllViolationsEntry,
2323
AllViolationsReportByFile,
2424
FileViolationReport,
2525
ComponentViolationInFile
@@ -161,7 +161,7 @@ export const reportAllViolationsHandler = createHandler<
161161

162162
// Group by component (default behavior)
163163
if (params.groupBy !== 'file') {
164-
const componentMap = new Map<string, ViolationEntry[]>();
164+
const componentMap = new Map<string, AllViolationsEntry[]>();
165165

166166
for (const item of processed) {
167167
if (!componentMap.has(item.component)) {
@@ -179,7 +179,7 @@ export const reportAllViolationsHandler = createHandler<
179179
}
180180
}
181181

182-
const components: ComponentViolationReport[] = Array.from(
182+
const components: AllViolationsComponentReport[] = Array.from(
183183
componentMap.entries(),
184184
([component, violations]) => ({ component, violations }),
185185
);

packages/angular-mcp-server/src/lib/tools/ds/report-violations/report-violations.tool.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
createHandler,
33
BaseHandlerOptions,
4-
RESULT_FORMATTERS,
54
} from '../shared/utils/handler-helpers.js';
65
import {
76
createViolationReportingSchema,
@@ -29,21 +28,15 @@ export const reportViolationsSchema = {
2928
};
3029

3130
/**
32-
* Extracts deprecated class and replacement from violation message
31+
* Extracts deprecated class from violation message
3332
*/
34-
function parseViolationMessage(message: string): { violation: string; replacement: string } {
33+
function parseViolationMessage(message: string): string {
3534
// Clean up HTML tags
3635
const cleanMessage = message.replace(/<code>/g, '`').replace(/<\/code>/g, '`');
3736

3837
// Extract deprecated class - look for patterns like "class `offer-badge`" or "class `btn, btn-primary`"
3938
const classMatch = cleanMessage.match(/class `([^`]+)`/);
40-
const violation = classMatch ? classMatch[1] : 'unknown';
41-
42-
// Extract replacement component - look for "Use `ComponentName`"
43-
const replacementMatch = cleanMessage.match(/Use `([^`]+)`/);
44-
const replacement = replacementMatch ? replacementMatch[1] : 'unknown';
45-
46-
return { violation, replacement };
39+
return classMatch ? classMatch[1] : 'unknown';
4740
}
4841

4942
export const reportViolationsHandler = createHandler<
@@ -72,13 +65,12 @@ export const reportViolationsHandler = createHandler<
7265
);
7366

7467
for (const [fileName, { lines, message }] of Object.entries(fileGroups)) {
75-
const { violation, replacement } = parseViolationMessage(message);
68+
const violation = parseViolationMessage(message);
7669

7770
violations.push({
7871
file: fileName,
7972
lines: lines.sort((a, b) => a - b),
8073
violation,
81-
replacement,
8274
});
8375
}
8476
}
@@ -88,7 +80,25 @@ export const reportViolationsHandler = createHandler<
8880
violations,
8981
};
9082
},
91-
(result) => RESULT_FORMATTERS.json(result),
83+
(result) => {
84+
if (result.violations.length === 0) {
85+
return [`No violations found for component: ${result.component}`];
86+
}
87+
88+
const message = [
89+
`Found violations for component: ${result.component}`,
90+
'Use this output to identify:',
91+
' - Which files contain violations',
92+
' - The specific line numbers where violations occur',
93+
' - What is being used that violates the rules (violation field)',
94+
'',
95+
'Violation Report:',
96+
'',
97+
JSON.stringify(result, null, 2),
98+
];
99+
100+
return [message.join('\n')];
101+
},
92102
);
93103

94104
export const reportViolationsTools = [

0 commit comments

Comments
 (0)