Skip to content

chore: forbid circular imports with import/no-cycle - #2190

Merged
raon0211 merged 1 commit into
mainfrom
chore/no-cycle
Nov 6, 2026
Merged

raon0211 merged 1 commit into
mainfrom
chore/no-cycle

Conversation

@raon0211

@raon0211 raon0211 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #2189. This turns on oxlint's import/no-cycle as an error, so a PR that introduces a circular import fails yarn lint. CI already lints every file.

"plugins": ["eslint", "typescript", "import"],
"import/no-cycle": ["error", { "ignoreTypes": true }]
  • ignoreTypes: type-only imports are erased at build time, so they cannot cause evaluation-order problems. The one existing type-only cycle (compat/function/partial.ts / partialRight.ts → compat/toolkit.ts → compat/compat.ts) is left alone.
  • Existing cycle: the only runtime cycle in src is the util/serialize recursion. serializeValue → serializeObject → serializePlainObject / compareValues → serializeValue. These functions are mutually recursive by design, and each import is used only at call time, never while the module is evaluated. So the six imports get an inline oxlint-disable-next-line ... -- reason comment instead of the four files being merged into one.
  • Cost: a full oxlint run goes from about 4.4s to about 4.6s.

Verification

I added a cycle temporarily and checked that the rule reports it, then reverted:

Case Result
src/array/chunk.ts imports from ../index.ts reported
src/compat/array/every.ts imports from ../compat.ts reported
partial.ts → toolkit.ts as import type (current code) not reported
the same import changed to a value import reported

Linting one file is enough. oxlint follows the module graph, so yarn oxlint src/array/chunk.ts reports the cycle on its own.

Test plan

  • yarn lint: 0 errors
  • yarn format:check
  • yarn vitest run src/util/serialize

@raon0211
raon0211 requested a review from dayongkr as a code owner November 6, 2026 00:52
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Nov 6, 2026 1:01am UTC

Request Review

@raon0211
raon0211 changed the base branch from chore/oxlint-reland to main November 6, 2026 00:54
Enable oxlint's import plugin and turn on import/no-cycle as an error so that
a new import cycle fails `yarn lint` in CI. Type-only imports are ignored
(`ignoreTypes`) because they are erased at build time. The compat Toolkit type
imports form a cycle that has no effect at runtime.

The only cycle left in src is the serialize recursion: serializeValue
dispatches to serializeObject, which calls back into serializeValue through
serializePlainObject and compareValues. Each of those imports is only used
at call time, never while the module is being evaluated, so they carry an
inline disable comment instead of being merged into one file.

The rule adds about 0.2s to a full oxlint run.
@raon0211
raon0211 merged commit c986957 into main Nov 6, 2026
11 of 12 checks passed
@raon0211
raon0211 deleted the chore/no-cycle branch November 6, 2026 00:56

This branch was successfully deployed

1 active deployment
Preview — 70117925 Deployed Nov 6, 2026 by vercel[bot]
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