From a4a17ffdf716d6945f2b61c1c3ecd4f3e101f437 Mon Sep 17 00:00:00 2001 From: Vlad Lukiantsev Date: Mon, 16 Nov 2026 10:47:27 +0000 Subject: [PATCH 1/2] chore(ui): harden ui eslint rules, fix hook basePath globs, and enable tsc typechecking - Fix ESLint root-cwd glob matching in `cmd/ui/eslint.config.js` (`**/app/testing/**`, `**/index.html`, `**/dist/**`, `**/coverage/**`, `**/out-tsc/**`, `**/node_modules/**`), enforce `max-lines` and Angular template rules, and keep strict `no-explicit-any`/`no-unused-vars`/`unused-imports` checks enabled on tests and mocks. - Update `tools/lint/precommit_runner.py` (`check_ui`) to exclude `dist`/`coverage`/`out-tsc`, run ESLint from `cmd/ui`, delegate `npm run --silent typecheck`, and cover deletes/renames, `eslint.config.js`, `tsconfig*.json`, and `package*.json`. - Add `cmd/ui/tsconfig.e2e.json`, `npm run typecheck`, `.github/workflows/lint.yml` typecheck step, and `.vscode/settings.json` ESLint validators. TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c --- .github/workflows/lint.yml | 5 ++ .vscode/settings.json | 4 +- cmd/ui/eslint.config.js | 28 ++++++++-- cmd/ui/package.json | 1 + cmd/ui/tsconfig.e2e.json | 9 +++ tools/lint/precommit_runner.py | 85 +++++++++++++++++++++-------- tools/lint/precommit_runner_test.py | 38 +++++++++++-- 7 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 cmd/ui/tsconfig.e2e.json diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 701e2051e..ac7b05b42 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -271,6 +271,11 @@ jobs: run: npm run lint working-directory: 'cmd/ui' + - name: 'Run TypeScript Typecheck' + if: steps.changes.outputs.ui == 'true' + run: npm run typecheck + working-directory: 'cmd/ui' + - name: 'Run ESLint on Non-UI JS Scripts' if: github.event_name == 'workflow_dispatch' || steps.changes.outputs.nonui_js == 'true' run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index cbe0dc2cd..e2bcd6368 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,8 @@ "source.fixAll.eslint": "explicit" }, "eslint.validate": [ - "typescript" + "javascript", + "typescript", + "html" ] } diff --git a/cmd/ui/eslint.config.js b/cmd/ui/eslint.config.js index 44c428b4e..76433706c 100644 --- a/cmd/ui/eslint.config.js +++ b/cmd/ui/eslint.config.js @@ -25,7 +25,14 @@ import eslintConfigPrettier from 'eslint-config-prettier'; export default tseslint.config( { - ignores: ['dist/**', 'node_modules/**', 'coverage/**', '**/*.scss', '**/*.css'], + ignores: [ + '**/dist/**', + '**/node_modules/**', + '**/coverage/**', + '**/out-tsc/**', + '**/*.scss', + '**/*.css', + ], }, { files: ['**/*.ts'], @@ -102,6 +109,7 @@ export default tseslint.config( ], }, ], + 'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }], 'max-lines-per-function': ['error', { max: 35, skipComments: true }], complexity: ['error', { max: 10, variant: 'modified' }], 'max-depth': ['error', 3], @@ -151,9 +159,8 @@ export default tseslint.config( '**/screenshot_tests/**', ], rules: { - 'unused-imports/no-unused-imports': 'off', - '@typescript-eslint/no-unused-vars': 'off', '@angular-eslint/prefer-standalone': 'off', + 'max-lines': ['error', { max: 600, skipBlankLines: true, skipComments: true }], 'max-lines-per-function': 'off', complexity: 'off', }, @@ -164,6 +171,12 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'off', }, }, + { + files: ['**/*.d.ts'], + rules: { + '@typescript-eslint/no-unused-vars': 'off', + }, + }, { files: ['**/*.ts'], ignores: [ @@ -203,7 +216,7 @@ export default tseslint.config( }, { files: ['**/*.html'], - ignores: ['index.html'], + ignores: ['**/index.html'], languageOptions: { parser: angularTemplateParser, }, @@ -225,6 +238,13 @@ export default tseslint.config( '@angular-eslint/template/valid-aria': 'error', '@angular-eslint/template/elements-content': 'error', '@angular-eslint/template/no-positive-tabindex': 'error', + 'max-lines': ['error', { max: 300, skipBlankLines: true, skipComments: true }], + '@angular-eslint/template/cyclomatic-complexity': ['error', { maxComplexity: 10 }], + '@angular-eslint/template/conditional-complexity': ['error', { maxComplexity: 4 }], + '@angular-eslint/template/no-inline-styles': ['error', { allowBindToStyle: true }], + '@angular-eslint/template/no-any': 'error', + '@angular-eslint/template/prefer-at-else': 'error', + '@angular-eslint/template/no-interpolation-in-attributes': 'error', }, }, eslintConfigPrettier, diff --git a/cmd/ui/package.json b/cmd/ui/package.json index eb0b63a39..57d76ce37 100644 --- a/cmd/ui/package.json +++ b/cmd/ui/package.json @@ -11,6 +11,7 @@ "test:screenshot": "playwright test", "test:screenshot:update": "playwright test --update-snapshots", "lint": "eslint .", + "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.spec.json && tsc --noEmit -p tsconfig.e2e.json", "format": "prettier --write --ignore-path ../../.gitignore .", "format:check": "prettier --check --ignore-path ../../.gitignore ." }, diff --git a/cmd/ui/tsconfig.e2e.json b/cmd/ui/tsconfig.e2e.json new file mode 100644 index 000000000..ec5410f85 --- /dev/null +++ b/cmd/ui/tsconfig.e2e.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": true, + "types": ["node"] + }, + "include": ["screenshot_tests/**/*.ts", "playwright.config.ts"], + "exclude": ["node_modules", "dist"] +} diff --git a/tools/lint/precommit_runner.py b/tools/lint/precommit_runner.py index 0125c2b7d..175221566 100755 --- a/tools/lint/precommit_runner.py +++ b/tools/lint/precommit_runner.py @@ -119,31 +119,72 @@ def check_go(ctx: gates.RunContext) -> None: ) +_UI_EXCLUDES = gates.COMMON_EXCLUDES | frozenset({"dist", "coverage", "out-tsc"}) +_UI_TYPECHECK_PATTERN = ( + r"^cmd/ui/(.*\.ts|([^/]+/)*tsconfig[^/]*\.json|([^/]+/)*package(-lock)?\.json)$" +) + + +def _run_ui_eslint(ctx: gates.RunContext, ui_files: Sequence[str], *, run_all_eslint: bool) -> None: + ui_lint_files = [ + f.removeprefix("cmd/ui/") + for f in ui_files + if f != "cmd/ui/index.html" and f.endswith((".ts", ".html")) + ] + if not run_all_eslint and not ui_lint_files: + return + if not gates.resolve_ui_binary(ctx, "eslint"): + return + print("--> Running UI Linter (ESLint)...") + targets = ["."] if run_all_eslint else ui_lint_files + gates.run_mode_command( + ctx, + ["./node_modules/.bin/eslint"], + check_args=[], + fix_args=["--fix"], + failure_msg="ESLint check failed.", + cwd=gates.REPO_ROOT / "cmd/ui", + files=targets, + chunk_size=200, + ) + + def check_ui(ctx: gates.RunContext) -> None: - """Runs Prettier and ESLint on Angular UI sources.""" - files = gates.collect_target_files( - ctx.mode, - staged_regex=r"^cmd/ui/.*\.(ts|html|scss)$", - roots=("cmd/ui",), - suffixes=(".ts", ".html", ".scss"), + """Runs Prettier, ESLint (cwd=`cmd/ui`), and `tsc` typecheck on Angular UI sources.""" + if ctx.mode == "check": + ui_files = gates.walk_repo_files( + ("cmd/ui",), suffixes=(".ts", ".html", ".scss"), excluded_dirs=_UI_EXCLUDES + ) + else: + regex = re.compile(r"^cmd/ui/.*\.(ts|html|scss)$") + ui_files = [p for p in gates.git_staged_paths("ACMR") if regex.search(p)] + run_all_eslint = ctx.mode == "check" or gates.staged_paths_match( + "AM", r"^cmd/ui/eslint\.config\.js$" ) - if not files: + run_typecheck = ctx.mode == "check" or gates.staged_paths_match("AMD", _UI_TYPECHECK_PATTERN) + if not ui_files and not run_all_eslint and not run_typecheck: return - for tool, cfg, chk, fx, title in ( - ("prettier", "cmd/ui/.prettierrc", ["--check"], ["--write"], "Formatter (Prettier)"), - ("eslint", "cmd/ui/eslint.config.js", [], ["--fix"], "Linter (ESLint)"), - ): - if binary := gates.resolve_ui_binary(ctx, tool): - print(f"--> Running UI {title}...") - gates.run_mode_command( - ctx, - [binary, "--config", cfg], - check_args=chk, - fix_args=fx, - failure_msg=f"{tool.capitalize()} check failed.", - files=files, - chunk_size=200, - ) + if ui_files and (prettier := gates.resolve_ui_binary(ctx, "prettier")): + print("--> Running UI Formatter (Prettier)...") + gates.run_mode_command( + ctx, + [prettier, "--config", "cmd/ui/.prettierrc"], + check_args=["--check"], + fix_args=["--write"], + failure_msg="Prettier check failed.", + files=ui_files, + chunk_size=200, + ) + _run_ui_eslint(ctx, ui_files, run_all_eslint=run_all_eslint) + if run_typecheck and gates.resolve_ui_binary(ctx, "tsc"): + print("--> Running UI Typechecker (tsc)...") + if ( + gates.exec_cmd( + ["npm", "run", "--silent", "typecheck"], cwd=gates.REPO_ROOT / "cmd/ui" + ).returncode + != 0 + ): + ctx.fail("UI TypeScript typecheck failed.") def check_license(ctx: gates.RunContext) -> None: diff --git a/tools/lint/precommit_runner_test.py b/tools/lint/precommit_runner_test.py index 814d5c9a5..4ba225734 100644 --- a/tools/lint/precommit_runner_test.py +++ b/tools/lint/precommit_runner_test.py @@ -149,17 +149,47 @@ def test_check_go_fails_on_gofmt_and_go_mod_tidy_errors_in_fix_mode(self): def test_check_ui_chunks_and_license(self): ctx = gates.RunContext(mode="fix") - many_ui = [f"cmd/ui/src/f{i}.ts" for i in range(201)] with ( - mock.patch.object(gates, "collect_target_files", return_value=many_ui), - mock.patch.object(gates, "resolve_ui_binary", side_effect=["/p/prettier", "/p/eslint"]), + mock.patch.object( + gates, + "git_staged_paths", + return_value=["cmd/ui/app.ts", "cmd/ui/index.html", "cmd/ui/s.scss"], + ), + mock.patch.object(gates, "staged_paths_match", side_effect=[False, True]), + mock.patch.object( + gates, "resolve_ui_binary", side_effect=["/p/prettier", "/p/eslint", "/p/tsc"] + ), mock.patch.object(gates, "run_mode_command") as run_mode, + mock.patch.object( + gates, "exec_cmd", return_value=subprocess.CompletedProcess([], 0, "", "") + ) as exec_mock, mock.patch("sys.stdout", new_callable=io.StringIO), ): runner.check_ui(ctx) + self.assertFalse(ctx.failed) self.assertEqual(run_mode.call_count, 2) self.assertEqual(run_mode.call_args_list[0].kwargs["chunk_size"], 200) - self.assertEqual(run_mode.call_args_list[0].kwargs["files"], many_ui) + self.assertEqual( + run_mode.call_args_list[0].kwargs["files"], + ["cmd/ui/app.ts", "cmd/ui/index.html", "cmd/ui/s.scss"], + ) + self.assertEqual(run_mode.call_args_list[1].kwargs["cwd"], gates.REPO_ROOT / "cmd/ui") + self.assertEqual(run_mode.call_args_list[1].kwargs["fix_args"], ["--fix"]) + self.assertEqual(run_mode.call_args_list[1].kwargs["files"], ["app.ts"]) + exec_mock.assert_called_once_with( + ["npm", "run", "--silent", "typecheck"], cwd=gates.REPO_ROOT / "cmd/ui" + ) + + ctx_cfg = gates.RunContext(mode="fix") + with ( + mock.patch.object(gates, "git_staged_paths", return_value=["cmd/ui/eslint.config.js"]), + mock.patch.object(gates, "staged_paths_match", side_effect=[True, False]), + mock.patch.object(gates, "resolve_ui_binary", return_value="/p/eslint"), + mock.patch.object(gates, "run_mode_command") as run_mode_cfg, + mock.patch("sys.stdout", new_callable=io.StringIO), + ): + runner.check_ui(ctx_cfg) + self.assertEqual(run_mode_cfg.call_args.kwargs["files"], ["."]) ctx_check = gates.RunContext(mode="check") with ( From 29b5c899d60c1fe6c924ccf9582e9729a92943cd Mon Sep 17 00:00:00 2001 From: Vlad Lukiantsev Date: Mon, 16 Nov 2026 20:12:32 +0000 Subject: [PATCH 2/2] fix(lint): invoke resolved eslint binary in _run_ui_eslint Address PR #1672 review feedback (`4590816747`) by invoking the resolved `eslint` path from `gates.resolve_ui_binary(ctx, "eslint")` instead of hardcoding `./node_modules/.bin/eslint`, and assert the passed binary in `precommit_runner_test.py`. TAG=agy CONV=ba8411ef-c093-4f45-950a-b3bc1899268c --- tools/lint/precommit_runner.py | 5 +++-- tools/lint/precommit_runner_test.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/lint/precommit_runner.py b/tools/lint/precommit_runner.py index 175221566..1ceb6af97 100755 --- a/tools/lint/precommit_runner.py +++ b/tools/lint/precommit_runner.py @@ -133,13 +133,14 @@ def _run_ui_eslint(ctx: gates.RunContext, ui_files: Sequence[str], *, run_all_es ] if not run_all_eslint and not ui_lint_files: return - if not gates.resolve_ui_binary(ctx, "eslint"): + eslint = gates.resolve_ui_binary(ctx, "eslint") + if not eslint: return print("--> Running UI Linter (ESLint)...") targets = ["."] if run_all_eslint else ui_lint_files gates.run_mode_command( ctx, - ["./node_modules/.bin/eslint"], + [eslint], check_args=[], fix_args=["--fix"], failure_msg="ESLint check failed.", diff --git a/tools/lint/precommit_runner_test.py b/tools/lint/precommit_runner_test.py index 4ba225734..5195b4aa6 100644 --- a/tools/lint/precommit_runner_test.py +++ b/tools/lint/precommit_runner_test.py @@ -173,6 +173,7 @@ def test_check_ui_chunks_and_license(self): run_mode.call_args_list[0].kwargs["files"], ["cmd/ui/app.ts", "cmd/ui/index.html", "cmd/ui/s.scss"], ) + self.assertEqual(run_mode.call_args_list[1].args[1], ["/p/eslint"]) self.assertEqual(run_mode.call_args_list[1].kwargs["cwd"], gates.REPO_ROOT / "cmd/ui") self.assertEqual(run_mode.call_args_list[1].kwargs["fix_args"], ["--fix"]) self.assertEqual(run_mode.call_args_list[1].kwargs["files"], ["app.ts"])