From d65f9312ea83a50db0642d476b22fac982a7a870 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:32:15 -0800 Subject: [PATCH 1/2] Add lint-changes npm scripts --- bin/lint_changes.js | 49 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 51 insertions(+) create mode 100644 bin/lint_changes.js diff --git a/bin/lint_changes.js b/bin/lint_changes.js new file mode 100644 index 00000000..a8edb44c --- /dev/null +++ b/bin/lint_changes.js @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2026 The xterm.js authors. All rights reserved. + * @license MIT + */ + +// @ts-check + +const { execSync, spawn } = require('child_process'); +const path = require('path'); + +const extensions = ['.ts', '.mts']; +const fix = process.argv.includes('--fix'); + +// Get uncommitted changed files (staged + unstaged) +function getChangedFiles() { + try { + const output = execSync('git diff --name-only --diff-filter=ACMR HEAD', { + encoding: 'utf-8', + cwd: path.join(__dirname, '..') + }); + return output.split('\n').filter(f => f && extensions.some(ext => f.endsWith(ext))); + } catch { + return []; + } +} + +const files = getChangedFiles(); + +if (files.length === 0) { + console.log('No changed TypeScript files to lint.'); + process.exit(0); +} + +console.log(`Linting ${files.length} changed file(s)...`); + +const eslintArgs = ['--max-warnings', '0']; +if (fix) { + eslintArgs.push('--fix'); +} +eslintArgs.push(...files); + +const eslint = process.platform === 'win32' ? 'eslint.cmd' : 'eslint'; +const child = spawn(eslint, eslintArgs, { + stdio: 'inherit', + cwd: path.join(__dirname, '..'), + shell: process.platform === 'win32' +}); + +child.on('close', code => process.exit(code ?? 0)); diff --git a/package.json b/package.json index ecb60ef4..9b54946c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,8 @@ "test": "npm run test-unit", "posttest": "npm run lint", "lint": "eslint --max-warnings 0 src/ addons/ demo/", + "lint-changes": "node ./bin/lint_changes.js", + "lint-changes-fix": "node ./bin/lint_changes.js --fix", "lint-fix": "eslint --fix src/ addons/ demo/", "lint-api": "eslint --config eslint.config.typings.mjs --max-warnings 0 typings/", "test-unit": "node ./bin/test_unit.js", From d6f6a6af9a7df03c3feaa3ff0e1a97fb9b28ae7c Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 8 Jan 2026 17:32:50 -0800 Subject: [PATCH 2/2] Lint instructions --- .github/copilot-instructions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 97325cb8..461f8fdb 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -26,6 +26,7 @@ npm run build && npm run esbuild # Build all TypeScript and bundle - Integration tests: `npm run test-integration` (Playwright across Chrome/Firefox/WebKit) - Integration tests by file: `npm run test-integration -- test/playwright/InputHandler.test.ts`. Never use grep to filter tests, it doesn't work - Integration tests by addon: `npm run test-integration --suite=addon-search`. Suites always follow the format `addon-` +- Lint changes: `npm run lint-changes` to lint only changed files, `npm run lint-changes-fix` to fix them ## Addon Development Pattern