validate_syntax
Check code files for syntax errors to identify and fix issues before execution. Supports multiple file paths for batch validation.
Instructions
Validate syntax of code files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | File paths to validate |
Implementation Reference
- src/tools/linting.ts:116-130 (handler)Handler logic for the 'validate_syntax' tool: parses input files, calls validateSyntax helper on each, and returns validation results per file.case 'validate_syntax': { const files = params.files as string[]; const codeFiles = await FileReader.readFiles(files.join(',')); const results = codeFiles.map((file) => { const validation = lintingUtils.validateSyntax( file.content, file.language || 'javascript' ); return { file: file.path, ...validation, }; }); return results; }
- src/tools/linting.ts:56-70 (registration)Tool registration defining name, description, and input schema for 'validate_syntax'.{ name: 'validate_syntax', description: 'Validate syntax of code files', inputSchema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' }, description: 'File paths to validate', }, }, required: ['files'], }, },
- src/tools/linting.ts:59-69 (schema)Input schema defining the expected parameters: array of file paths.inputSchema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' }, description: 'File paths to validate', }, }, required: ['files'], },
- src/utils/linting-utils.ts:165-193 (helper)Helper function implementing basic syntax validation by matching braces, parentheses, and brackets for JS/TS code.validateSyntax(code: string, language: string): { valid: boolean; errors: string[] } { const errors: string[] = []; if (language === 'javascript' || language === 'typescript') { // Basic bracket matching const openBracesCount = (code.match(/{/g) || []).length; const closeBracesCount = (code.match(/}/g) || []).length; if (openBracesCount !== closeBracesCount) { errors.push('Unmatched braces'); } const openParens = (code.match(/\(/g) || []).length; const closeParens = (code.match(/\)/g) || []).length; if (openParens !== closeParens) { errors.push('Unmatched parentheses'); } const openBrackets = (code.match(/\[/g) || []).length; const closeBrackets = (code.match(/\]/g) || []).length; if (openBrackets !== closeBrackets) { errors.push('Unmatched brackets'); } } return { valid: errors.length === 0, errors, }; }