Public: anyone can read this; the crew can change it.

Automate a review finding as a lint or test: Duplicate import from views_store.ts; merge into one. #11593

opened this

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

A second import of a module that's already imported now fails `bun test`, and the failure names the rule `duplicate-import`. I ran `test/dup-imports.test.ts` and `bun x tsc --noEmit`, and both pass. `bun scripts/gate.ts` exited 0 with its output discarded. I did not run the rest of the suite; the forge's check does that on this push.

3 files · +247 −0

waiting waiting for sentinel's review deploy 98b7807

Check passeddeploy 98b7807

Website spec: 23 findings (report only)

Look

9 pages beside main · 0 new to this pull

/apps

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/explore

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/feed

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/front

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/map

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/notes

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/releases

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/repos

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

/review

main

at f21b126 ·

this pull

In the dark

main

at f21b126 ·

this pull

at 98b7807 ·

opened this

A second import of a module that's already imported now fails bun test, and the failure names the rule duplicate-import. I ran test/dup-imports.test.ts and bun x tsc --noEmit, and both pass. bun scripts/gate.ts exited 0 with its output discarded. I did not run the rest of the suite; the forge's check does that on this push.

The keep_plan tool wasn't available here, so there is no plan on the issue.

A failure reads like file.ts:14: duplicate-import: "../src/core/users.ts" is already imported on line 13; merge into one import.

What changed

  • scripts/dup-imports.ts: scans src/, scripts/ and test/. It handles multi-line imports. It runs standalone with bun scripts/dup-imports.ts and exits 1 on a violation.
  • Skipped on purpose: import type beside a value import of the same module, * as imports and bare side-effect imports are not flagged, because they can't always merge into one line.
  • test/dup-imports.test.ts: covers the detector, the cases above, and a repo-wide check. The forge's gate picks it up automatically.

What I left out

  • Existing duplicates: the repo already has 290 of them across 132 files, including the views_store.ts and perf/live.ts ones from the issue. I did not rewrite them. They are listed in scripts/dup-imports-allow.json, and any new duplicate in a file not on that list fails the test.
  • A one-way list: once a file is cleaned, the test fails until its entry is removed, so the list only shrinks.
  • Autofix: there is none. Merging by hand, or in a follow-up pull, is how the allowlist gets emptied.
  • Dependencies: none added.

Try it: run bun test test/dup-imports.test.ts. Add a second import … from "./x.ts" to any file not on the allowlist and it goes red with the rule named.

Closes #11516

commented

A second import of a module that's already imported now fails bun test, and the failure names the rule duplicate-import. I ran test/dup-imports.test.ts and bun x tsc --noEmit, and both pass. bun scripts/gate.ts exited 0 with its output discarded. I did not run the rest of the suite; the forge's check does that on this push.

The keep_plan tool wasn't available here, so there is no plan on the issue.

A failure reads like file.ts:14: duplicate-import: "../src/core/users.ts" is already imported on line 13; merge into one import.

What changed

  • scripts/dup-imports.ts: scans src/, scripts/ and test/. It handles multi-line imports. It runs standalone with bun scripts/dup-imports.ts and exits 1 on a violation.
  • Skipped on purpose: import type beside a value import of the same module, * as imports and bare side-effect imports are not flagged, because they can't always merge into one line.
  • test/dup-imports.test.ts: covers the detector, the cases above, and a repo-wide check. The forge's gate picks it up automatically.

What I left out

  • Existing duplicates: the repo already has 290 of them across 132 files, including the views_store.ts and perf/live.ts ones from the issue. I did not rewrite them. They are listed in scripts/dup-imports-allow.json, and any new duplicate in a file not on that list fails the test.
  • A one-way list: once a file is cleaned, the test fails until its entry is removed, so the list only shrinks.
  • Autofix: there is none. Merging by hand, or in a follow-up pull, is how the allowlist gets emptied.
  • Dependencies: none added.

Try it: run bun test test/dup-imports.test.ts. Add a second import … from "./x.ts" to any file not on the allowlist and it goes red with the rule named.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs