Skip to content

Commit 3b48e07

Browse files
better check direction param
1 parent b439a8e commit 3b48e07

4 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/checker.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ interface TypeMismatch {
4545
paramsType: string[];
4646
}
4747

48+
/**
49+
* Parameter information with direction
50+
*/
51+
interface ParameterInfo {
52+
name: string;
53+
direction: Direction;
54+
}
55+
4856
/**
4957
* Validation result for variant parameters
5058
*/
@@ -102,19 +110,36 @@ export class SyntaxChecker {
102110
}
103111

104112
/**
105-
* Extract actual parameter names from parameter array
113+
* Extract actual parameter names and directions from parameter array
114+
* @param params - Parameter array from documentation
115+
* @returns Array of parameter info with names and directions
116+
*/
117+
extractActualParamNames(params: DocumentationParameter[]): ParameterInfo[] {
118+
if (!params || params.length === 0) return [];
119+
120+
return params
121+
.filter(param => param.direction !== undefined) // Only include params with valid direction
122+
.map(param => ({
123+
name: param.name.toLowerCase(),
124+
direction: param.direction!
125+
}));
126+
}
127+
128+
/**
129+
* Get input parameter names (excluding return parameters)
106130
* @param params - Parameter array from documentation
107-
* @returns Array of parameter names
131+
* @returns Array of input parameter names
108132
*/
109-
extractActualParamNames(params: DocumentationParameter[]): string[] {
133+
getInputParameterNames(params: DocumentationParameter[]): string[] {
110134
if (!params || params.length === 0) return [];
111135

112136
return params
113137
.filter(param => {
114138
const name = param.name;
115139
const direction = param.direction;
116-
// Only include input and input/output parameters, exclude return parameters
140+
// Only include parameters with valid direction, and exclude return parameters
117141
return (
142+
direction !== undefined &&
118143
direction !== Direction.Return &&
119144
name !== 'Function result'
120145
);
@@ -402,7 +427,8 @@ export class SyntaxChecker {
402427

403428
// Check if there are any errors/warnings
404429
let hasErrors = false;
405-
const actualParamNames = params && params.length > 0 ? this.extractActualParamNames(params) : [];
430+
const actualParamNames = params && params.length > 0 ? this.getInputParameterNames(params) : [];
431+
const allParamInfo = params && params.length > 0 ? this.extractActualParamNames(params) : [];
406432

407433
// Check each parsed variant for issues (malformations and parameter errors)
408434
parsedParams.forEach((variant) => {
@@ -421,6 +447,7 @@ export class SyntaxChecker {
421447
console.log('\nActual Params:', JSON.stringify(params, null, 2));
422448

423449
console.log('Expected parameter names:', actualParamNames);
450+
console.log('All parameter info:', allParamInfo.map(p => `${p.name} (direction: ${p.direction})`));
424451

425452
// Check each parsed variant
426453
parsedParams.forEach((variant, index) => {
@@ -456,6 +483,7 @@ export class SyntaxChecker {
456483
case '->': return Direction.In;
457484
case '←':
458485
case '<-': return Direction.Return;
486+
case '&#8596;':
459487
case '<->': return Direction.IO;
460488
}
461489
return undefined;

tests/integration/entry-points.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Entry Points and CLI', () => {
6969
const checker = new SyntaxChecker();
7070

7171
// Test basic functionality
72-
const result = checker.extractActualParamNames(checker.parseParams([
72+
const result = checker.getInputParameterNames(checker.parseParams([
7373
['param1', 'Type1', '&#8594;', 'Description1']
7474
] as any));
7575

@@ -151,7 +151,7 @@ describe('Entry Points and CLI', () => {
151151

152152
const promises = Array.from({ length: 10 }, async (_, i) => {
153153
const checker = new module.SyntaxChecker();
154-
return checker.extractActualParamNames(checker.parseParams([
154+
return checker.getInputParameterNames(checker.parseParams([
155155
[`param${i}`, `Type${i}`, '&#8594;', `Description${i}`]
156156
] as any));
157157
});

tests/validation/checker-comprehensive.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('SyntaxChecker - Comprehensive Coverage', () => {
2828
['Result', 'Type3', '<-', 'Description3']
2929
];
3030

31-
const result = checker.extractActualParamNames(checker.parseParams(params));
31+
const result = checker.getInputParameterNames(checker.parseParams(params));
3232

3333
expect(result).toEqual(['param1', 'param2']);
3434
});
@@ -40,7 +40,7 @@ describe('SyntaxChecker - Comprehensive Coverage', () => {
4040
['Result', 'Type3', '<-', 'Description3']
4141
];
4242

43-
const result = checker.extractActualParamNames(checker.parseParams(params));
43+
const result = checker.getInputParameterNames(checker.parseParams(params));
4444

4545
expect(result).toEqual(['param1', 'param2']);
4646
});
@@ -61,7 +61,7 @@ describe('SyntaxChecker - Comprehensive Coverage', () => {
6161
['UPPERPARAM', 'Type2', '->', 'Description2']
6262
];
6363

64-
const result = checker.extractActualParamNames(checker.parseParams(params));
64+
const result = checker.getInputParameterNames(checker.parseParams(params));
6565

6666
expect(result).toEqual(['paramname', 'upperparam']);
6767
});

tests/validation/command-validation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('SyntaxChecker Command Validation', () => {
7373
['param4', 'Object', '&#8596;', 'Input/Output parameter (HTML arrow)']
7474
] as any[];
7575

76-
const actualParamNames = checker.extractActualParamNames(checker.parseParams(params));
76+
const actualParamNames = checker.getInputParameterNames(checker.parseParams(params));
7777
expect(actualParamNames).toContain('param1');
7878
expect(actualParamNames).toContain('param2');
7979
expect(actualParamNames).toContain('param3');
@@ -87,7 +87,7 @@ describe('SyntaxChecker Command Validation', () => {
8787
['error', 'Boolean', '<-', 'Output parameter (HTML arrow)']
8888
] as any[];
8989

90-
const actualParamNames = checker.extractActualParamNames(checker.parseParams(params));
90+
const actualParamNames = checker.getInputParameterNames(checker.parseParams(params));
9191
expect(actualParamNames).toContain('param1');
9292
expect(actualParamNames).not.toContain('result'); // Result should be excluded
9393
expect(actualParamNames).not.toContain('error');

0 commit comments

Comments
 (0)