Skip to content

chore(lint): unmask no-unsafe-dictionary-type behind effect's Record - #287

Merged
thomasfosterau merged 2 commits into
trunkfrom
issue-275-masked-dictionary-lint
Oct 8, 2026
Merged

thomasfosterau merged 2 commits into
trunkfrom
issue-275-masked-dictionary-lint

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #275.

effect(no-unsafe-dictionary-type) treats Record<K, V> as the built-in only while no local binding is named Record (isBuiltIn → hasVisibleTypeBinding in the plugin's internal/anti-slop/dictionary-types.ts). import { Record } from "effect" creates that binding, so every such site in the file disappears. effect(no-known-value-widening) goes through the same isBuiltIn check and has the same blind spot.

This PR:

  • Aliases every import of effect's Record as Rec. In src/: Query.ts, Handlers.ts, Middleware.ts, internal/codecs.ts and internal/filter.ts. In tests: internal/codecs.test.ts, plus Assemble.test.ts and Handlers.test.ts, which used R. With trunk's internal/schemaExt.ts, the repository now has one spelling. R is ruled out because it is the resource type parameter in many files: 51 places in Query.ts, for example, and Handlers.ts too. No file in src/, test/, examples/ or scripts/ still binds effect's Record as Record, whether through a named import, a multi-line named import or import * as Record.
  • Fixes the sites a small change can fix.
    • nest in codecs.ts is now generic over its leaf value type (<V>(flat: { readonly [key: string]: V }) => Record<string, V | Record<string, V>>). Call sites infer V.
    • Query.schema's filter decode splits the flat record with Rec.filter(flatValues, (_, key) => isFilterKey(key)) and its negation. Before, a loop filled two Record<string, unknown> locals. Rec.filter writes through effect's assignProperty, so a __proto__ key stays an own property, and the split cannot write through a prototype.
  • Documents the convention next to the rule's tier entry in vite.config.ts: never bind effect's Record module as Record, and spell the alias Rec everywhere.

Counts (vp lint --format json, per rule)

"True" is the count with every import of effect's Record in src/ and test/ temporarily aliased. On this branch there is nothing left to alias, so true equals visible.

no-unsafe-dictionary-type visible no-unsafe-dictionary-type true no-known-value-widening visible no-known-value-widening true all rules visible
trunk d8d9f18 87 95 63 68 4340
this PR 89 89 68 68 4348

On trunk, 8 sites of no-unsafe-dictionary-type were hidden:

  • 5 in codecs.ts: nest's return, nested, the group cast, flatten's return and flat;
  • 2 in Query.ts: others and filterKeys in the filter decode;
  • 1 in Handlers.ts: projected.

5 sites of no-known-value-widening were hidden: codecs.ts ×2, filter.ts, Query.ts and Middleware.ts (SUPPORT_FAMILIES).

After this PR:

  • 5 hidden dictionary sites are fixed: 3 by nest and 2 by Rec.filter. nest's parameter, which was already visible, is fixed too.
  • 3 dictionary sites are now visible warn-tier debt: flatten's return and its flat local in codecs.ts, and projected in Handlers.ts. flatten's leaves come from Object.entries on arbitrary group objects, so it needs a group type guard. That's a code change outside this issue.
  • All 5 hidden widening sites are now visible.
  • Nothing is hidden. For both rules, visible equals true.

Both rules are still above zero, so they stay at warn.

Why a note and not a lint rule

oxlint's no-restricted-imports matches the imported name, so it also reports import { Record as Rec } from "effect". I probed it. effect/prefer-namespace-imports would enforce a namespace import, but it does that for every module, which is why it is off. That leaves a custom JS plugin rule as the only mechanical guard. The issue's done-when allows a note. A guard is a possible follow-up, and that's the owner's call.

Verification

All run in a fresh clone at the head commit, rebased on trunk d8d9f18:

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass (0 errors, 4348 warnings)
  • vp run check (sources, type-level tests, examples, emitted declarations): pass ("check: every type gate green")
  • vp run -r test:unit: pass (root 2477/2477; examples 45, 41, 54)
  • vp run docgen (every JSDoc @example compiled and executed): pass (224 examples)
  • fallow audit --format json --quiet --explain --gate-marker agent: verdict pass
  • fallow audit --base origin/trunk: pass ("No issues in 10 changed files"; 15 inherited findings excluded)

Changeset

None. Published behaviour does not change.

  • A changeset under .changeset/ for every change to published behaviour (not applicable)

dist/ does change. I diffed it against a trunk d8d9f18 build:

  • dist/index.js changes only at the filter split. The loop becomes two Record.filter calls, with the same keys on the same side. The old loop passes the new test, as noted above.
  • dist/index.d.ts differs only in the member order of one union: the requirements of Conformance.verify's Effect. The set of members is the same.

Notes

  • Review fixes (second commit).
  • Owner decision: whether to report the blind spot upstream to @mpsuesser/oxlint-plugin-effect. The issue leaves that to you, and nothing was filed. The plugin should treat a value-only namespace import as a type binding only when it's referenced as Record.X, never as a bare Record<…>.
  • The nest signature change was checked against src/internal/codecs.test.ts. Its call sites infer V (string, or string | string[]).

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits October 8, 2026 22:32
`effect(no-unsafe-dictionary-type)` and `effect(no-known-value-widening)`
only treat `Record<K, V>` as the built-in while no local binding is named
`Record`, so `import { Record } from "effect"` hid every such site in the
file. Alias the module (`Record as R`; `Rec` in Query.ts, where `R` is the
resource type parameter) in codecs.ts, filter.ts and Query.ts, and record
the convention next to the rule's tier entry in vite.config.ts.

Make `nest` generic over its leaf value type, which removes four of the
rule's sites in codecs.ts (three of them previously hidden). The rest of
the unmasked sites (`flatten`, and the decode loop in `Query.schema`) have
no types-only fix and are now visible warn-tier debt. Handlers.ts and
codecs.test.ts keep the unaliased import: other open PRs edit them.

No runtime or emitted-declaration change: `dist/` is byte-identical to
trunk's build.

Closes #275

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
take the alias: `src/Handlers.ts`, `src/Middleware.ts` and
`src/internal/codecs.test.ts` now import it as `Rec`. That unmasks one
`no-unsafe-dictionary-type` site (`Handlers.ts`, `projected`) and one
`no-known-value-widening` site (`Middleware.ts`, `SUPPORT_FAMILIES`), so
the visible count of both rules equals the true count.

`codecs.ts`, `filter.ts`, `Assemble.test.ts` and `Handlers.test.ts` switch
from `R` to `Rec`, the spelling
`Query.ts` and trunk's `schemaExt.ts` use, and the `vite.config.ts` note
now says to spell the alias `Rec` everywhere.

`Query.schema`'s filter decode splits the flat record with `Rec.filter`
instead of a loop into two annotated `Record<string, unknown>` locals,
which clears both remaining sites there. `Rec.filter` writes through
effect's `assignProperty`, so a `__proto__` key stays an own property.
A new test routes `filter[<Object.prototype member>]` to the grammar and
drops a bare key of that name next to a valid filter.

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc

Co-Authored-By: Claude <noreply@anthropic.com>
@thomasfosterau
thomasfosterau force-pushed the issue-275-masked-dictionary-lint branch from 2fc9e05 to e32e7b2 Compare October 8, 2026 22:36
@thomasfosterau
thomasfosterau merged commit 2521e53 into trunk Oct 8, 2026
1 check passed
@thomasfosterau
thomasfosterau deleted the issue-275-masked-dictionary-lint branch October 8, 2026 23:12
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.

chore: lint no-unsafe-dictionary-type misses sites in files that import effect's Record

2 participants