Skip to content

fix(lint): enable anti-slop/no-reflect-get - #20751

Closed
nwparker wants to merge 1 commit into
nwparker/2x-lintfrom
nwparker/anti-slop/no-reflect-get
Closed

nwparker wants to merge 1 commit into
nwparker/2x-lintfrom
nwparker/anti-slop/no-reflect-get

Conversation

@nwparker

@nwparker nwparker commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 51 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​157 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​50 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32

Stacked on #20726 (nwparker/2x-lint). Review only the top commit; base that PR first.

Flips anti-slop/no-reflect-get from off to error in config/oxlint-anti-slop.json and clears the repo to zero.

What the rule rejects, and why it matters

Every call to Reflect.get. The reflective read bypasses ordinary property access and throws away the type evidence the compiler would otherwise give you: the result is any/unknown with no narrowing, so a typo in the key or a shape drift in the source object is invisible until runtime. The remedy the rule pushes you toward is to narrow (or parse) dynamic input into a real type and then read the field normally, so the key is checked.

The one construct the rule cannot replace is a Proxy get trap's default forward — see Suppressions.

Violations fixed

86 at baseline across 67 files. 44 rewritten, 42 suppressed. Audit is now clean:

pnpm audit:anti-slop   # exit 0

Fix pattern

The dominant shape was an unknown read through Reflect.get right after a typeof === 'object' guard. Those became in-narrowed property access, which TypeScript actually checks:

-  const agents = detectedManagedHookAgents(Reflect.get(value, 'agents'))
-  const versions = Reflect.get(value, 'versions')
+  const agents = detectedManagedHookAgents('agents' in value ? value.agents : null)
+  const versions = 'versions' in value ? value.versions : null

Two further shapes:

  • Reflect.get(Object(x), 'k') on a possibly-primitive envelope became a small named reader that boxes once and indexes a Record<string, unknown> (settingsField in mobile/src/transport/settings-read-operations.ts).
  • Tests reaching into private state moved to TypeScript's checked bracket-index escape hatch (runtime['layoutQueues']), or to a documented read-only accessor on the owning class (SearchSubprocessLineAccumulator.retainedCapacityBytes(), CodexSubagentExecutions.retentionSizes()).

No type assertion was added anywhere. The diff contains zero net-new as casts, as any, as unknown as, @ts-ignore, or @ts-expect-error, so nothing was laundered into the sibling assertion rules to make this one go green.

Suppressions

42x // oxlint-disable-next-line anti-slop/no-reflect-get across 38 files. Every one is the default-forward branch of a Proxy get trap:

get(target, property, receiver) {
  ...
  return Reflect.get(target, property, receiver)
}

Reflect.get(target, property, receiver) is the only construct that forwards with correct receiver semantics. target[property] invokes an accessor with the wrong this and silently breaks getters that read sibling state through the proxy. There is no typed alternative, so these are suppressed rather than rewritten. "Zero violations" here means zero unsuppressed violations.

3x // oxlint-disable-next-line typescript-eslint/consistent-type-definitions -- declaration merging requires interface in tests/e2e/github-url-smart-input-transition.spec.ts, tests/e2e/linear-url-workspace-entry.spec.ts, tests/e2e/worktree-active-delete-scroll-position.spec.ts. Replacing Reflect.get(window, 'x') with typed window.x requires a declare global { interface Window } block, and interface is mandatory for declaration merging. Matches the existing convention at tests/e2e/helpers/runtime-types.ts:63. (The anti-slop audit config does not include that rule, so a clean audit hid a red main lint gate until the whole changed set was run under the main .oxlintrc.json.)

1x // eslint-disable-next-line no-var -- main-process gate handle for this spec in tests/e2e/project-group-creation-visibility.spec.ts, for the same typed-global reason. Matches tests/e2e/agent-session-log-tail-stability.spec.ts:24.

What a reviewer should scrutinise

  • undefined -> null swaps. Reflect.get(x, 'k') yields undefined for a missing key; the 'k' in x ? x.k : null rewrite yields null. Each site was checked against its consumer — all of them guard with Array.isArray/typeof/== null, so the swap is unobservable. Worth a second pair of eyes if you know a consumer that distinguishes the two.
  • Two proxy traps that dropped receiver (src/main/runtime/missing-worktree-terminal-reconciliation.ts:28, src/main/updater-test-harness.ts:150). Both target getter-free plain objects, so receiver was inert, but that is an invariant of the target, not of the trap.
  • typeof prop === 'string' && added before prop in namespace in useIpcEvents-zoom-routing.test.ts and useIpcEvents-rate-limit-hydration.test.ts. This is a real semantic narrowing: symbol-keyed lookups now land on the fallback path. It is unreachable here (every makeEvents() target is an {}-rooted object literal with no own symbol keys, and Object.prototype carries no Symbol.iterator/toPrimitive/toStringTag), but it is a narrowing.
  • Two public accessors added to production classes purely for test observation (CodexSubagentExecutions.retentionSizes(), SearchSubprocessLineAccumulator.retainedCapacityBytes()). Both read-only and documented, but they do widen API surface where three sibling sites in this same diff instead used bracket access. Say the word and they become bracket access too.
  • mobile/src/test-support/rpc-recording/ mutation anchors. That harness pins the exact source text of a line in settings-read-operations.ts and hard-fails with Mutant anchor matched 0 sites, expected 1 if the text drifts. Two anchors had to move with the rewrite: the bot-overrides-envelope entry in operation-mutations.ts and the synthetic-duplicate fixture in recording-runner.test.ts.

How this was verified

Ran and green:

  • pnpm audit:anti-slop — exit 0. Confirmed the rule is genuinely firing (not silently disabled) by planting a Reflect.get probe, seeing it reported, and removing it.
  • oxlint under the main .oxlintrc.json on all 68 changed files — exit 0. The pre-commit hook re-ran oxlint, oxlint --config config/oxlint-react-doctor.json, and oxfmt --write over the staged set.
  • node config/scripts/run-typecheck-projects-in-parallel.mjs — exit 0, before and after the rebase onto the corrected base.
  • Vitest over 57 files: every changed test file, plus the test files covering each changed non-test source (and orca-runtime.test.ts, which is the entry point for the changed orca-runtime-tests/terminal-listing.spec.ts helper). 1,839 tests passed, 3 skipped, 0 failed.
  • Statically validated all 9 mutation anchors in operation-mutations.ts: each resolves to a file that contains its before text exactly once.
  • No files added: git diff --name-only <base> --diff-filter=A is empty; no .js, .d.ts, or .tsbuildinfo anywhere in the diff; working tree clean.

Could not verify:

  • mobile/ is a separate pnpm workspace and its dependencies are not installed in this worktree (mobile/node_modules is empty; vitest fails at Cannot find module 'expo/tsconfig.base.json'). So mobile's tests and tsc --noEmit never ran, and the root typecheck script does not cover mobile. The three mobile files in this diff were verified by lint (oxlint under mobile/.oxlintrc), by oxfmt, and by the static anchor check above — not by execution. Mobile CI is the gate here.
  • tests/e2e/*.spec.ts are Playwright specs and were not executed. They were typechecked and linted. Note tsc -p config/tsconfig.e2e.json has 219 pre-existing errors on this branch; none are in the four spec files touched here.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — flipped anti-slop/no-reflect-get to error and cleared the repo to zero unsuppressed violations across 68 files.

  • Rule enablement — config/oxlint-anti-slop.json now sets anti-slop/no-reflect-get to error; the audit config is a leaf of the root pnpm lint chain and includes mobile.
  • in-narrowed property reads — Reflect.get(x, k) became 'k' in x ? x.k : null in managed-hook-detection-commands.ts, daemon-client-rpc-request.ts, managed-hook-installer.ts, worktree-name-retirement.ts, versioned-agent-session-wire.ts, and the e2e specs.
  • Named reader / accessor / bracket rewrites — settingsField boxing helper in mobile/.../settings-read-operations.ts; readRecordString reuse in codex-prompt-registry.ts; new CodexSubagentExecutions.retentionSizes() and SearchSubprocessLineAccumulator.retainedCapacityBytes(); bracket access for private class fields in tests.
  • Suppressions — 42 Proxy get-trap default forwards (the only construct that forwards correct receiver semantics), plus consistent-type-definitions/no-var disables for the e2e Window declaration-merge blocks.

I verified the author's flagged items rather than taking them on faith: every Reflect.get( under src config tests mobile is rewritten or has a suppression on the preceding line; the undefined→null swap is unobservable at each consumer (Array.isArray/typeof/== null); the typeof prop === 'string' narrowing in the useIpcEvents proxies only affects unreachable symbol keys; the two dropped-receiver traps target getter-free objects; and the mobile mutation anchor still resolves exactly once. Locally I got audit:anti-slop → 0 errors, root oxlint over all 68 changed files → 0, tc:node/tc:web → 0, and the changed tests green via pnpm test.

Note the author-documented gap stands: mobile/ tests and tsc were not executable in this worktree, so mobile CI is the real gate for those three files.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/anti-slop/no-reflect-get branch from 633f3e0 to 9860077 Compare September 15, 2026 03:51
@nwparker
nwparker force-pushed the nwparker/anti-slop/no-reflect-get branch from 9860077 to 885f2d0 Compare September 15, 2026 03:57

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The pinned anti-slop plugin is provisioned by postinstall, but the repo's CI install action runs pnpm install --ignore-scripts, and .github/workflows/pr.yml has no audit:anti-slop step. The pnpm lint parity test fails on this branch (reproduced locally) and adding the step alone would still fail the plugin load — so the rule this PR enables is not actually gated on PRs.

Reviewed changes — re-reviewed the delta since the prior Pullfrog review. The branch was rebased so the anti-slop machinery now matches the (stacked) base: the plugin moved from vendored source to a SHA-pinned dependency plus a generated copy step, while the no-reflect-get commit content is unchanged.

  • Pinned dependency instead of vendoring — oxlint-plugin-anti-slop is now github:dmmulroy/anti-slop#c44ef22; config/scripts/sync-anti-slop-plugin.mjs, run from postinstall, copies its source to the gitignored .anti-slop-plugin/, and config/oxlint-anti-slop.json loads ../.anti-slop-plugin/index.ts.
  • Deslop rules dropped — no-call-only-assertions and no-pass-through-type-alias are removed from the config.
  • Ignore plumbing retargeted — .oxfmtrc.json ignores .anti-slop-plugin/**, and audit:anti-slop drops its --ignore-pattern because the generated directory sits outside the linted paths.

I verified the rule still loads and fires after the sync (pnpm run audit:anti-slop → 0 errors, 1 rules), and that with .anti-slop-plugin/ removed oxlint hard-fails with Failed to load JS plugin: ../.anti-slop-plugin/index.ts.

⚠️ The anti-slop gate cannot run under the repo's script-free CI install

pnpm lint now lists audit:anti-slop, and config/scripts/pr-workflow-lint-parity.test.mjs enforces that .github/workflows/pr.yml mirrors every lint step. That test fails on this branch: pr.yml has no audit:anti-slop step. Even after adding one, the command would fail to load the plugin, because the pinned source is a postinstall-generated artifact and the CI install action deliberately runs --ignore-scripts.

Technical details
# Pinned plugin is absent under the repo's script-free CI install

## Affected sites
- `package.json:166` — `audit:anti-slop` loads `../.anti-slop-plugin/index.ts`, which only exists after the sync script runs.
- `package.json:98` — `postinstall` chains `sync-anti-slop-plugin.mjs`; skipped by `--ignore-scripts`.
- `.github/actions/install-node-dependencies/action.yml:93` — `pnpm install --frozen-lockfile --ignore-scripts`, used by every `pr.yml` job.
- `.github/workflows/pr.yml` — no `audit:anti-slop` step (`pnpm exec oxlint --format github` at line 134 is the root config, which does not load anti-slop).
- `config/scripts/pr-workflow-lint-parity.test.mjs:84` — fails with `.github/workflows/pr.yml is missing lint steps: oxlint --config config/oxlint-anti-slop.json src config tests mobile --deny-warnings`.

## Required outcome
- `config/scripts/pr-workflow-lint-parity.test.mjs` passes (the missing step is added to `pr.yml`).
- The generated plugin directory exists in the job that runs the audit despite the script-free install.

## Suggested approach
Add a `pnpm run sync:anti-slop-plugin` step (or another bootstrap) before an added `pnpm run audit:anti-slop` step in the `static analysis` job.

## Open questions for the human
These files are identical on the stacked base (`nwparker/2x-lint`), which lacks the `pr.yml` step too — is the fix intended to land in #20726? Confirming the landing PR avoids a duplicate fix.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/anti-slop/no-reflect-get branch from 885f2d0 to 6556ff1 Compare September 15, 2026 04:24

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The top commit is a clean rebase with the same rewrite set as before, but the stacked base (#20726) now chains sync-anti-slop-plugin.mjs onto postinstall, and that breaks config/scripts/package-electron-runtime-contract.test.mjs, which the sharded unit job in this PR's test run collects.

Reviewed changes — re-reviewed the delta since the prior Pullfrog review: the no-reflect-get commit was rebased onto an updated nwparker/2x-lint, moving the anti-slop provisioning machinery onto the base and resolving the prior CI-gating concern.

  • Rebased onto the updated stack base — the plugin pin, config/scripts/sync-anti-slop-plugin.mjs, the .gitignore/.oxfmtrc.json entries, the package.json scripts, and the pr.yml step are now base-owned and no longer part of this diff, leaving the rule flip plus the unchanged 68-file rewrite/suppression set.
  • Resolved the prior CI-provisioning concern in the base — audit:anti-slop now runs the sync itself (node config/scripts/sync-anti-slop-plugin.mjs && oxlint ...) and pr.yml:137 runs it, so the gate provisions its plugin despite pnpm install --ignore-scripts. Verified locally: pnpm run audit:anti-slop → 0 warnings, 0 errors, 1 rules.
  • Introduced a base-side unit-test failure — chaining the sync onto postinstall no longer matches the exact string pinned by the Electron-runtime contract test (details below).

⚠️ The base's chained postinstall fails the Electron-runtime contract test

postinstall is now node config/scripts/rebuild-native-deps.mjs && node config/scripts/sync-anti-slop-plugin.mjs, but config/scripts/package-electron-runtime-contract.test.mjs:28 asserts postinstall equals the exact pre-chain string node config/scripts/rebuild-native-deps.mjs. The test job in pr.yml calls the sharded unit-tests.yml, whose run includes config/scripts/**/*.test.mjs, so this is a red unit test on the branch this PR merges into. The chain is also redundant: audit:anti-slop is the only consumer of config/oxlint-anti-slop.json and already syncs the plugin itself, so dropping it restores the assertion without weakening the gate.

