Skip to content

chore: harden ui eslint rules and enable tsc typechecking - #1672

Open
VLukiantsev wants to merge 2 commits into
refactor/eliminate-ui-test-explicit-anyfrom
chore/harden-ui-eslint-and-typecheck
Open

VLukiantsev wants to merge 2 commits into
refactor/eliminate-ui-test-explicit-anyfrom
chore/harden-ui-eslint-and-typecheck

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Harden UI ESLint rules (max-lines and Angular template quality/complexity checks, plus re-enabling unused-imports and no-unused-vars checks on tests/mocks with a .d.ts no-unused-vars exemption while preserving PR #1671's narrow no-explicit-any exemptions) and wire strict tsc typechecking across production, unit-test, and Playwright E2E TypeScript configs into CI and tools/lint/precommit_runner.py.

Motivation & Context

Closing remaining ESLint and TypeScript gaps in test, mock, E2E, and template code prevents agents from bypassing type checking, leaving dead imports, or introducing oversized templates and components.

Key Changes

Modified/added 7 file(s):

  • cmd/ui/eslint.config.js: Enforce max-lines (300 non-blank/non-comment lines for **/*.ts and **/*.html excluding **/index.html; 600 for test, mock_*.ts, *.d.ts, **/testing/**, and **/screenshot_tests/**), add 6 Angular template rules (cyclomatic-complexity max 10, conditional-complexity max 4, no-inline-styles with allowBindToStyle: true, no-any, prefer-at-else, no-interpolation-in-attributes), re-enable unused-imports/no-unused-imports and @typescript-eslint/no-unused-vars on tests/mocks while keeping @typescript-eslint/no-unused-vars: 'off' on **/*.d.ts and preserving PR refactor(ui): remove explicit any and enforce lint rule in ui tests #1671's narrow no-explicit-any exemption on **/app/testing/test.ts and **/app/protos/*.d.ts, and prefix **/dist/**, **/node_modules/**, **/coverage/**, and **/out-tsc/** ignores for cwd-independent matching.
  • cmd/ui/tsconfig.e2e.json & cmd/ui/package.json: Add strict E2E tsconfig (extends: ./tsconfig.json, noEmit: true, types: ["node"]) covering screenshot_tests/**/*.ts and playwright.config.ts, and add "typecheck" running tsc --noEmit across tsconfig.json, tsconfig.spec.json, and tsconfig.e2e.json.
  • .github/workflows/lint.yml: Add Run TypeScript Typecheck (npm run typecheck) step when steps.changes.outputs.ui == 'true'.
  • tools/lint/precommit_runner.py & precommit_runner_test.py: Update check_ui() / _run_ui_eslint() to exclude dist/coverage/out-tsc, capture ACMR changes (including renames), run ESLint with cwd="cmd/ui" (full . when --check or staged_paths_match AM '^cmd/ui/eslint\.config\.js$', filtered .ts/.html otherwise skipping cmd/ui/index.html), and run npm run --silent typecheck when --check or staged_paths_match AMD matches UI .ts/tsconfig*.json/package.json/package-lock.json changes, backed by unit tests in test_check_ui_and_license.
  • .vscode/settings.json: Expand "eslint.validate" from ["typescript"] to ["javascript", "typescript", "html"].

Assumptions

  • Existing UI tests, mock_*.ts fixtures, screenshot specs, and non-*.d.ts helpers satisfy no-unused-vars and unused-imports/no-unused-imports alongside PR refactor(ui): remove explicit any and enforce lint rule in ui tests #1671's no-explicit-any enforcement, while **/*.d.ts retains @typescript-eslint/no-unused-vars: 'off' — ambient .d.ts declaration merging requires matching unused generic parameters, and ESLint passes across cmd/ui — future unused type parameters in .d.ts remain allowed, while unused imports/vars in tests and mocks will fail lint.
  • max-lines limits (300 effective lines for prod TS/HTML, 600 for test/mock/.d.ts/**/testing/**/**/screenshot_tests/**) and template complexity caps (cyclomatic-complexity: 10, conditional-complexity: 4) establish enforceable size/complexity ceilings — current UI files pass eslint . — oversized or branch-heavy components added later will fail lint until refactored.
  • Static tsc --noEmit checking of cmd/ui/tsconfig.e2e.json (types: ["node"], noEmit: true) suffices in lint/pre-commit without executing Playwright browser runtime (npm run test:screenshot) — E2E specs import @playwright/test while playwright.config.ts uses hoisted @types/node for process.env, and browser screenshot runs require ng build + Chromium in the UI test job — removing hoisted @types/node will break static typecheck until added to devDependencies, while Playwright browser runtime regressions would not be flagged by static typecheck alone.
  • Running the three tsc --noEmit projects sequentially via npm run --silent typecheck (cwd="cmd/ui") in precommit_runner.py balances commit speed and clean diagnostics — tsc checks all three configs in seconds sequentially — slower UI trees in the future will add sequential seconds to UI-touching commits, and pre-existing type errors in any of the three configs block unrelated UI commits.
  • Deferring docs/developer.md / .agents/rules/languages/typescript_javascript.md updates for npm run typecheck to dedicated docs updates keeps this check-enabling slice focused — PR chore: harden ui eslint rules and enable tsc typechecking #1672 only modifies lint/typecheck configs, runner, and CI — until updated, docs omit npm run typecheck alongside npm run lint.

Verification & Testing

  • Commands Executed:
    • ./.githooks/pre-commit --check (includes full UI Prettier/ESLint/tsc, actionlint, golangci-lint, ruff, mypy, shellcheck, and Bazel tests via run_affected_tests.py --skip-emulator-check)
    • (cd cmd/ui && ./node_modules/.bin/eslint . && npm run --silent typecheck)
    • bazel test --test_output=errors //tools/lint:precommit_runner_test //cmd/ui:ui_unit_tests
  • Coverage & Test Status:
    • Verified cleanly rebased onto updated PR refactor(ui): remove explicit any and enforce lint rule in ui tests #1671 (cmd/ui/eslint.config.js preserving narrow test.ts and app/protos/*.d.ts no-explicit-any exemption), with full ./.githooks/pre-commit --check, ESLint, typecheck, //tools/lint:precommit_runner_test, and //cmd/ui:ui_unit_tests passing on the stack. Playwright browser screenshot runtime (npm run test:screenshot) was not executed locally.

Related Issues / Bugs

N/A (part of automated linter and refactoring stack).

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c

@VLukiantsev
VLukiantsev added this pull request to stack #1675 November 12, 2026 19:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces UI typechecking via tsc to the pre-commit hook and adds a new typecheck script, along with updating ESLint rules and VS Code settings. Feedback on these changes includes removing the non-existent @angular-eslint/template/prefer-at-else rule which will break ESLint, restoring overrides for no-explicit-any and no-unused-vars in test and mock files to avoid overly verbose type assertions, and running the sequential tsc checks in parallel within the pre-commit hook to improve execution speed.

Comment thread cmd/ui/eslint.config.js Resolved
Comment thread cmd/ui/eslint.config.js Resolved
Comment thread .githooks/pre-commit Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 81b9dba to 6f25670 Compare November 13, 2026 00:07
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the pre-commit githook to run TypeScript typechecking and optimize UI formatting and linting, introduces a new tsconfig.e2e.json configuration, and enhances ESLint rules for TypeScript and HTML templates. The review feedback suggests improving the git diff filters in the pre-commit hook to include renamed and copied files (ACMR and ACMRD) so they are not skipped during checks. Additionally, it is recommended to remove the max-lines rule from the HTML ESLint configuration as it is ineffective on Angular HTML templates.

Comment thread .githooks/pre-commit Resolved
Comment thread .githooks/pre-commit Resolved
Comment thread cmd/ui/eslint.config.js Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 6f25670 to 0d4aaf9 Compare November 13, 2026 00:16
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the pre-commit hook to support UI typechecking and refactors ESLint configurations, including adding new rules for TypeScript and Angular templates. The review feedback highlights two key issues: a bug in the pre-commit hook's regular expression that prevents typechecking from triggering when root configuration files (like tsconfig.json or package.json) are modified, and an inactive 'max-lines' rule configuration in the ESLint settings for HTML files, which is silently ignored due to the custom AST parser used for Angular templates.

Comment thread .githooks/pre-commit Resolved
Comment thread cmd/ui/eslint.config.js Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 0d4aaf9 to 3f3e6ae Compare November 13, 2026 00:24
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the pre-commit hook to improve UI file handling, introduces a new TypeScript type-checking step, and updates ESLint configurations with stricter rules and HTML template validations. It also adds a dedicated tsconfig.e2e.json for end-to-end tests. Feedback suggests adding @types/node to the UI package dependencies to prevent potential type-checking failures due to dependency hoisting.

Comment thread cmd/ui/tsconfig.e2e.json Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 3f3e6ae to 50a6d68 Compare November 13, 2026 08:22
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 50a6d68 to 1642a35 Compare November 13, 2026 09:19
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch 2 times, most recently from 7a6ced9 to b01cf90 Compare November 13, 2026 10:56
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch 2 times, most recently from 8649f00 to ccfdced Compare November 13, 2026 12:52
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch 2 times, most recently from ce31da0 to ab5d147 Compare November 13, 2026 14:12
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from ab5d147 to 0071503 Compare November 13, 2026 14:58
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch 2 times, most recently from 9fc76be to b59f2b8 Compare November 16, 2026 09:17
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from b59f2b8 to 2c0b1ad Compare November 16, 2026 11:14
@VLukiantsev
VLukiantsev removed this pull request from stack #1675 November 16, 2026 11:16
@VLukiantsev
VLukiantsev added this pull request to stack #1702 November 16, 2026 11:16
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 2c0b1ad to f54f474 Compare November 16, 2026 11:44
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from f54f474 to 68205b1 Compare November 16, 2026 12:36
@VLukiantsev
VLukiantsev marked this pull request as ready for review November 16, 2026 19:24
@github-actions
github-actions Bot requested a review from AntonTyb November 16, 2026 19:24
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 68205b1 to 91db96f Compare November 16, 2026 19:56
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the UI linting and type-checking configuration, including adding a new typecheck script, a tsconfig.e2e.json file, and expanding ESLint rules for TypeScript and HTML templates. The pre-commit runner is also refactored to support these checks. Feedback points out a cross-platform compatibility issue in the pre-commit runner where the ESLint binary path is hardcoded instead of using the dynamically resolved path.

Comment thread tools/lint/precommit_runner.py Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 91db96f to 779092b Compare November 16, 2026 20:08
VLukiantsev added a commit that referenced this pull request Nov 16, 2026
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
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the UI linting and typechecking setup by adding HTML and JavaScript validation to VS Code, introducing a new TypeScript configuration for E2E tests, and updating ESLint rules. Additionally, the pre-commit runner is refactored to support selective ESLint execution and TypeScript typechecking. The review feedback identifies two important improvements: normalizing file paths to POSIX style in the pre-commit runner to ensure cross-platform compatibility on Windows, and running the tsc binary directly instead of through npm run to reduce process startup overhead.

Comment thread tools/lint/precommit_runner.py Resolved
Comment on lines +180 to +188
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.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of invoking npm run --silent typecheck which introduces significant startup overhead from npm (often 0.5 to 1.5 seconds), we can run the resolved tsc binary directly on each configuration file. This is much faster, avoids the extra process overhead, and aligns with how eslint and prettier are executed.

    if run_typecheck and (tsc := gates.resolve_ui_binary(ctx, "tsc")):
        print("--> Running UI Typechecker (tsc)...")
        failed = False
        for config in ("tsconfig.json", "tsconfig.spec.json", "tsconfig.e2e.json"):
            if (
                gates.exec_cmd(
                    [tsc, "--noEmit", "-p", config], cwd=gates.REPO_ROOT / "cmd/ui"
                ).returncode
                != 0
            ):
                failed = True
                break
        if failed:
            ctx.fail("UI TypeScript typecheck failed.")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push Back: Intentionally keeping npm run --silent typecheck so the list of TypeScript project configs (tsconfig.json, tsconfig.spec.json, tsconfig.e2e.json) stays in a single source of truth inside cmd/ui/package.json shared with .github/workflows/lint.yml (Run TypeScript Typecheck), rather than duplicating the project list in tools/lint/precommit_runner.py where future configs could drift. This trade-off is documented in PR #1672 ## Assumptions.

…e 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
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
@VLukiantsev
VLukiantsev force-pushed the chore/harden-ui-eslint-and-typecheck branch from 627c8bc to 5362ec2 Compare November 17, 2026 11:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant