Repository navigation
chore: enforce eslint on non-ui js scripts - #1668
VLukiantsev wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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.
dd811f7 to
39cf7c0
Compare
39cf7c0 to
628db1c
Compare
628db1c to
70cc246
Compare
00712a4 to
c8b80b2
Compare
c8b80b2 to
c99000c
Compare
aafa370 to
ef8b0d6
Compare
a26deed to
a846bbb
Compare
aec67e9 to
cf95620
Compare
cf95620 to
7111850
Compare
7111850 to
871ec8b
Compare
8dfa8b1 to
7d2f2ad
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
…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
…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
addfc98 to
affa7bb
Compare
- 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
affa7bb to
bcf68b4
Compare
…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
Summary
Add
tools/lint/eslint.nonui.config.mjs(enforcingcomplexity: 15,max-lines-per-function: 80,no-empty,no-unused-vars,eqeqeq), wire ESLint for non-UI JS into.github/workflows/lint.ymlandtools/lint/precommit_runner.py(check_nonui_js), hardengit-range-diff.js/range-diff-parser.jsalongside unused test imports, and synchronize linter docs.Motivation & Context
Non-UI JavaScript scripts under
.github/scripts/,tools/nightly_tests/, andcmd/experiment_state_server/static/previously bypassed ESLint completely. Auditing the scripts under those rules also surfaced a fail-opencatch (_)ingetPrChangedFiles, missing--no-renamesflags ongit diff --name-onlycalls, and an unbounded leading-whitespace regex inparseRangeDiff.Key Changes
Modified/added 13 file(s) (
214prod,290test,8doc lines viatools/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-effortcatch (_)blocks, remove the unreachable/fail-opentry / catch (_)ingetPrChangedFiles, normalizeignoreExitCode: falseand pass'--no-renames'across all threegit diff --name-onlycalls (3-dot, follow-up, and2-dot), remove unused test imports, update positionalgit diffmock assertions, add fail-closed / unreachable-SHA / option-normalization /--no-renames/ moved-protected-file regression tests, and align theREADME.md3-dot diff snippet..github/scripts/range-diff-parser.js&.github/scripts/range-diff-parser.test.js: Addno-control-regexsuppression for ANSI stripping, boundcommitMatchleading spaces to^ {0,3}to prevent context/commit-message header forgery, and add regression tests..github/workflows/lint.yml: Add recursivenonui_jsdorny/paths-filterglobs (**/*.js),workflow_dispatchguards on Node setup/install/ESLint steps, andgit ls-files -zenumeration withwait "$!"fail-closed propagation for ESLint on non-UI JS.tools/lint/eslint.nonui.config.mjs: Add ESLint 10 flat config withmax-lines-per-functionhoisted intoBASE_RULESand**/*.test.js/**/*_test.jsoverrides ordered last.tools/lint/precommit_runner.py&tools/lint/precommit_runner_test.py: Addcheck_nonui_js()(:(glob)recursive discovery when--checkortools/lint/eslint.nonui.config.mjsis stagedACMR, else matching staged non-UI JS paths; reusesgates.resolve_ui_binary(ctx, "eslint")) and unit tests coveringnot files, missingeslint(checkvsfix), config trigger regex, and filteredexec_cmdargs/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
cmd/ui/node_modules/.bin/eslint(gates.resolve_ui_binary(ctx, "eslint")) avoids adding a separate rootpackage.jsonand extra CI dependency install step — all repository JS tooling already installs viacmd/ui/package-lock.json— in fresh local worktrees withoutcmd/ui/node_modulesinstalled,.githooks/pre-commit(fixmode) warns and skipscheck_nonui_jswhile--checkfails untilcd cmd/ui && npm ci --legacy-peer-depsis run, and non-UI JS remains coupled to the ESLint major version pinned incmd/ui..jsallowlist (.github/scripts/**/*.js,tools/nightly_tests/**/*.js,cmd/experiment_state_server/static/**/*.js), leavingtools/lint/eslint.nonui.config.mjs(.mjs) and other directories out of scope — those three roots contain all non-UI.jsruntime scripts currently tracked in the repository — any new non-UI.jsor.mjsscripts 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.complexity: 15andmax-lines-per-function: 80(vs10and35incmd/ui/eslint.config.js) and deferring Prettier formatting — existing.github/scripts/*.jsmodules 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
node --test .github/scripts/*.test.jsandnode --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[@]}"(27files viagit ls-files -z)actionlint -shellcheck="$(command -v shellcheck)" .github/workflows/lint.ymlXMC_BYPASS_VENV=1 python3 ./tools/lint/check_file_naming.pyandcheck_agent_doc_paths.pybazel test --test_output=errors //tools/lint/....githooks/pre-commitongit commitandpython3 ./tools/analyze_diff_size.py --base-ref origin/refactor/decompose-approval-scripts...origin/chore/lint-non-ui-js-scripts27/27tracked.jsfiles (0 errors); Node tests passed (250/250in.github/scripts/*.test.js,11/11intools/nightly_tests/*_test.js).actionlint,check_file_naming.py(2561files),check_agent_doc_paths.py(27docs),//tools/lint/...(11/11Bazel targets), and.githooks/pre-commit(including320/320backend 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