Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/oxlint-extends-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"ultracite": patch
---

`ultracite init` now extends the Oxlint presets in a fixed order when it updates an existing `oxlint.config.ts`: `core` first, then the framework presets, and `anti-slop` last. It used to follow the order of the preset imports, so once `ultracite fix` had sorted them, re-running `init` put `antiSlop` (and presets such as `angular` and `astro`) ahead of `core`, which turned back on the rules Anti-Slop turns off. Configs that were reordered this way are put back in order, and `init` now says when it moves a preset. A js-plugins selection now sits where the full js-plugins preset would, ahead of the react-doctor add-ons, `shadcn` and `anti-slop`, so Anti-Slop is always last.

Updating an existing `oxlint.config.ts` also keeps more of what you wrote:

- Which presets are extended now comes from `extends` rather than the imports, so a preset you import without extending (to reuse its `rules`, say) keeps its import and is no longer added to `extends`. A full js-plugins preset that a new selection replaces in `extends` keeps its import too when your own code still uses it. Workspace configs and `ultracite doctor` go by `extends` as well, so a preset that's only imported doesn't count as loaded.
- A preset imported under another name, such as `import ultraciteCore from "ultracite/oxlint/core"`, keeps that name, including in the settings `init` moves over from `.oxlintrc.json`, and a second import of the same preset under another name is kept as written. A preset `init` adds takes an `ultracite`-prefixed name, such as `ultraciteReact`, when the config already uses the usual one.
- Your own `extends` entries stay where they were among the presets: an entry before `core` stays first, one right after a preset stays after it, and one after the last preset stays last. An entry is no longer dropped because its name matches a constant older Ultracite releases generated, such as `selectedJsPlugins`, or because it's a `jsPlugins` const declared with a `selectJsPlugins` of your own, and a `selectJsPlugins` of your own is no longer read as an Ultracite selection.
- A config that imports a preset with `import * as`, or declares its own `defineConfig`, `selectJsPlugins` or `jsPluginSettings` where the Ultracite config needs that name, is left unchanged with a warning that says how to fix it, instead of being rewritten into one that doesn't load.
41 changes: 24 additions & 17 deletions packages/cli/__tests__/mock-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { mock } from "bun:test";
* puts back the defaults the test preload installs, keeping the blast radius
* to the test that opted in.
*/
// The real readdirSync captured (and typed via `declare global`) by the test
// preload before it installs the default node:fs mock.
const realReaddirSync = globalThis.__realReaddirSync;

/**
* `links` maps a path to the path its symbolic link points at: reads and
* existence checks follow it, `lstatSync` reports it as a link, and
Expand Down Expand Up @@ -44,23 +40,34 @@ export const mockFileSystem = (

return content;
}),
readdirSync: realReaddirSync,
// The real readdirSync, captured (and typed via `declare global`) by the
// test preload before it installs the default node:fs mock.
readdirSync: globalThis.__realReaddirSync,
realpathSync: mock(resolve),
writeFileSync: mock(() => {}),
}));
};

/**
* The node:fs mock the test preload installs: every path is missing and
* writes do nothing. readdirSync stays real because oxlint-config.test.ts
* reads the real config files.
*/
export const defaultFileSystemMock = () => ({
accessSync: mock(() => {
throw new Error("ENOENT");
}),
existsSync: mock(() => false),
lstatSync: mock(() => ({ isSymbolicLink: () => false })),
mkdirSync: mock(() => {}),
mkdtempSync: mock((prefix: string) => `${prefix}mock`),
readFileSync: mock(() => "{}"),
readdirSync: globalThis.__realReaddirSync,
realpathSync: mock((filePath: string) => filePath),
rmSync: mock(() => {}),
writeFileSync: mock(() => {}),
});

export const restoreFileSystemMock = (): void => {
mock.module("node:fs", () => ({
accessSync: mock(() => {
throw new Error("ENOENT");
}),
existsSync: mock(() => false),
lstatSync: mock(() => ({ isSymbolicLink: () => false })),
mkdirSync: mock(() => {}),
readFileSync: mock(() => "{}"),
readdirSync: realReaddirSync,
realpathSync: mock((filePath: string) => filePath),
writeFileSync: mock(() => {}),
}));
mock.module("node:fs", defaultFileSystemMock);
};
Loading