Skip to content

Commit 06560e9

Browse files
author
Szymon.Poltorak
committed
feat(): report all violations
1 parent 7fcd5d6 commit 06560e9

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ToolSchemaOptions } from '@push-based/models';
66
import { dsComponentCoveragePlugin } from '@push-based/ds-component-coverage';
77
import { baseToolsSchema } from '../schema';
88
import { join } from 'node:path';
9-
import { reportViolationsTools } from './report-violations/index.js';
9+
import { reportViolationsTools, reportAllViolationsTools } from './report-violations/index.js';
1010

1111
export const componentCoverageToolsSchema: ToolSchemaOptions = {
1212
name: 'ds_component-coverage',
@@ -127,4 +127,8 @@ export const componentCoverageTools = [
127127
},
128128
];
129129

130-
export const dsTools = [...componentCoverageTools, ...reportViolationsTools];
130+
export const dsTools = [
131+
...componentCoverageTools,
132+
...reportViolationsTools,
133+
...reportAllViolationsTools,
134+
];

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { reportViolationsTools } from './report-violations.tool.js';
1+
export { reportViolationsTools } from './report-violations.tool';
2+
export { reportAllViolationsTools } from './report-violations-all.tool';
23

34
export type {
45
ReportViolationsOptions,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { createHandler, BaseHandlerOptions } from '../shared/utils/handler-helpers.js';
2+
import {
3+
createProjectAnalysisSchema,
4+
COMMON_ANNOTATIONS,
5+
} from '../shared/models/schema-helpers.js';
6+
import {
7+
analyzeProjectCoverage,
8+
} from '../shared/violation-analysis/coverage-analyzer.js';
9+
import { formatViolations } from '../shared/violation-analysis/formatters.js';
10+
import { loadAndValidateDsComponentsFile } from '../../../validation/ds-components-file-loader.validation.js';
11+
12+
interface ReportAllViolationsOptions extends BaseHandlerOptions {
13+
directory: string;
14+
groupBy?: 'file' | 'folder';
15+
}
16+
17+
export const reportAllViolationsSchema = {
18+
name: 'report-all-violations',
19+
description:
20+
'Report all deprecated DS CSS usage for every component defined in the config file within a directory.',
21+
inputSchema: createProjectAnalysisSchema({
22+
groupBy: {
23+
type: 'string',
24+
enum: ['file', 'folder'],
25+
description: 'How to group the results',
26+
default: 'file',
27+
},
28+
}),
29+
annotations: {
30+
title: 'Report All Violations',
31+
...COMMON_ANNOTATIONS.readOnly,
32+
},
33+
};
34+
35+
36+
// Reuse centralized loader+validator for DS components config
37+
38+
export const reportAllViolationsHandler = createHandler<
39+
ReportAllViolationsOptions,
40+
string[]
41+
>(
42+
reportAllViolationsSchema.name,
43+
async (params, { cwd, deprecatedCssClassesPath }) => {
44+
const groupBy = params.groupBy || 'file';
45+
const dsComponents = await loadAndValidateDsComponentsFile(
46+
cwd,
47+
deprecatedCssClassesPath || '',
48+
);
49+
50+
const coverageResult = await analyzeProjectCoverage({
51+
cwd,
52+
returnRawData: true,
53+
directory: params.directory,
54+
dsComponents,
55+
});
56+
57+
const raw = coverageResult.rawData?.rawPluginResult;
58+
if (!raw) return [];
59+
60+
// Reuse the existing minimal formatter so output format matches report-violations
61+
// and respect groupBy option.
62+
const formattedContent = formatViolations(raw, params.directory, {
63+
groupBy: groupBy === 'file' ? 'file' : 'folder',
64+
});
65+
66+
// Extract text items to string[]
67+
const lines = formattedContent.map((item: { type?: string; text?: string } | string) => {
68+
if (typeof item === 'string') return item;
69+
if (item && typeof item.text === 'string') return item.text;
70+
return String(item);
71+
});
72+
73+
return lines;
74+
},
75+
(result) => result,
76+
);
77+
78+
export const reportAllViolationsTools = [
79+
{
80+
schema: reportAllViolationsSchema,
81+
handler: reportAllViolationsHandler,
82+
},
83+
];

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ToolsConfig } from '@push-based/models';
2-
import { reportViolationsTools } from './report-violations';
2+
import { reportViolationsTools, reportAllViolationsTools } from './report-violations';
33
import { getProjectDependenciesTools } from './project/get-project-dependencies.tool';
44
import { reportDeprecatedCssTools } from './project/report-deprecated-css.tool';
55
import { buildComponentUsageGraphTools } from './component-usage-graph';
@@ -14,6 +14,7 @@ import {
1414
export const dsTools: ToolsConfig[] = [
1515
// Project tools
1616
...reportViolationsTools,
17+
...reportAllViolationsTools,
1718
...getProjectDependenciesTools,
1819
...reportDeprecatedCssTools,
1920
...buildComponentUsageGraphTools,

0 commit comments

Comments
 (0)