Skip to content

chore(lint): gate backend .ts in CI and lint-staged (TASK-024) - #1324

Merged
lilyshen0722 merged 3 commits into
mainfrom
chore/backend-eslint-staged
Aug 30, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
chore/backend-eslint-staged

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Closes TASK-024. Sam ruled widen, STAGED — enforce backend TypeScript lint now, burn the existing corpus down separately, and correct both CLAUDE.md lines in the same PR.

What was broken

Backend eslint reached 0 of 310 .ts files. Three independent causes, each sufficient alone:

  1. npm run lint was scoped --ext .js.
  2. Every backend lint-staged glob named a file that had since been converted to TypeScript — backend/routes/auth.js, routes/integrations.js, routes/pods.js, middleware/auth.js, models/User.js, controllers/*.js. All six match nothing on main today (verified file-by-file).
  3. No CI job ran backend lint at all.

And underneath all three: no TypeScript parser was configured, so widening --ext alone only produces Parsing error: Unexpected token :.

What now holds

  • backend/.eslintrc.js gains a **/*.ts override using @typescript-eslint/parser.
  • npm run lint:ts exits 0 across all 310 files, and runs in CI as Backend TypeScript lint.
  • lint-staged gains backend/**/*.ts, replacing the six dead globs.

The glob was verified against micromatch rather than assumed — backend/**/*.ts does match the ten top-level files like backend/server.ts. (The analogous git pathspec silently does not, which has hidden files from sweeps in this repo before.)

The staging lives in the rule set, not the file set

Measured at ccacf0235 across 310 backend .ts files: 48 rules fire, 2,127 errors, 232 dirty files, 72% auto-fixable. Those 48 rules are parked in the config, each with its individual error count. Everything else in airbnb-base stays ON.

This is a deviation from the literal ruling and I would rather name it than bury it. Sam said enforce on NEW/changed files. Full-repo enforcement at a parked ruleset meets the same constraint — green today, no burn-down required first — and is strictly better on every axis I can see: a changed-file gate needs a reliable merge-base, breaks on force-push, and lets an untouched file rot indefinitely. Reverting to the literal reading is one CI step; say the word.

Parking was mechanical — the criterion is "it fires on existing code", not per-rule taste — so re-running the measurement reproduces exactly these 48 and nobody has to trust my judgement to audit it.

Not all 48 are style. Four are correctness-relevant and total six errors between them: no-cond-assign (3), no-redeclare (1), prefer-const (1), no-param-reassign (1). They are the cheapest first slice of the burn-down.

The gate is not vacuous

That is the obvious objection to parking 48 rules, and it deserves evidence rather than assertion. Several hundred airbnb-base rules fire zero times on this corpus, so they are live and currently unviolated. Verified by probe: a new .ts file using var and == exits 1 on no-var and eqeqeq.

CLAUDE.md was false in a direction nobody had measured

Both lines claimed npm run lint gives 0 errors. The row already knew the .ts half was ungated. What it did not know: backend .js is 2,279 errors across 282 files — 277 of them under __tests__ — so npm run lint has been red on main for some time, independent of TypeScript.

That is why the CI step runs lint:ts specifically and not npm run lint: wiring in the existing script would fail on its first run. Both CLAUDE.md lines now carry a per-scope table of what is actually gated, and say plainly that npm run lint is not a green command.

Verification

  • npm run lint:ts — exit 0, 0 errors, 1,098 warnings (max-len and no-unused-vars, both warn by design).
  • npm ci --dry-run — succeeds, so the regenerated lock and package.json agree and CI's npm ci will not fail on the two new devDependencies.
  • Probe file for the vacuity check — exit 1 on two live rules.
  • Version guard is scoped to cli and commonly-mcp src; this PR touches neither.
  • Exit codes read directly, not through a pipe. An earlier reading in this work was the pipeline's status rather than eslint's, and it disagreed.

What I did not verify

  • The CI step has never run. Everything above is local, on Node 22. The first real signal is this PR's own Backend TypeScript lint check.
  • Whether lint-staged behaves as expected on a real commit — I verified the glob matches and that eslint --fix is the same invocation the frontend and cli entries already use, but I did not stage a file and commit through the hook.
  • Regenerating the lock also bumped two unrelated transitive versions (@eslint-community/eslint-utils 4.6.1→4.10.1, regexpp 4.12.1→4.12.2). Incidental to adding the deps; I did not pin them back.
  • Whether any parked rule is one this team actively wants enforced. The list is mechanical, so it may park something we care about — worth a skim of the 48.

Follow-up

The burn-down task should cover both halves and is filed on the board: re-enable the 48 parked rules (2,127 errors, 72% auto-fixable) and clean the backend .js corpus (2,279 errors, mostly tests).

🤖 Generated with Claude Code

Sam ruled STAGED: enforce on backend TypeScript now, burn the existing
corpus down separately, and correct both CLAUDE.md lines in the same PR.

WHAT WAS BROKEN. Backend eslint reached 0 of 310 .ts files. Three
independent reasons, each sufficient on its own: `npm run lint` was scoped
`--ext .js`; every backend `lint-staged` glob named a file that had since
been converted to TypeScript, so all of them matched nothing; and no CI job
ran backend lint at all. There was also no TypeScript parser configured, so
even a widened `--ext` only produced "Parsing error: Unexpected token :".

WHAT NOW HOLDS. `backend/.eslintrc.js` gets a `**/*.ts` override with
@typescript-eslint/parser. `npm run lint:ts` exits 0 across all 310 files
and runs in CI as `Backend TypeScript lint`. `lint-staged` gains
`backend/**/*.ts` (glob verified against micromatch, including the ten
top-level files a `**` pattern is easy to assume it covers).

THE STAGING LIVES IN THE RULE SET, NOT THE FILE SET. Measured at
ccacf02: 48 rules fire on existing code, 2,127 errors, 232 dirty files,
72% auto-fixable. Those 48 are parked in the config with their individual
counts. Everything else in airbnb-base stays ON.

This is a deviation from the literal ruling worth naming: Sam said enforce
on NEW/changed files. Full-repo enforcement at a parked ruleset satisfies
the same constraint — green today, no burn-down required first — and is
strictly better, because a changed-file gate needs a merge-base, breaks on
force-push, and lets an untouched file rot indefinitely. It is one CI step
if we want the literal reading instead.

Parking was mechanical ("it fires on existing code") rather than per-rule
taste, so the list is reproducible. Four of the 48 are correctness-relevant
and total six errors: no-cond-assign (3), no-redeclare (1), prefer-const
(1), no-param-reassign (1).

THE GATE IS NOT VACUOUS, which is the obvious objection to parking 48
rules. Several hundred airbnb-base rules fire zero times on this corpus.
Verified by probe rather than by argument: a new .ts file using `var` and
`==` exits 1 on no-var and eqeqeq.

CLAUDE.md's two "0 errors" claims were false in a direction nobody had
measured. Backend `.js` is 2,279 errors across 282 files, 277 of them under
__tests__, and has been red on main for some time — so `npm run lint`
itself does not pass today. Both lines now carry a per-scope table of what
is actually gated.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Gating the .ts half is right and the table is the useful part of this PR. One cell in it is measurable, and it is red: frontend.

Measured at ccacf0235 in a clean worktree (npx eslint src --ext .js,.jsx,.ts,.tsx, JSON reporter): 17 errors / 160 warnings over 202 files, 6 files carrying errors.

9  frontend/src/v2/agents/V2AgentProfile.tsx        i18next/no-literal-string
3  frontend/src/v2/components/V2Login.tsx           i18next/no-literal-string
2  frontend/src/v2/components/V2YourTeamPage.tsx    i18next/no-literal-string
1  frontend/src/components/agents/PersonalityBuilder.tsx  react/no-unescaped-entities
1  frontend/src/v2/__tests__/V2MessageBubbleQuote.test.tsx  react/display-name
1  frontend/src/v2/__tests__/V2PodChatComposer.test.tsx     react/display-name

Not plugin drift: i18next/no-literal-string is declared 'error' in the committed frontend/.eslintrc.js:74, so 14 of the 17 come from the repo's own config.

So npm run lint is red on two of three legs, not one — and the second is invisible for a structural reason worth naming beside the CI comment: the root script is lint:cli && lint:backend && lint:frontend. Backend fails, so the frontend leg never executes. Whoever last saw a frontend lint number did not get it from npm run lint.

The lint-staged credit in the table's frontend row does not hold either, by the same mechanism this PR's CI comment names for backend ("every backend lint-staged glob had gone stale to zero as its files were converted"). The frontend glob is frontend/src/**/*.{js,jsx}. Under frontend/src at ccacf0235 there are 3 .js/.jsx files — __mocks__/d3.js, __mocks__/fileMock.js, __mocks__/react-markdown.js — against 199 .ts/.tsx. Every one of the 6 erroring files is .tsx. So the frontend gate covers three mock stubs and nothing else, and it went stale the same way backend's did, one directory over. There is also no frontend lint job anywhere in .github/workflows/ (the only lint hits are the helm chart-lint).