Technical details
# Chained postinstall breaks the pinned postinstall contract

## Affected sites
- `package.json:100` — `postinstall` is `node config/scripts/rebuild-native-deps.mjs && node config/scripts/sync-anti-slop-plugin.mjs`.
- `config/scripts/package-electron-runtime-contract.test.mjs:28` — `expect(packageJson.scripts.postinstall).toBe('node config/scripts/rebuild-native-deps.mjs')` fails: received `... && node config/scripts/sync-anti-slop-plugin.mjs`.
- `.github/workflows/pr.yml:622` — the `test` job calls `unit-tests.yml`, whose run collects `config/scripts/**/*.test.mjs` (`config/vitest.config.ts:34`), so this fails PR CI.
- `package.json:168` — `audit:anti-slop` already runs `sync-anti-slop-plugin.mjs` before oxlint.

## Required outcome
- `config/scripts/package-electron-runtime-contract.test.mjs` passes on the branch this PR merges into, and the anti-slop gate still provisions its generated plugin.

## Suggested approach
Remove the `sync-anti-slop-plugin.mjs` chain from `postinstall` — the only consumer, `audit:anti-slop`, self-syncs — or relax the assertion to a prefix check. `package.json` is base-owned (#20726), so the fix belongs there.

## Open questions for the human
Was chaining the sync onto `postinstall` intentional (e.g. for editor-time linting), or can it be dropped now that `audit:anti-slop` self-provisions?

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

`anti-slop/no-reflect-get` rejects every call to `Reflect.get`. The
reflective read bypasses ordinary property access and throws away the
type evidence the compiler would otherwise give you: the result is
`any`/`unknown` with no narrowing, so a typo in the key or a shape drift
in the source object is invisible until runtime. The rule's remedy is to
parse dynamic input into a named domain type (or narrow it with `in`)
and then read the field normally.

Baseline: 86 violations across 67 files. Now zero unsuppressed
violations under
`npx oxlint --config config/oxlint-anti-slop.json --ignore-pattern 'config/oxlint-plugins/anti-slop/**' src config tests mobile`.

Fix pattern
-----------
44 of the 86 were rewritten. The dominant shape was an `unknown` value
read through `Reflect.get` right after a `typeof === 'object'` guard;
those became `in`-narrowed property access, which TypeScript checks:

  - Reflect.get(value, 'agents')
  + 'agents' in value ? value.agents : null

Two further shapes:
- `Reflect.get(Object(x), 'k')` on a possibly-primitive envelope became a
  small named reader that boxes once and indexes a
  `Record<string, unknown>` (`settingsField` in
  mobile/src/transport/settings-read-operations.ts).
- Tests reaching into private state moved to TypeScript's checked
  bracket-index escape hatch (`runtime['layoutQueues']`), or to a
  documented read-only accessor on the owning class
  (`SearchSubprocessLineAccumulator.retainedCapacityBytes()`,
  `CodexSubagentExecutions.retentionSizes()`).

No type assertion was added anywhere: the diff contains zero net-new
`as` casts, `as any`, `as unknown as`, `@ts-ignore`, or
`@ts-expect-error`, so nothing was laundered into the sibling
assertion rules.

Suppressions
------------
42x `// oxlint-disable-next-line anti-slop/no-reflect-get` across 38
files. Every one is the default-forward branch of a `Proxy` `get` trap:

    get(target, property, receiver) {
      ...
      return Reflect.get(target, property, receiver)
    }

`Reflect.get(target, property, receiver)` is the only construct that
forwards with correct `receiver` semantics; `target[property]` invokes
an accessor with the wrong `this` and silently breaks getters that read
sibling state. There is no typed alternative, so these are suppressed
rather than rewritten.

3x `// oxlint-disable-next-line typescript-eslint/consistent-type-definitions
-- declaration merging requires interface` in
tests/e2e/github-url-smart-input-transition.spec.ts,
tests/e2e/linear-url-workspace-entry.spec.ts, and
tests/e2e/worktree-active-delete-scroll-position.spec.ts. Replacing
`Reflect.get(window, 'x')` with typed `window.x` requires a
`declare global { interface Window }` block, and `interface` is
mandatory for declaration merging. Matches the existing convention at
tests/e2e/helpers/runtime-types.ts:63.

1x `// eslint-disable-next-line no-var -- main-process gate handle for
this spec` in tests/e2e/project-group-creation-visibility.spec.ts, for
the same reason a `var` global is needed to type the handle. Matches
tests/e2e/agent-session-log-tail-stability.spec.ts:24.

Also updates two source-text anchors in mobile's rpc-recording mutation
harness (mobile/src/test-support/rpc-recording/operation-mutations.ts
and recording-runner.test.ts), which pin the exact text of the rewritten
line in settings-read-operations.ts and would otherwise fail with
"Mutant anchor matched 0 sites, expected 1".
@nwparker
nwparker force-pushed the nwparker/anti-slop/no-reflect-get branch from 6556ff1 to e37b93a Compare September 15, 2026 04:38
@nwparker
nwparker deleted the branch nwparker/2x-lint September 15, 2026 04:42
@nwparker nwparker closed this Sep 15, 2026
@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by #20786 — GitHub auto-closed this when the base branch nwparker/2x-lint was deleted on merge of #20726, and refuses to reopen a force-pushed branch. Same commit, now targeting main.

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