#!/usr/bin/env node /** * JavaScript Syntax Linter for Code Quality Checks * * This script checks JavaScript files for syntax errors using Babel parser * with support for decorators and modern JavaScript features. * * Usage: node js-linter.js * Exit codes: * 0 - No syntax errors * 1 - Syntax error found */ const fs = require('fs'); const path = require('path'); // Resolve to system/node_modules since that's where packages are installed const systemDir = path.resolve(__dirname, '..'); const babelParser = require(path.join(systemDir, 'node_modules', '@babel', 'parser')); // Get input file from command line arguments const inputFile = process.argv[2]; if (!inputFile) { console.error('Usage: node js-linter.js '); process.exit(1); } try { const code = fs.readFileSync(inputFile, 'utf8'); // Parse the code to check for syntax errors // Babel parser supports decorators natively babelParser.parse(code, { sourceType: 'module', plugins: [ 'decorators-legacy', // Support for @decorator syntax 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'optionalChaining', 'nullishCoalescingOperator', 'asyncGenerators', 'bigInt', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'objectRestSpread', 'topLevelAwait' ] }); // Silent success - no output when no errors process.exit(0); } catch (error) { // Output error information console.error('Syntax error: ' + error.message); if (error.loc) { console.error('Line: ' + error.loc.line); console.error('Column: ' + error.loc.column); } process.exit(1); }