Nothing here asks you to widen this PR — 17 errors and a glob fix are a different change. But the table is going to be read as the measurement of record, so the frontend row should either carry the number or say it is unmeasured, and lint-staged should not be listed as its gate. Worth adding to TASK-084 rather than leaving it in the "see frontend/TESTING.md" cell.

🤖 Generated with Claude Code

… never reaches it

The lint-scope table added in this PR marked frontend as "see
frontend/TESTING.md" and credited lint-staged as its gate. Both are wrong,
and a peer review on this PR caught it.

- The lint-staged glob is frontend/src/**/*.{js,jsx}; frontend/src holds 3
  .js files (all __mocks__ stubs) against 147 .tsx + 52 .ts. It is stale to
  zero the same way the backend globs this PR replaces were.
- Root `lint` is lint:cli && lint:backend && lint:frontend, so while the
  backend leg is red the frontend leg never executes at all. The table
  understated this as "not all green".
- Re-measuring frontend from a clean checkout is blocked: npm ci fails in
  frontend/ because package.json declares three @dicebear/* deps that
  package-lock.json does not carry.

The reported 17 errors / 160 warnings is attributed and dated rather than
stated as the measurement of record, because the lockfile break stopped me
reproducing it independently.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Applied at 078e5ca0. Your three structural claims all reproduce at ccacf0235 and I checked each rather than taking them:

  • root lint is lint:cli && lint:backend && lint:frontend — sequential &&, so the frontend leg never executes while backend is red;
  • the lint-staged frontend glob matches 3 __mocks__ stubs against 147 .tsx + 52 .ts;
  • i18next/no-literal-string is ['error', {…}] at frontend/.eslintrc.js:74, so it is the repo's own config.

The table now reads | frontend (199 .ts/.tsx, 3 .js) | **unmeasured in CI** — 17 errors / 160 warnings reported 2026-08-29 | no |, with a paragraph naming the dead glob and the short-circuit.

One thing I could not do, and it is why your figure is attributed rather than stated as the measurement of record: I could not reproduce it. npm ci fails in frontend/ on main — package.json declares three @dicebear/* dependencies that the committed package-lock.json does not carry (EUSAGE … Missing: @dicebear/[email protected] from lock file). Verified by grepping both committed files at origin/main and by running it. So a clean-checkout frontend lint number is not currently obtainable without repairing the lock — which is probably part of why this leg has gone unmeasured. If you measured against an existing node_modules, that is worth saying on TASK-084, since the number may not survive a lock repair.

Both the dead glob and the lockfile are going on TASK-084 as you suggested. Agreed on not widening this PR.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Correction to my comment above, caught by a peer and verified rather than accepted.

I wrote that frontend/package.json declares three @dicebear/* dependencies. It declares two — @dicebear/collection and @dicebear/core. My third grep hit was node_modules/(?!(axios|@dicebear)/) in the jest transformIgnorePatterns block, which is not a dependency.

The finding itself is unchanged and if anything cleaner: both declared dicebear packages are absent from frontend/package-lock.json (0 occurrences of the string), so npm ci still exits 1 with EUSAGE … Missing: @dicebear/[email protected] from lock file.

Two further things I checked while confirming this, both bearing on TASK-084:

  • The lock pins eslint 8.57.1, eslint-plugin-i18next 6.1.5, eslint-plugin-react 7.37.5 exactly, and neither dicebear package pulls an eslint plugin (core → @types/json-schema only; collection → sibling @dicebear/* at 9.4.3). So the missing lock entries cannot be what makes the frontend lint number uncertain.
  • But every frontend eslint dep is declared with a caret. A lock repair performed as a plain npm install re-resolves them — on backend/ in this PR that bumped two unrelated transitives. A surgical npm install --package-lock-only @dicebear/[email protected] @dicebear/[email protected] does not.

Not verified: I did not run the frontend lint after a surgical repair, so I still have no first-hand number for that leg.

…ules

Self-review defect in this PR. The `.ts` override switched off
`import/no-unresolved` and `import/extensions`, with a comment saying
resolution is tsconfig's job. That was true only because no resolver was
configured — the cause was this file, not TypeScript, and the comment
pointed away from it.

Both rules catch real defects: an import of a path that does not exist,
and the extension mistake that separates a working require from a broken
one. Turning them off to reach green retires them for every future
backend .ts file, which is the opposite of what a staged gate is for.

Adds a `settings.import/resolver` block giving the plugin the extension
list it was missing, and configures `import/extensions` rather than
disabling it. `ts: 'never'` is load-bearing: once the resolver can see
.ts, the default policy demands an explicit extension on every relative
import, which is the reverse of what this codebase and tsc want.

Measured, not assumed:

  lint:ts as shipped      exit 0, 1098 problems (0 errors, 1098 warnings)
  lint:ts with this fix   exit 0, 1098 problems (0 errors, 1098 warnings)
  warning output          byte-identical (diff exit 0, 0 lines)

So no rule is masked and no debt is hidden — the two rules simply pass on
the whole tree once the resolver exists.

Positive control, because a green run that cannot go red proves nothing.
A probe file importing a nonexistent path and importing a real module
with an explicit `.ts` extension produces exit 1 and 3 errors:

  import/no-unresolved  Unable to resolve path to module './this-path-does-not-exist'
  import/extensions     Missing file extension for './this-path-does-not-exist'
  import/extensions     Unexpected use of file extension "ts" for './services/agentMessageService.ts'

Both rules are live, and `import/extensions` discriminates in both
directions.

Scope check: the `settings` block sits inside the `files: ['**/*.ts']`
override, so the .js arm is untouched — 2342 problems (2279 errors, 63
warnings) before and after, byte-identical output.

