Skip to content

Commit 5d61a02

Browse files
Merge pull request #27 from AbdulRehaman08/feature/group-violations-single-component-support
feat: support single-component report format in group-violations
2 parents 100f0ae + 8f9fed3 commit 5d61a02

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { join } from 'path';
66
import type {
77
AllViolationsReportByFile,
88
AllViolationsReport,
9+
ComponentViolationReport,
910
GroupViolationsOptions,
1011
GroupViolationsReport,
1112
GroupViolationsResult,
@@ -14,6 +15,7 @@ import { groupViolationsSchema } from './models/schema.js';
1415
import {
1516
detectReportFormat,
1617
convertComponentToFileFormat,
18+
convertSingleComponentToComponentFormat,
1719
enrichFiles,
1820
groupByDirectory,
1921
determineOptimalGroups,
@@ -55,13 +57,18 @@ export const groupViolationsHandler = createHandler<
5557

5658
if (format === 'unknown') {
5759
throw new Error(
58-
'Invalid violations report format. Expected either { files: [...] } or { components: [...] }',
60+
'Invalid violations report format. Expected { files: [...] }, { components: [...] }, or { component: "...", violations: [...] }',
5961
);
6062
}
6163

6264
let violationsData: AllViolationsReportByFile;
6365

64-
if (format === 'component') {
66+
if (format === 'single-component') {
67+
const asComponentFormat = convertSingleComponentToComponentFormat(
68+
rawData as ComponentViolationReport,
69+
);
70+
violationsData = convertComponentToFileFormat(asComponentFormat);
71+
} else if (format === 'component') {
6572
violationsData = convertComponentToFileFormat(
6673
rawData as AllViolationsReport,
6774
);

packages/angular-mcp-server/src/lib/tools/ds/report-violations/utils/format-converter.utils.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
AllViolationsReport,
33
AllViolationsReportByFile,
4+
ComponentViolationReport,
45
FileViolationReport,
56
} from '../models/types.js';
67

@@ -9,16 +10,39 @@ import type {
910
*/
1011
export function detectReportFormat(
1112
data: any,
12-
): 'file' | 'component' | 'unknown' {
13+
): 'file' | 'component' | 'single-component' | 'unknown' {
1314
if (data.files && Array.isArray(data.files)) {
1415
return 'file';
1516
}
1617
if (data.components && Array.isArray(data.components)) {
1718
return 'component';
1819
}
20+
if (data.component && data.violations && Array.isArray(data.violations)) {
21+
return 'single-component';
22+
}
1923
return 'unknown';
2024
}
2125

26+
/**
27+
* Convert single-component report to multi-component format
28+
*/
29+
export function convertSingleComponentToComponentFormat(
30+
report: ComponentViolationReport,
31+
): AllViolationsReport {
32+
return {
33+
components: [
34+
{
35+
component: report.component,
36+
violations: report.violations.map((v) => ({
37+
...v,
38+
replacement: report.component,
39+
})),
40+
},
41+
],
42+
rootPath: report.rootPath,
43+
};
44+
}
45+
2246
/**
2347
* Convert component-grouped report to file-grouped format
2448
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
export {
1212
detectReportFormat,
1313
convertComponentToFileFormat,
14+
convertSingleComponentToComponentFormat,
1415
} from './format-converter.utils.js';
1516
export { calculateViolations, enrichFiles } from './file-enrichment.utils.js';
1617
export {

0 commit comments

Comments
 (0)