Skip to content

chore: enforce eslint on non-ui js scripts - #1668

Open
VLukiantsev wants to merge 5 commits into
refactor/decompose-approval-scriptsfrom
chore/lint-non-ui-js-scripts
Open

VLukiantsev wants to merge 5 commits into
refactor/decompose-approval-scriptsfrom
chore/lint-non-ui-js-scripts

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add tools/lint/eslint.nonui.config.mjs (enforcing complexity: 15, max-lines-per-function: 80, no-empty, no-unused-vars, eqeqeq), wire ESLint for non-UI JS into .github/workflows/lint.yml and tools/lint/precommit_runner.py (check_nonui_js), harden git-range-diff.js / range-diff-parser.js alongside unused test imports, and synchronize linter docs.

Motivation & Context

Non-UI JavaScript scripts under .github/scripts/, tools/nightly_tests/, and cmd/experiment_state_server/static/ previously bypassed ESLint completely. Auditing the scripts under those rules also surfaced a fail-open catch (_) in getPrChangedFiles, missing --no-renames flags on git diff --name-only calls, and an unbounded leading-whitespace regex in parseRangeDiff.

Key Changes

Modified/added 13 file(s) (214 prod, 290 test, 8 doc lines via tools/analyze_diff_size.py):

  • .github/scripts/git-range-diff.js, .github/scripts/git-range-diff.test.js, .github/scripts/approval-policy.test.js, & .github/scripts/README.md: Document intentional best-effort catch (_) blocks, remove the unreachable/fail-open try / catch (_) in getPrChangedFiles, normalize ignoreExitCode: false and pass '--no-renames' across all three git diff --name-only calls (3-dot, follow-up, and 2-dot), remove unused test imports, update positional git diff mock assertions, add fail-closed / unreachable-SHA / option-normalization / --no-renames / moved-protected-file regression tests, and align the README.md 3-dot diff snippet.
  • .github/scripts/range-diff-parser.js & .github/scripts/range-diff-parser.test.js: Add no-control-regex suppression for ANSI stripping, bound commitMatch leading spaces to ^ {0,3} to prevent context/commit-message header forgery, and add regression tests.
  • .github/workflows/lint.yml: Add recursive nonui_js dorny/paths-filter globs (**/*.js), workflow_dispatch guards on Node setup/install/ESLint steps, and git ls-files -z enumeration with wait "$!" fail-closed propagation for ESLint on non-UI JS.
  • tools/lint/eslint.nonui.config.mjs: Add ESLint 10 flat config with max-lines-per-function hoisted into BASE_RULES and **/*.test.js / **/*_test.js overrides ordered last.
  • tools/lint/precommit_runner.py & tools/lint/precommit_runner_test.py: Add check_nonui_js() (:(glob) recursive discovery when --check or tools/lint/eslint.nonui.config.mjs is staged ACMR, else matching staged non-UI JS paths; reuses gates.resolve_ui_binary(ctx, "eslint")) and unit tests covering not files, missing eslint (check vs fix), config trigger regex, and filtered exec_cmd args/cwd.
  • docs/developer.md, tools/README.md, .agents/rules/rule_authoring_standards.md: Document non-UI JS ESLint scope, pre-commit trigger behavior, and Rung-2 lint destination.

Assumptions

  • Reusing ESLint 10 from cmd/ui/node_modules/.bin/eslint (gates.resolve_ui_binary(ctx, "eslint")) avoids adding a separate root package.json and extra CI dependency install step — all repository JS tooling already installs via cmd/ui/package-lock.json — in fresh local worktrees without cmd/ui/node_modules installed, .githooks/pre-commit (fix mode) warns and skips check_nonui_js while --check fails until cd cmd/ui && npm ci --legacy-peer-deps is run, and non-UI JS remains coupled to the ESLint major version pinned in cmd/ui.
  • Scoping enforcement to the three-directory .js allowlist (.github/scripts/**/*.js, tools/nightly_tests/**/*.js, cmd/experiment_state_server/static/**/*.js), leaving tools/lint/eslint.nonui.config.mjs (.mjs) and other directories out of scope — those three roots contain all non-UI .js runtime scripts currently tracked in the repository — any new non-UI .js or .mjs scripts placed outside these paths will bypass ESLint until added to _NONUI_JS_GLOBS, _NONUI_JS_PATTERN, tools/lint/eslint.nonui.config.mjs, and .github/workflows/lint.yml.
  • Adopting complexity: 15 and max-lines-per-function: 80 (vs 10 and 35 in cmd/ui/eslint.config.js) and deferring Prettier formatting — existing .github/scripts/*.js modules exceed UI complexity/length limits and follow pre-existing formatting conventions, so enforcing UI thresholds or Prettier now would force broad refactoring and unrelated formatting churn — functions up to 80 lines / complexity 15 and minor formatting differences remain permitted until tightened in a follow-up PR.

Verification & Testing

  • Commands Executed:
    • node --test .github/scripts/*.test.js and node --test tools/nightly_tests/*_test.js
    • ./cmd/ui/node_modules/.bin/eslint --no-config-lookup -c tools/lint/eslint.nonui.config.mjs -- "${NONUI_JS_FILES[@]}" (27 files via git ls-files -z)
    • actionlint -shellcheck="$(command -v shellcheck)" .github/workflows/lint.yml
    • XMC_BYPASS_VENV=1 python3 ./tools/lint/check_file_naming.py and check_agent_doc_paths.py
    • bazel test --test_output=errors //tools/lint/...
    • .githooks/pre-commit on git commit and python3 ./tools/analyze_diff_size.py --base-ref origin/refactor/decompose-approval-scripts...origin/chore/lint-non-ui-js-scripts
  • Coverage & Test Status:
    • Non-UI JS ESLint passed across 27/27 tracked .js files (0 errors); Node tests passed (250/250 in .github/scripts/*.test.js, 11/11 in tools/nightly_tests/*_test.js).
    • actionlint, check_file_naming.py (2561 files), check_agent_doc_paths.py (27 docs), //tools/lint/... (11/11 Bazel targets), and .githooks/pre-commit (including 320/320 backend Bazel unit tests) all passed cleanly.

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 a pre-commit hook check and a new ESLint configuration to lint non-UI JavaScript files, alongside cleaning up unused imports in test files and adding explanatory comments to empty catch blocks. The review feedback suggests updating the file discovery patterns in the pre-commit hook to be recursive, ensuring that nested JavaScript files are correctly identified and linted.

Comment thread .githooks/pre-commit Resolved
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from dd811f7 to 39cf7c0 Compare November 12, 2026 22:51
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from 39cf7c0 to 628db1c Compare November 13, 2026 08:22
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from 628db1c to 70cc246 Compare November 13, 2026 09:19
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch 2 times, most recently from 00712a4 to c8b80b2 Compare November 13, 2026 10:56
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from c8b80b2 to c99000c Compare November 13, 2026 11:58
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch 2 times, most recently from aafa370 to ef8b0d6 Compare November 13, 2026 13:16
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch 2 times, most recently from a26deed to a846bbb Compare November 13, 2026 14:58
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch 2 times, most recently from aec67e9 to cf95620 Compare November 16, 2026 09:17
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from cf95620 to 7111850 Compare November 16, 2026 11:13
@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/lint-non-ui-js-scripts branch from 7111850 to 871ec8b Compare November 16, 2026 11:44
@VLukiantsev
VLukiantsev marked this pull request as ready for review November 16, 2026 19:21
@github-actions
github-actions Bot requested a review from AntonTyb November 16, 2026 19:21
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from 8dfa8b1 to 7d2f2ad Compare November 16, 2026 19:54
@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 introduces a new ESLint configuration (eslint.nonui.config.mjs) and integrates a non-UI JavaScript linter check into the pre-commit runner (precommit_runner.py), along with corresponding unit tests. It also cleans up unused imports and adds comments to empty catch blocks in existing scripts to comply with the new linting rules. The review feedback recommends enhancing the new linter check by conditionally passing the --fix flag when the pre-commit runner is executed in fix mode, and updating the unit tests to verify this behavior.

Comment thread tools/lint/precommit_runner.py Resolved
Comment thread tools/lint/precommit_runner_test.py Resolved
VLukiantsev added a commit that referenced this pull request Nov 16, 2026
…mand

Address PR #1668 review feedback (`4590812023`, `4590812041`) by delegating `check_nonui_js` execution and 500-file batching to `gates.run_mode_command` with `fix_args=["--fix"]` and asserting both `fix` and `check` CLI flags in `precommit_runner_test.py`.

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
Comment thread .github/workflows/lint.yml Resolved
Comment thread .github/scripts/git-range-diff.js Resolved
Comment thread .github/scripts/range-diff-parser.js Resolved
Comment thread tools/lint/eslint.nonui.config.mjs Resolved
Comment thread tools/lint/precommit_runner_test.py Resolved
Comment thread tools/lint/precommit_runner.py Resolved
Comment thread tools/lint/precommit_runner.py Resolved
VLukiantsev added a commit that referenced this pull request Nov 17, 2026
…mand

Address PR #1668 review feedback (`4590812023`, `4590812041`) by delegating `check_nonui_js` execution and 500-file batching to `gates.run_mode_command` with `fix_args=["--fix"]` and asserting both `fix` and `check` CLI flags in `precommit_runner_test.py`.

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
VLukiantsev added a commit that referenced this pull request Nov 17, 2026
…ty, tests, and docs

- Align `.github/workflows/lint.yml` `nonui_js` filter and `Run ESLint on Non-UI JS Scripts` step with recursive `**/*.js` discovery via `git ls-files -z` and `workflow_dispatch` guards.
- Remove the misleading `try / catch (_)` in `getPrChangedFiles` (`.github/scripts/git-range-diff.js`), normalize `ignoreExitCode: false` for `git diff` calls, and add unit tests in `git-range-diff.test.js`.
- Bound `commitMatch` leading indentation to `^ {0,3}` in `.github/scripts/range-diff-parser.js` so code context and commit message lines cannot forge commit-pair headers, with regression tests in `range-diff-parser.test.js`.
- Hoist `max-lines-per-function` into `BASE_RULES` and move `**/*.test.js` / `**/*_test.js` overrides to the end of `tools/lint/eslint.nonui.config.mjs`.
- Strengthen `tools/lint/precommit_runner_test.py` (`test_check_nonui_js` and `test_check_nonui_js_skips_and_missing_binary`) to exercise `not files`, missing `eslint` in `check` vs `fix` modes, `staged_paths_match` config trigger, and filtered `exec_cmd` args/`cwd`.
- Synchronize non-UI JS ESLint documentation in `docs/developer.md`, `tools/README.md`, and `.agents/rules/rule_authoring_standards.md`.

Comment links:
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from addfc98 to affa7bb Compare November 17, 2026 11:34
- Adds `tools/lint/eslint.nonui.config.mjs` and enables non-UI JS linting across `.github/scripts`, `tools/nightly_tests`, and `cmd/experiment_state_server/static` in CI and `tools/lint/precommit_runner.py`.
- Uses recursive `:(glob).../**/*.js` pathspecs so top-level and nested non-UI JS files are covered, with unit tests in `tools/lint/precommit_runner_test.py`.

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
Restore `import re` in `tools/lint/precommit_runner.py` after PR #1666 migrated `check_shell` to `str.endswith`, resolving `NameError` in `check_nonui_js`.

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

Address PR #1668 review feedback (`4590812023`, `4590812041`) by delegating `check_nonui_js` execution and 500-file batching to `gates.run_mode_command` with `fix_args=["--fix"]` and asserting both `fix` and `check` CLI flags in `precommit_runner_test.py`.

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
…ty, tests, and docs

- Align `.github/workflows/lint.yml` `nonui_js` filter and `Run ESLint on Non-UI JS Scripts` step with recursive `**/*.js` discovery via `git ls-files -z` and `workflow_dispatch` guards.
- Remove the misleading `try / catch (_)` in `getPrChangedFiles` (`.github/scripts/git-range-diff.js`), normalize `ignoreExitCode: false` for `git diff` calls, and add unit tests in `git-range-diff.test.js`.
- Bound `commitMatch` leading indentation to `^ {0,3}` in `.github/scripts/range-diff-parser.js` so code context and commit message lines cannot forge commit-pair headers, with regression tests in `range-diff-parser.test.js`.
- Hoist `max-lines-per-function` into `BASE_RULES` and move `**/*.test.js` / `**/*_test.js` overrides to the end of `tools/lint/eslint.nonui.config.mjs`.
- Strengthen `tools/lint/precommit_runner_test.py` (`test_check_nonui_js` and `test_check_nonui_js_skips_and_missing_binary`) to exercise `not files`, missing `eslint` in `check` vs `fix` modes, `staged_paths_match` config trigger, and filtered `exec_cmd` args/`cwd`.
- Synchronize non-UI JS ESLint documentation in `docs/developer.md`, `tools/README.md`, and `.agents/rules/rule_authoring_standards.md`.

Comment links:
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)
- #1668 (comment)

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
@VLukiantsev
VLukiantsev force-pushed the chore/lint-non-ui-js-scripts branch from affa7bb to bcf68b4 Compare November 17, 2026 11:58
@VLukiantsev
VLukiantsev requested a review from AntonTyb November 17, 2026 12:55
Comment thread .github/scripts/git-range-diff.js Resolved
Comment thread .github/workflows/lint.yml Resolved
Comment thread .github/scripts/git-range-diff.test.js Resolved
…in lint

- Pass `--no-renames` to all three `git diff --name-only` calls (3-dot PR diff, ancestor follow-up diff, and 2-dot fallback diff) in `.github/scripts/git-range-diff.js` so pure `git mv` renames out of protected paths still emit the protected source path and trigger `PROTECTED_FILES_MODIFIED` lockout.
- Update positional `git diff` mock assertions in `.github/scripts/git-range-diff.test.js` and `.github/scripts/approval-policy.test.js`, add regression tests for `--no-renames` across all three call forms and moved protected files, and align `.github/scripts/README.md`.
- Add `wait "$!"` after `mapfile -d '' -t NONUI_JS_FILES < <(...)` in `.github/workflows/lint.yml` so a non-zero `git ls-files` exit code fails the CI step closed.

Comment link: #1668 (comment)
Comment link: #1668 (comment)

TAG=agy
CONV=ba8411ef-c093-4f45-950a-b3bc1899268c
@VLukiantsev
VLukiantsev requested a review from AntonTyb November 17, 2026 14:21

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.

2 participants