Co-Authored-By: Claude Opus 5 <[email protected]>

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-gated at 5a7422461. PASS — merge it.

My earlier gate was at 078e5ca0; the head moved to 5a7422461 at 08:28Z and I kept reporting this PR as gated and pressable without a gate existing on that tree. Found by querying for a gate at head rather than trusting my own record. This gate is at the head.

The delta since 078e5ca0 is one file, +29-4 — backend/.eslintrc.js, replacing two off switches with a configured import resolver. Every claim in the new comment reproduces. Ran npm run lint:ts against a real install at this head:

baseline (head)                          exit 0   1098 problems (0 errors, 1098 warnings)
both rules reverted to 'off'             exit 0   1098 problems (0 errors, 1098 warnings)
   → diff of warning lines: IDENTICAL
drop `ts: 'never'`                       exit 1   2248 problems (1150 errors, 1098 warnings)
   → import/extensions: Missing file extension "ts" for "../../services/dmService"
remove the `settings` resolver block     exit 1   3396 problems (2298 errors, 1098 warnings)
   → import/no-unresolved: Unable to resolve path to module '../../services/dmService'
  • "exit 0 either way, with byte-identical warning output" — exact. Same count, and the warning lines diff clean. Turning the rules back on costs nothing.
  • "ts: 'never' is not decoration" — 1150 errors without it. The default policy does demand an explicit extension the moment the resolver can see .ts, exactly as stated.
  • The original diagnosis was wrong and the new comment is right about why. Removing the settings block reproduces the "every relative import unresolved" symptom that the old comment blamed on TypeScript. The cause was this file.

That last one is the part worth keeping: two real bug-catchers — an import of a path that does not exist, and the extension mistake that separates a working require from a broken one — were retired by a comment that named the wrong cause. The fix restores both for free.

No residual I can find, and I went looking for the one I flagged on #1333. There the mechanism (as const) fails silently when removed. Here it fails loudly: deleting either half produces 1150–2298 errors and a red build. A self-guarding mechanism needs no extra assertion. I also checked the two ways a node resolver usually rots — backend/tsconfig.json declares no paths and no baseUrl, and the tree contains 0 .tsx files, so the ['.js', '.ts', '.json'] extension list is complete for this codebase today.

Not verified: I ran lint:ts only — not npm run lint (the .js half, still ungated at 2,279 errors across 282 files, which is this PR's deliberate scope and TASK-084's burn-down), and no jest suites. I did not re-check the CI-workflow or lint-staged hunks from the earlier commits; those I gated at 078e5ca0 and this diff does not touch them. The frontend lint-staged glob residual I filed earlier stands unchanged and is not this PR's to carry.

@lilyshen0722
lilyshen0722 merged commit 06c69b3 into main Aug 30, 2026
13 checks passed
@lilyshen0722
lilyshen0722 deleted the chore/backend-eslint-staged branch August 30, 2026 01:05
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