Skip to content

Commit becea84

Browse files
author
Szymon.Poltorak
committed
refactor: revent not needed changes
1 parent de01586 commit becea84

File tree

9 files changed

+23
-95
lines changed

9 files changed

+23
-95
lines changed

packages/angular-mcp-server/src/lib/tools/ds/component-contract/builder/build-component-contract.tool.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '../shared/utils/contract-file-ops.js';
1111
import { ContractResult } from './models/types.js';
1212
import { resolveCrossPlatformPath } from '../../shared/utils/cross-platform-path.js';
13-
import { validateAndNormalizeComponentName } from '../../shared/utils/component-validation.js';
1413

1514
interface BuildComponentContractOptions extends BaseHandlerOptions {
1615
directory: string;
@@ -26,12 +25,13 @@ export const buildComponentContractHandler = createHandler<
2625
>(
2726
buildComponentContractSchema.name,
2827
async (params, { cwd, workspaceRoot }) => {
29-
const { directory, templateFile, styleFile, typescriptFile } = params;
30-
31-
// Normalize component name at handler entry point
32-
const dsComponentName = validateAndNormalizeComponentName(
33-
params.dsComponentName,
34-
);
28+
const {
29+
directory,
30+
templateFile,
31+
styleFile,
32+
typescriptFile,
33+
dsComponentName,
34+
} = params;
3535

3636
const effectiveTemplatePath = resolveCrossPlatformPath(
3737
directory,

packages/angular-mcp-server/src/lib/tools/ds/component-contract/diff/diff-component-contract.tool.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {
99
import { diffComponentContractSchema } from './models/schema.js';
1010
import type { DomPathDictionary } from '../shared/models/types.js';
1111
import { loadContract } from '../shared/utils/contract-file-ops.js';
12-
import {
13-
componentNameToKebabCase,
14-
validateAndNormalizeComponentName,
15-
} from '../../shared/utils/component-validation.js';
12+
import { componentNameToKebabCase } from '../../shared/utils/component-validation.js';
1613
import { basename } from 'node:path';
1714
import {
1815
consolidateAndPruneRemoveOperationsWithDeduplication,
@@ -38,11 +35,6 @@ export const diffComponentContractHandler = createHandler<
3835
>(
3936
diffComponentContractSchema.name,
4037
async (params, { workspaceRoot }) => {
41-
// Normalize component name at handler entry point
42-
const dsComponentName = validateAndNormalizeComponentName(
43-
params.dsComponentName,
44-
);
45-
4638
const effectiveBeforePath = resolveCrossPlatformPath(
4739
params.directory,
4840
params.contractBeforePath,
@@ -65,7 +57,7 @@ export const diffComponentContractHandler = createHandler<
6557
const diffData = {
6658
before: effectiveBeforePath,
6759
after: effectiveAfterPath,
68-
dsComponentName: dsComponentName,
60+
dsComponentName: params.dsComponentName,
6961
timestamp: new Date().toISOString(),
7062
domPathDictionary: domPathDict.paths,
7163
changes: groupedChanges,
@@ -76,7 +68,7 @@ export const diffComponentContractHandler = createHandler<
7668
const normalizedDiffData = normalizePathsInObject(diffData, workspaceRoot);
7769

7870
// Create component-specific diffs directory
79-
const componentKebab = componentNameToKebabCase(dsComponentName);
71+
const componentKebab = componentNameToKebabCase(params.dsComponentName);
8072
const diffDir = resolveCrossPlatformPath(
8173
workspaceRoot,
8274
`.cursor/tmp/contracts/${componentKebab}/diffs`,

packages/angular-mcp-server/src/lib/tools/ds/component/get-deprecated-css-classes.tool.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
COMMON_ANNOTATIONS,
66
} from '../shared/models/schema-helpers.js';
77
import { getDeprecatedCssClasses } from './utils/deprecated-css-helpers.js';
8-
import { validateAndNormalizeComponentName } from '../shared/utils/component-validation.js';
98

109
interface DeprecatedCssClassesOptions {
1110
componentName: string;
@@ -29,12 +28,8 @@ export const getDeprecatedCssClassesHandler = createHandler<
2928
>(
3029
getDeprecatedCssClassesSchema.name,
3130
async ({ componentName }, { cwd, deprecatedCssClassesPath }) => {
32-
// Normalize component name at handler entry point
33-
const normalizedComponentName =
34-
validateAndNormalizeComponentName(componentName);
35-
3631
return getDeprecatedCssClasses(
37-
normalizedComponentName,
32+
componentName,
3833
deprecatedCssClassesPath,
3934
cwd,
4035
);

packages/angular-mcp-server/src/lib/tools/ds/component/get-ds-component-data.tool.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { COMMON_ANNOTATIONS } from '../shared/models/schema-helpers.js';
77
import { getComponentPathsInfo } from './utils/paths-helpers.js';
88
import { getComponentDocPathsForName } from './utils/doc-helpers.js';
99
import {
10-
validateAndNormalizeComponentName,
10+
validateComponentName,
1111
componentNameToKebabCase,
1212
} from '../shared/utils/component-validation.js';
1313
import { resolveCrossPlatformPath } from '../shared/utils/cross-platform-path.js';
@@ -114,11 +114,12 @@ export const getDsComponentDataHandler = createHandler<
114114
DsComponentData
115115
>(
116116
getDsComponentDataToolSchema.name,
117-
async (params, { cwd, uiRoot, storybookDocsRoot }) => {
118-
const { sections = ['all'] } = params;
119-
let { componentName } = params;
117+
async (
118+
{ componentName, sections = ['all'] },
119+
{ cwd, uiRoot, storybookDocsRoot },
120+
) => {
120121
try {
121-
componentName = validateAndNormalizeComponentName(componentName);
122+
validateComponentName(componentName);
122123

123124
const includeAll = sections.includes('all');
124125
const includeImplementation =

packages/angular-mcp-server/src/lib/tools/ds/project/get-project-dependencies.tool.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
COMMON_ANNOTATIONS,
99
} from '../shared/models/schema-helpers.js';
1010
import { analyzeProjectDependencies } from './utils/dependencies-helpers.js';
11-
import { validateAndNormalizeComponentName } from '../shared/utils/component-validation.js';
11+
import { validateComponentName } from '../shared/utils/component-validation.js';
1212

1313
interface ProjectDependenciesOptions extends BaseHandlerOptions {
1414
directory: string;
@@ -42,11 +42,10 @@ export const getProjectDependenciesHandler = createHandler<
4242
>(
4343
getProjectDependenciesSchema.name,
4444
async (params, { cwd, workspaceRoot, uiRoot }) => {
45-
const { directory } = params;
46-
let { componentName } = params;
45+
const { directory, componentName } = params;
4746

4847
if (componentName) {
49-
componentName = validateAndNormalizeComponentName(componentName);
48+
validateComponentName(componentName);
5049
}
5150

5251
return await analyzeProjectDependencies(

packages/angular-mcp-server/src/lib/tools/ds/project/report-deprecated-css.tool.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
BaseHandlerOptions,
66
RESULT_FORMATTERS,
77
} from '../shared/utils/handler-helpers.js';
8-
import { validateAndNormalizeComponentName } from '../shared/utils/component-validation.js';
98
import {
109
createDirectoryComponentSchema,
1110
COMMON_ANNOTATIONS,
@@ -41,12 +40,7 @@ export const reportDeprecatedCssHandler = createHandler<
4140
>(
4241
reportDeprecatedCssSchema.name,
4342
async (params, { cwd, deprecatedCssClassesPath }) => {
44-
const { directory } = params;
45-
46-
// Normalize component name at handler entry point
47-
const componentName = validateAndNormalizeComponentName(
48-
params.componentName,
49-
);
43+
const { directory, componentName } = params;
5044

5145
const deprecated = getDeprecatedCssClasses(
5246
componentName,

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BaseHandlerOptions,
44
RESULT_FORMATTERS,
55
} from '../shared/utils/handler-helpers.js';
6-
import { validateAndNormalizeComponentName } from '../shared/utils/component-validation.js';
76
import {
87
createViolationReportingSchema,
98
COMMON_ANNOTATIONS,
@@ -37,14 +36,7 @@ export const reportViolationsHandler = createHandler<
3736
// Default to 'file' grouping if not specified
3837
const groupBy = params.groupBy || 'file';
3938

40-
// Normalize component name at handler entry point
41-
const normalizedParams = {
42-
...params,
43-
componentName: validateAndNormalizeComponentName(params.componentName),
44-
};
45-
46-
const result =
47-
await analyzeViolationsBase<ViolationResult>(normalizedParams);
39+
const result = await analyzeViolationsBase<ViolationResult>(params);
4840

4941
const formattedContent = formatViolations(result, params.directory, {
5042
groupBy,

packages/angular-mcp-server/src/lib/tools/ds/shared/utils/component-validation.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { COMPONENT_REGEXES } from './regex-helpers.js';
22

3-
/**
4-
* Normalizes a component name to ensure it has the "Ds" prefix
5-
* @param componentName The component name (e.g., "Button" or "DsButton")
6-
* @returns The normalized component name with "Ds" prefix (e.g., "DsButton")
7-
*/
8-
export function normalizeComponentName(componentName: string): string {
9-
return componentName.startsWith('Ds') ? componentName : `Ds${componentName}`;
10-
}
11-
123
/**
134
* Validates that a component name is a valid Design System component name
145
* Accepts both formats: "Button" and "DsButton"
@@ -29,20 +20,6 @@ export function validateComponentName(
2920
}
3021
}
3122

32-
/**
33-
* Validates and normalizes a component name to ensure it has the "Ds" prefix
34-
* Accepts both formats: "Button" and "DsButton" but always returns "DsButton"
35-
* @param componentName The component name to validate and normalize
36-
* @returns The normalized component name with "Ds" prefix (e.g., "DsButton")
37-
* @throws Error if the component name is invalid
38-
*/
39-
export function validateAndNormalizeComponentName(
40-
componentName: unknown,
41-
): string {
42-
validateComponentName(componentName);
43-
return normalizeComponentName(componentName);
44-
}
45-
4623
/**
4724
* Converts a Design System component name to kebab case
4825
* @param componentName The component name (e.g., "DsButton" or "Button")

packages/angular-mcp-server/src/lib/tools/ds/shared/utils/handler-helpers.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import {
22
CallToolRequest,
33
CallToolResult,
44
} from '@modelcontextprotocol/sdk/types.js';
5-
import {
6-
validateComponentName,
7-
validateAndNormalizeComponentName,
8-
} from './component-validation.js';
5+
import { validateComponentName } from './component-validation.js';
96
import { buildTextResponse, throwError } from './output.utils.js';
107
import * as process from 'node:process';
118

@@ -47,25 +44,6 @@ export function validateCommonInputs(params: BaseHandlerOptions): void {
4744
}
4845
}
4946

50-
/**
51-
* Validates and normalizes common input parameters, returning normalized params
52-
*/
53-
export function validateAndNormalizeCommonInputs<T extends BaseHandlerOptions>(
54-
params: T,
55-
): T {
56-
if (params.componentName) {
57-
params.componentName = validateAndNormalizeComponentName(
58-
params.componentName,
59-
);
60-
}
61-
62-
if (params.directory && typeof params.directory !== 'string') {
63-
throw new Error('Directory parameter is required and must be a string');
64-
}
65-
66-
return params;
67-
}
68-
6947
/**
7048
* Sets up common environment for handlers
7149
*/

0 commit comments

Comments
 (0)