@sonsu-lee/oxlint-config 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -15
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +123 -15
- package/package.json +15 -4
- package/skills/sonsu-lee-lint-setup/SKILL.md +113 -0
package/README.md
CHANGED
|
@@ -8,11 +8,17 @@ Oxlint preset with selectable profiles and per-project rule settings.
|
|
|
8
8
|
pnpm add -D oxlint oxlint-tsgolint @sonsu-lee/oxlint-config
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Type-aware rules are on by default and run through `oxlint-tsgolint`. Your tsconfig must be compatible with TypeScript 7; the installed `typescript` package may be older. For a JavaScript project, pass `typescript: false` and
|
|
11
|
+
Type-aware rules are on by default and run through `oxlint-tsgolint`. Your tsconfig must be compatible with TypeScript 7; the installed `typescript` package may be older. For a JavaScript project, pass `typescript: false` to turn off the TypeScript and type-aware rules. `oxlint-tsgolint` is still a required peer dependency.
|
|
12
12
|
|
|
13
|
-
Upgrade `oxlint-tsgolint` together with `oxlint
|
|
13
|
+
Upgrade `oxlint-tsgolint` together with `oxlint`: each Oxlint release sets the minimum in its peer range (1.90.0–1.93.0: 7.0.2005, 1.94.0: 7.0.2007, 1.95.0 and newer: 7.0.2008). An older tsgolint panics on a rule that a newer Oxlint hands it, and Oxlint then prints no report at all. npm reports the mismatch as a peer conflict; pnpm installs it with only a warning, so check the pair when you upgrade.
|
|
14
14
|
|
|
15
|
-
The preset requires Node.js 20.6 or newer
|
|
15
|
+
The preset uses `import.meta.resolve` to resolve `@sonsu-lee/oxlint-plugin`, which requires Node.js 20.6 or newer. Oxlint needs Node.js 22.18 or newer to load a `.ts` or `.mts` config, such as the example below. A JSON config cannot call `preset()`.
|
|
16
|
+
|
|
17
|
+
## AI agents
|
|
18
|
+
|
|
19
|
+
The package ships a setup skill at `skills/sonsu-lee-lint-setup/SKILL.md`. In your agent, run:
|
|
20
|
+
|
|
21
|
+
> Read `node_modules/@sonsu-lee/oxlint-config/skills/sonsu-lee-lint-setup/SKILL.md` and follow it to set up or migrate linting in this project.
|
|
16
22
|
|
|
17
23
|
## Usage
|
|
18
24
|
|
|
@@ -22,7 +28,7 @@ import { preset } from '@sonsu-lee/oxlint-config';
|
|
|
22
28
|
import { defineConfig } from 'oxlint';
|
|
23
29
|
|
|
24
30
|
export default defineConfig(
|
|
25
|
-
preset({ node: true, vitest: true, ignores: ['gen/**'] }, { rules: { 'no-
|
|
31
|
+
preset({ node: true, vitest: true, ignores: ['gen/**'] }, { rules: { 'no-ternary': 'off' } }),
|
|
26
32
|
);
|
|
27
33
|
```
|
|
28
34
|
|
|
@@ -59,19 +65,23 @@ Returns a complete Oxlint root config. Oxlint's `correctness`, `suspicious`, `pe
|
|
|
59
65
|
|
|
60
66
|
| Option | Default | Description |
|
|
61
67
|
| --- | --- | --- |
|
|
62
|
-
| `ignores` | `[]` | Paths to ignore in addition to `**/dist
|
|
68
|
+
| `ignores` | `[]` | Paths to ignore in addition to `**/dist/**`, `**/coverage/**`, and `**/*.astro` |
|
|
63
69
|
| `typescript` | `true` | TypeScript plugin |
|
|
64
70
|
| `typeAware` | same as `typescript` | Type-aware rules, replacing overlapping rules. Needs `typescript` |
|
|
65
71
|
| `node` | `false` | Node.js plugin and globals |
|
|
72
|
+
| `server` | `false` | Server handler rules: `require-await` off, `no-await-in-loop` and `no-unchecked-fetch` warnings |
|
|
66
73
|
| `browser` | `false` | Browser globals |
|
|
67
74
|
| `react` | `false` | React and React Hooks plugin |
|
|
68
75
|
| `nextjs` | `false` | Next.js core-web-vitals rules; enables React |
|
|
69
|
-
| `tanstackQuery` | `false` | Enables React and
|
|
76
|
+
| `tanstackQuery` | `false` | Enables React and the [TanStack Query rules](#tanstack-query). Install the peer with `pnpm add -D @tanstack/eslint-plugin-query` |
|
|
77
|
+
| `tanstackRouter` | `false` | TanStack Router rules; install the peer with `pnpm add -D @tanstack/eslint-plugin-router` |
|
|
78
|
+
| `reactRouter` | `false` | React Router route-module rules for `app/routes`; bans `react-router-dom` |
|
|
70
79
|
| `xstate` | `false` | Five XState v5 machine rules; independent of React |
|
|
80
|
+
| `stylex` | `false` | StyleX rules; install the peer with `pnpm add -D @stylexjs/eslint-plugin` |
|
|
71
81
|
| `vitest` | `false` | Vitest plugin for `*.test.*`, `*.spec.*`, and `*.e2e-spec.*` files |
|
|
72
|
-
| `nestjs` | `false` | Allows code the NestJS CLI generates. Needs `typescript` and turns on `node` |
|
|
82
|
+
| `nestjs` | `false` | Allows code the NestJS CLI generates. Needs `typescript` and turns on `node` and `server` |
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
The preset throws if you pass `typescript: false` with `typeAware: true` or `nestjs: true`. It also throws if you pass `node: false` or `server: false` with `nestjs: true`, or `react: false` with `nextjs: true` or `tanstackQuery: true`. Why the preset uses these categories, and when a profile changes a rule, is described in [ADR 0005](../../docs/decisions/0005-profile-rule-sources.md).
|
|
75
85
|
|
|
76
86
|
If both arguments set `typeAware`, `userConfig.options.typeAware` wins. The same TypeScript requirement applies to that value.
|
|
77
87
|
|
|
@@ -108,7 +118,7 @@ await pushToWarehouse(order);
|
|
|
108
118
|
markSynced(order);
|
|
109
119
|
```
|
|
110
120
|
|
|
111
|
-
**Profile and severity.** The type-aware profile reports an error. Return the promise, await it, or attach a rejection handler.
|
|
121
|
+
**Profile and severity.** The type-aware profile reports an error. Return the promise, await it, or attach a rejection handler. For `main.ts`, the NestJS profile sets `ignoreVoid`, because the CLI's CommonJS template ends with `void bootstrap()`; any voided promise in that file is allowed.
|
|
112
122
|
|
|
113
123
|
**What it cannot see.** JavaScript-only presets without type-aware linting and calls on `any` do not provide the promise type this check needs.
|
|
114
124
|
|
|
@@ -134,6 +144,92 @@ return cached ?? loadFromDatabase(key);
|
|
|
134
144
|
|
|
135
145
|
**What it cannot see.** The rule does not follow a handler passed by reference or decide whether a log message provides adequate recovery.
|
|
136
146
|
|
|
147
|
+
### Server handlers
|
|
148
|
+
|
|
149
|
+
**Failure it prevents.** A loop serializes calls that could run concurrently.
|
|
150
|
+
|
|
151
|
+
**Reported**
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
for (const id of ids) {
|
|
155
|
+
await notify(id);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Allowed**
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
app.get('/health', async (context) => context.json({ status: 'ok' }));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Profile and severity.** `server` turns off `require-await`, and `typescript/require-await` when type-aware, so an `async` route handler can return a value without awaiting. It warns on `no-await-in-loop`; some loops must await in order, so the rule is a review warning, not an error. It also enables the promise plugin and warns on `promise/always-return`, `unicorn/no-process-exit`, and `sonsu-lee/no-unchecked-fetch`. `nestjs: true` turns on `server`.
|
|
166
|
+
|
|
167
|
+
**What it cannot see.** The rule reports an `await` directly in the loop body. An `await` inside a nested function in the loop is not an `await` in the loop.
|
|
168
|
+
|
|
169
|
+
### Promise misuse on servers
|
|
170
|
+
|
|
171
|
+
**Failure it prevents.** A callback resolves a promise twice, or a callback API and a promise are mixed, so a caller hangs or observes a late value.
|
|
172
|
+
|
|
173
|
+
**Reported**
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
resolve(value);
|
|
177
|
+
resolve(other);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
readFile(path, (error, data) => {
|
|
182
|
+
if (error) return;
|
|
183
|
+
void Promise.resolve(data);
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Allowed**
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
if (error) {
|
|
191
|
+
reject(error);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
resolve(value);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Profile and severity.** `server` loads the promise plugin. The plugin's rules are errors except `promise/no-multiple-resolved` and `promise/always-return`, which are warnings: the first while its upstream false-positive history is reviewed, the second because it cannot tell whether the chain value is read.
|
|
198
|
+
|
|
199
|
+
**What it cannot see.** A callback passed by reference, a promise handed to an external scheduler, or a reject path that only a runtime branch reaches.
|
|
200
|
+
|
|
201
|
+
### Blocking and process exit
|
|
202
|
+
|
|
203
|
+
**Failure it prevents.** A request path calls `readFileSync` and blocks every request; a request handler calls `process.exit()` and truncates in-flight work.
|
|
204
|
+
|
|
205
|
+
**Reported**
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { readFileSync } from 'node:fs';
|
|
209
|
+
const config = readFileSync('/etc/app/config.json', 'utf8');
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
process.exit(1);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Allowed**
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
process.on('SIGTERM', () => process.exit(0));
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Startup reads still warn. Suppress the warning on the line before the read and give the reason on the same comment line; see [lint exceptions](../../docs/reference/lint-exceptions.md).
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
// oxlint-disable-next-line node/no-sync -- Startup reads config before the server accepts requests.
|
|
226
|
+
const config = readFileSync('/etc/app/config.json', 'utf8');
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Profile and severity.** `node` warns on `node/no-sync`; test files are exempt because they set up fixtures before the test body. `server` warns on `unicorn/no-process-exit` and `sonsu-lee/no-unchecked-fetch`.
|
|
230
|
+
|
|
231
|
+
**What it cannot see.** The rule cannot tell startup code from a request path, which is why both stay warnings.
|
|
232
|
+
|
|
137
233
|
### Ternaries
|
|
138
234
|
|
|
139
235
|
**Failure it prevents.** A second shipping threshold can be added to the wrong arm of a nested fee calculation.
|
|
@@ -224,15 +320,41 @@ useEffect(() => connect(roomId), [roomId]);
|
|
|
224
320
|
|
|
225
321
|
### TanStack Query
|
|
226
322
|
|
|
227
|
-
**Failure it prevents.** Orders with different IDs share a cache entry if the query key omits the ID. Creating a new client on render discards that cache.
|
|
323
|
+
**Failure it prevents.** Orders with different IDs share a cache entry if the query key omits the ID. Creating a new client on render discards that cache. A query result in a dependency array makes every render a dependency change.
|
|
324
|
+
|
|
325
|
+
**Reported:** inline `useQuery({ queryKey: ['order'], queryFn: () => fetchOrder(orderId) })`; `useMemo(() => query.data, [query])`. The typed `sonsu-lee-eslint/no-query-rest-destructuring` reports `const { data, ...rest } = useQuery(...)` in TypeScript files when the project runs ESLint with `@sonsu-lee/eslint-config`.
|
|
326
|
+
|
|
327
|
+
**Allowed:** `useQuery(queryOptions({ queryKey: ['order', orderId], queryFn: () => fetchOrder(orderId) }))`; `useMemo(() => query.data, [query.data])`; destructure only the fields the component reads.
|
|
328
|
+
|
|
329
|
+
**Profile and severity.** `tanstackQuery` reports `exhaustive-deps`, `stable-query-client`, `no-unstable-deps`, `prefer-query-options`, the two property-order rules, and `sonsu-lee/no-query-data-mutation` as errors. The upstream `no-rest-destructuring` is off; the typed `sonsu-lee-eslint/no-query-rest-destructuring` reports object rest without the `useQueries` array false positive (#12419) in TypeScript files when the project runs ESLint with `@sonsu-lee/eslint-config`. `sonsu-lee/no-query-import-alias` is an error, because an alias or re-export hides the call from these rules.
|
|
228
330
|
|
|
229
|
-
**
|
|
331
|
+
**What it cannot see.** `no-void-query-fn` needs types; Oxlint does not supply them to JS plugins, so the profile does not enable it. A query result returned from a custom hook is covered by the typed rest rule when the project runs ESLint.
|
|
230
332
|
|
|
231
|
-
|
|
333
|
+
### TanStack Router
|
|
232
334
|
|
|
233
|
-
**
|
|
335
|
+
**Failure it prevents.** Route properties that read inferred types must come before the ones that provide them; reversing the order changes what `loader`, `context`, and search parameters resolve to. A path parameter that is not a JavaScript identifier cannot be read from `params`.
|
|
234
336
|
|
|
235
|
-
**
|
|
337
|
+
**Reported:** `createFileRoute('/path')({ loader, beforeLoad })`; `createFileRoute('/posts/$post-id')`; an aliased or re-exported `createFileRoute`.
|
|
338
|
+
|
|
339
|
+
**Allowed:** `beforeLoad` before `loader`; `$postId`; importing each router API under its own name from `@tanstack/*-router`.
|
|
340
|
+
|
|
341
|
+
**Profile and severity.** `tanstackRouter` warns about `create-route-property-order` (the upstream severity; the rule is fixable) and reports `route-param-names` and `sonsu-lee/no-router-import-alias` as errors. The alias rule exists because the upstream rules find a route creator by its imported name; an alias, a namespace import, or a re-export makes them miss the call.
|
|
342
|
+
|
|
343
|
+
**What it cannot see.** A wrapper or barrel file that re-exports the router package, and a route creator reached through a variable.
|
|
344
|
+
|
|
345
|
+
### React Router
|
|
346
|
+
|
|
347
|
+
**Failure it prevents.** A route module with only an `action` cannot answer a `GET`, so a refresh or a history navigation fails. A typo such as `Loader` or `ErrorBoundry` is an unknown export React Router silently ignores. v8 removed `react-router-dom`, the v6-to-v7 mirror.
|
|
348
|
+
|
|
349
|
+
**Reported:** a route module that exports `action` or `clientAction` and no loader and no default component; `Loader` or another near miss for a route export; `import { Link } from 'react-router-dom'`.
|
|
350
|
+
|
|
351
|
+
**Allowed:** an action with a loader or a default component; the documented route exports and helper exports such as `formatPrice`; `react-router/dom`.
|
|
352
|
+
|
|
353
|
+
**Profile and severity.** `reactRouter` reports `sonsu-lee/no-action-only-route` and the `react-router-dom` ban as errors, and warns about `sonsu-lee/no-misnamed-route-export`. The route-module rules apply to `**/app/routes/**`, the framework's file-routes layout at any depth; a project that keeps route modules elsewhere adds its own `overrides` entry with the same files. `no-misnamed-route-export` reports only near misses; a named `Component` export is not reported and does not count as a component for `no-action-only-route`. Its `allow` option silences a deliberate near-miss name; set it in an `overrides` entry for `**/app/routes/**`, because the profile's route-module override replaces a root `rules` entry.
|
|
354
|
+
|
|
355
|
+
**What it cannot see.** A resource route that always redirects before the browser sends a `GET`; a named `Component` export, which React Router v8 does not document and the rules do not count; an unknown export that is not close to a route export.
|
|
356
|
+
|
|
357
|
+
**Composition limits.** A project root `no-restricted-imports` replaces the profile's entry, including the `react-router-dom` path, so repeat the ban in the project list. The route-module override also matches modules colocated in a route folder; turn the two rules off for that directory with its own `overrides` entry.
|
|
236
358
|
|
|
237
359
|
### XState
|
|
238
360
|
|
|
@@ -276,6 +398,20 @@ preset(
|
|
|
276
398
|
|
|
277
399
|
The profile does not impose this list: a project's root `no-restricted-imports` replaces the whole inherited rule.
|
|
278
400
|
|
|
401
|
+
### StyleX
|
|
402
|
+
|
|
403
|
+
**Failure it prevents.** A property or value that StyleX cannot compile never reaches the stylesheet, and nothing else reports it. A multi-value shorthand such as `padding: '10px 20px'` is one of those: StyleX wants one property per value. A `className` or `style` prop next to a `stylex.props()` spread competes with the compiled class, and which one wins depends on the order of the rules in the stylesheet.
|
|
404
|
+
|
|
405
|
+
**Reported:** `disply: 'flex'`, `padding: '10px 20px'`, and `<div {...stylex.props(styles.root)} className="row" />`.
|
|
406
|
+
|
|
407
|
+
**Allowed:** the supported property, `paddingTop` and `paddingBottom` in place of the shorthand, and the spread alone.
|
|
408
|
+
|
|
409
|
+
**Profile and severity.** `stylex` reports `valid-styles`, `valid-shorthands`, `no-conflicting-props`, `no-nonstandard-styles`, `no-legacy-contextual-styles`, and `no-unused` as errors. It warns about `no-lookahead-selectors`, which reports the browser support of `stylex.when.*` rather than a defect in the code. The profile loads `@stylexjs/eslint-plugin` as a JS plugin: that package is the official StyleX lint, and Oxlint has no built-in equivalent.
|
|
410
|
+
|
|
411
|
+
Two rules stay off. `sort-keys` orders the keys of a style object, which is the formatter's job and does not change the compiled output. `enforce-extension` requires every exported StyleX value to live in a `*.stylex.js` file: that is a project layout choice, and its options name the imports to track.
|
|
412
|
+
|
|
413
|
+
**What it cannot see.** A style object reached only through another file's import. `no-unused` treats an exported object as used, so the profile does not report that object as dead code.
|
|
414
|
+
|
|
279
415
|
## Import boundaries
|
|
280
416
|
|
|
281
417
|
Projects own their restricted paths. Use `paths` to prevent callers from bypassing an SDK wrapper or importing a retired package. Use `patterns` to keep another feature's internal modules private.
|
|
@@ -310,12 +446,16 @@ preset(
|
|
|
310
446
|
);
|
|
311
447
|
```
|
|
312
448
|
|
|
313
|
-
The rule compares import strings: a relative path is not the same as an alias, and a `paths` entry matches the whole specifier, so cover subpaths with `patterns`. Root rules replace the entire inherited entry, including its path list. The example maps `@/*` to `src/boundaries/*`; override `files` are paths relative to the config, not aliases, and disabling the rule there also lifts the feature pattern. For APIs whose declarations you own, `@deprecated` also lets `typescript/no-deprecated` report use of retired symbols.
|
|
449
|
+
The rule compares import strings: a relative path is not the same as an alias, and a `paths` entry matches the whole specifier, so cover subpaths with `patterns`. Root rules replace the entire inherited entry, including its path list. The `reactRouter` profile uses this rule for its `react-router-dom` ban, so a project list must repeat that path while the profile is on. The example maps `@/*` to `src/boundaries/*`; override `files` are paths relative to the config, not aliases, and disabling the rule there also lifts the feature pattern. For APIs whose declarations you own, `@deprecated` also lets `typescript/no-deprecated` report use of retired symbols.
|
|
314
450
|
|
|
315
451
|
## Contributing
|
|
316
452
|
|
|
317
453
|
See [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
|
318
454
|
|
|
455
|
+
## Related
|
|
456
|
+
|
|
457
|
+
See the [architecture guide](../../ARCHITECTURE.md) for how the packages fit together.
|
|
458
|
+
|
|
319
459
|
## License
|
|
320
460
|
|
|
321
461
|
[MIT](LICENSE) © Sonsu Lee
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,8 @@ interface Options {
|
|
|
11
11
|
typeAware?: boolean;
|
|
12
12
|
/** Node.js globals and rules. */
|
|
13
13
|
node?: boolean;
|
|
14
|
+
/** Long-running server rules for async handlers and sequential awaits. */
|
|
15
|
+
server?: boolean;
|
|
14
16
|
/** Browser globals. */
|
|
15
17
|
browser?: boolean;
|
|
16
18
|
/** React and React Hooks rules. Turned on by nextjs and tanstackQuery. */
|
|
@@ -19,11 +21,17 @@ interface Options {
|
|
|
19
21
|
nextjs?: boolean;
|
|
20
22
|
/** TanStack Query rules for React; needs @tanstack/eslint-plugin-query. Turns on react. */
|
|
21
23
|
tanstackQuery?: boolean;
|
|
24
|
+
/** TanStack Router rules; needs @tanstack/eslint-plugin-router. */
|
|
25
|
+
tanstackRouter?: boolean;
|
|
26
|
+
/** React Router rules for route modules under app/routes. */
|
|
27
|
+
reactRouter?: boolean;
|
|
22
28
|
/** XState v5 machine rules. */
|
|
23
29
|
xstate?: boolean;
|
|
30
|
+
/** StyleX rules; needs @stylexjs/eslint-plugin. */
|
|
31
|
+
stylex?: boolean;
|
|
24
32
|
/** Vitest rules for test files. */
|
|
25
33
|
vitest?: boolean;
|
|
26
|
-
/** Adjusts the TypeScript rules for NestJS. Needs `typescript` and turns on `node`. */
|
|
34
|
+
/** Adjusts the TypeScript rules for NestJS. Needs `typescript` and turns on `node` and `server`. */
|
|
27
35
|
nestjs?: boolean;
|
|
28
36
|
}
|
|
29
37
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -25,17 +25,18 @@ const base = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
// src/configs/nestjs.ts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
rules: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
28
|
+
function nestjs(typeAware) {
|
|
29
|
+
const mainRules = { "unicorn/prefer-top-level-await": "off" };
|
|
30
|
+
if (typeAware) mainRules["typescript/no-floating-promises"] = ["error", { ignoreVoid: true }];
|
|
31
|
+
return {
|
|
32
|
+
plugins: [],
|
|
33
|
+
rules: { "typescript/no-extraneous-class": ["error", { allowWithDecorator: true }] },
|
|
34
|
+
overrides: [{
|
|
35
|
+
files: ["**/main.ts"],
|
|
36
|
+
rules: mainRules
|
|
37
|
+
}]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
39
40
|
// src/configs/nextjs.ts
|
|
40
41
|
const nextjs = {
|
|
41
42
|
plugins: ["nextjs"],
|
|
@@ -57,7 +58,28 @@ const nextjs = {
|
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
// src/configs/node.ts
|
|
60
|
-
const node = {
|
|
61
|
+
const node = {
|
|
62
|
+
plugins: ["node"],
|
|
63
|
+
rules: { "node/no-sync": "warn" },
|
|
64
|
+
overrides: [{
|
|
65
|
+
files: ["**/*.{test,spec,e2e-spec}.{js,jsx,ts,tsx,mjs,cjs,mts,cts}"],
|
|
66
|
+
rules: { "node/no-sync": "off" }
|
|
67
|
+
}]
|
|
68
|
+
};
|
|
69
|
+
const reactRouter = {
|
|
70
|
+
plugins: [],
|
|
71
|
+
rules: { "no-restricted-imports": ["error", { paths: [{
|
|
72
|
+
name: "react-router-dom",
|
|
73
|
+
message: "Import from react-router or react-router/dom instead. v8 removed react-router-dom."
|
|
74
|
+
}] }] },
|
|
75
|
+
overrides: [{
|
|
76
|
+
files: ["**/app/routes/**/*.{js,jsx,ts,tsx}"],
|
|
77
|
+
rules: {
|
|
78
|
+
"sonsu-lee/no-action-only-route": "error",
|
|
79
|
+
"sonsu-lee/no-misnamed-route-export": "warn"
|
|
80
|
+
}
|
|
81
|
+
}]
|
|
82
|
+
};
|
|
61
83
|
// src/configs/react.ts
|
|
62
84
|
const react = {
|
|
63
85
|
plugins: ["react"],
|
|
@@ -73,6 +95,51 @@ const react = {
|
|
|
73
95
|
"typescript/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }]
|
|
74
96
|
}
|
|
75
97
|
};
|
|
98
|
+
// src/configs/server.ts
|
|
99
|
+
function server(typeAware) {
|
|
100
|
+
const rules = {
|
|
101
|
+
"require-await": "off",
|
|
102
|
+
"no-await-in-loop": "warn"
|
|
103
|
+
};
|
|
104
|
+
if (typeAware) rules["typescript/require-await"] = "off";
|
|
105
|
+
return {
|
|
106
|
+
plugins: ["promise"],
|
|
107
|
+
rules: {
|
|
108
|
+
...rules,
|
|
109
|
+
"promise/no-multiple-resolved": "warn",
|
|
110
|
+
"promise/always-return": "warn",
|
|
111
|
+
"unicorn/no-process-exit": "warn",
|
|
112
|
+
"sonsu-lee/no-unchecked-fetch": "warn"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// src/configs/stylex.ts
|
|
117
|
+
function stylex() {
|
|
118
|
+
let specifier;
|
|
119
|
+
try {
|
|
120
|
+
specifier = import.meta.resolve("@stylexjs/eslint-plugin");
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new Error("stylex needs @stylexjs/eslint-plugin, but it is not installed.", { cause: error });
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
plugins: [],
|
|
126
|
+
jsPlugins: [{
|
|
127
|
+
name: "stylex",
|
|
128
|
+
specifier
|
|
129
|
+
}],
|
|
130
|
+
rules: {
|
|
131
|
+
"stylex/valid-styles": "error",
|
|
132
|
+
"stylex/valid-shorthands": "error",
|
|
133
|
+
"stylex/no-conflicting-props": "error",
|
|
134
|
+
"stylex/no-nonstandard-styles": "error",
|
|
135
|
+
"stylex/no-legacy-contextual-styles": "error",
|
|
136
|
+
"stylex/no-unused": "error",
|
|
137
|
+
"stylex/no-lookahead-selectors": "warn",
|
|
138
|
+
"stylex/sort-keys": "off",
|
|
139
|
+
"stylex/enforce-extension": "off"
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
76
143
|
// src/configs/tanstack-query.ts
|
|
77
144
|
function tanstackQuery() {
|
|
78
145
|
let specifier;
|
|
@@ -89,7 +156,35 @@ function tanstackQuery() {
|
|
|
89
156
|
}],
|
|
90
157
|
rules: {
|
|
91
158
|
"@tanstack/query/exhaustive-deps": "error",
|
|
92
|
-
"@tanstack/query/stable-query-client": "error"
|
|
159
|
+
"@tanstack/query/stable-query-client": "error",
|
|
160
|
+
"@tanstack/query/no-unstable-deps": "error",
|
|
161
|
+
"@tanstack/query/no-rest-destructuring": "off",
|
|
162
|
+
"@tanstack/query/prefer-query-options": "error",
|
|
163
|
+
"sonsu-lee/no-query-data-mutation": "error",
|
|
164
|
+
"@tanstack/query/infinite-query-property-order": "error",
|
|
165
|
+
"@tanstack/query/mutation-property-order": "error",
|
|
166
|
+
"sonsu-lee/no-query-import-alias": "error"
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// src/configs/tanstack-router.ts
|
|
171
|
+
function tanstackRouter() {
|
|
172
|
+
let specifier;
|
|
173
|
+
try {
|
|
174
|
+
specifier = import.meta.resolve("@tanstack/eslint-plugin-router");
|
|
175
|
+
} catch (error) {
|
|
176
|
+
throw new Error("tanstackRouter needs @tanstack/eslint-plugin-router, but it is not installed.", { cause: error });
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
plugins: [],
|
|
180
|
+
jsPlugins: [{
|
|
181
|
+
name: "@tanstack/router",
|
|
182
|
+
specifier
|
|
183
|
+
}],
|
|
184
|
+
rules: {
|
|
185
|
+
"@tanstack/router/create-route-property-order": "warn",
|
|
186
|
+
"@tanstack/router/route-param-names": "error",
|
|
187
|
+
"sonsu-lee/no-router-import-alias": "error"
|
|
93
188
|
}
|
|
94
189
|
};
|
|
95
190
|
}
|
|
@@ -158,7 +253,11 @@ const xstate = {
|
|
|
158
253
|
}
|
|
159
254
|
};
|
|
160
255
|
// src/ignores.ts
|
|
161
|
-
const defaultIgnores = [
|
|
256
|
+
const defaultIgnores = [
|
|
257
|
+
"**/dist/**",
|
|
258
|
+
"**/coverage/**",
|
|
259
|
+
"**/*.astro"
|
|
260
|
+
];
|
|
162
261
|
// src/preset.ts
|
|
163
262
|
function selectProfiles(options, typeAwareOverride) {
|
|
164
263
|
const isTypeScript = options.typescript ?? true;
|
|
@@ -167,17 +266,22 @@ function selectProfiles(options, typeAwareOverride) {
|
|
|
167
266
|
typescript: isTypeScript,
|
|
168
267
|
typeAware: typeAwareOverride ?? options.typeAware ?? isTypeScript,
|
|
169
268
|
node: options.node ?? options.nestjs ?? false,
|
|
269
|
+
server: options.server ?? options.nestjs ?? false,
|
|
170
270
|
browser: options.browser ?? false,
|
|
171
271
|
react: options.react ?? needsReact,
|
|
172
272
|
nextjs: options.nextjs ?? false,
|
|
173
273
|
tanstackQuery: options.tanstackQuery ?? false,
|
|
274
|
+
tanstackRouter: options.tanstackRouter ?? false,
|
|
275
|
+
reactRouter: options.reactRouter ?? false,
|
|
174
276
|
xstate: options.xstate ?? false,
|
|
277
|
+
stylex: options.stylex ?? false,
|
|
175
278
|
vitest: options.vitest ?? false,
|
|
176
279
|
nestjs: options.nestjs ?? false
|
|
177
280
|
};
|
|
178
281
|
if (!selected.react && needsReact) throw new Error("nextjs and tanstackQuery need the react profile, but react is false.");
|
|
179
282
|
if (!selected.typescript && (selected.typeAware || selected.nestjs)) throw new Error("typeAware and nestjs need the typescript profile, but typescript is false.");
|
|
180
283
|
if (!selected.node && selected.nestjs) throw new Error("nestjs needs the node profile, but node is false.");
|
|
284
|
+
if (!selected.server && selected.nestjs) throw new Error("nestjs needs the server profile, but server is false.");
|
|
181
285
|
return selected;
|
|
182
286
|
}
|
|
183
287
|
/**
|
|
@@ -191,12 +295,16 @@ function preset(options = {}, userConfig = {}) {
|
|
|
191
295
|
[selected.typescript, () => typescript],
|
|
192
296
|
[selected.typeAware, () => typeAware],
|
|
193
297
|
[selected.node, () => node],
|
|
298
|
+
[selected.server, () => server(selected.typeAware)],
|
|
194
299
|
[selected.react, () => react],
|
|
195
300
|
[selected.nextjs, () => nextjs],
|
|
196
301
|
[selected.tanstackQuery, tanstackQuery],
|
|
302
|
+
[selected.tanstackRouter, tanstackRouter],
|
|
303
|
+
[selected.reactRouter, () => reactRouter],
|
|
197
304
|
[selected.xstate, () => xstate],
|
|
305
|
+
[selected.stylex, stylex],
|
|
198
306
|
[selected.vitest, () => vitest],
|
|
199
|
-
[selected.nestjs, () => nestjs]
|
|
307
|
+
[selected.nestjs, () => nestjs(selected.typeAware)]
|
|
200
308
|
];
|
|
201
309
|
const extendsConfigs = [
|
|
202
310
|
base,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonsu-lee/oxlint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Oxlint preset with selectable profiles and @sonsu-lee/oxlint-plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"directory": "packages/oxlint-config"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"skills"
|
|
13
14
|
],
|
|
14
15
|
"type": "module",
|
|
15
16
|
"exports": {
|
|
@@ -22,11 +23,13 @@
|
|
|
22
23
|
"access": "public"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@sonsu-lee/oxlint-plugin": "^0.
|
|
26
|
+
"@sonsu-lee/oxlint-plugin": "^0.3.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
29
|
+
"@stylexjs/eslint-plugin": "0.19.2",
|
|
28
30
|
"@tanstack/eslint-plugin-query": "5.108.4",
|
|
29
|
-
"@
|
|
31
|
+
"@tanstack/eslint-plugin-router": "1.162.0",
|
|
32
|
+
"@types/node": "26.6.11",
|
|
30
33
|
"oxlint": "1.90.0",
|
|
31
34
|
"oxlint-tsgolint": "7.0.2005",
|
|
32
35
|
"tsdown": "0.23.4",
|
|
@@ -34,13 +37,21 @@
|
|
|
34
37
|
"vitest": "5.0.5"
|
|
35
38
|
},
|
|
36
39
|
"peerDependencies": {
|
|
40
|
+
"@stylexjs/eslint-plugin": "^0.19.0",
|
|
37
41
|
"@tanstack/eslint-plugin-query": "^5.108.0",
|
|
42
|
+
"@tanstack/eslint-plugin-router": "^1.162.0",
|
|
38
43
|
"oxlint": "^1.90.0",
|
|
39
44
|
"oxlint-tsgolint": "^7.0.0"
|
|
40
45
|
},
|
|
41
46
|
"peerDependenciesMeta": {
|
|
47
|
+
"@stylexjs/eslint-plugin": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
42
50
|
"@tanstack/eslint-plugin-query": {
|
|
43
51
|
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@tanstack/eslint-plugin-router": {
|
|
54
|
+
"optional": true
|
|
44
55
|
}
|
|
45
56
|
},
|
|
46
57
|
"engines": {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sonsu-lee-lint-setup
|
|
3
|
+
description: >-
|
|
4
|
+
Set up or migrate linting in a consumer JavaScript or TypeScript project with @sonsu-lee/oxlint-config, @sonsu-lee/eslint-config, or @sonsu-lee/stylelint-config. Use for consumer projects, not for contributing to the style-guide repository.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Set up consumer linting
|
|
8
|
+
|
|
9
|
+
## Hard rules
|
|
10
|
+
|
|
11
|
+
- Use Oxlint as the primary JS/TS linter. Use ESLint only for custom typed rules Oxlint cannot run and for Astro. Use Stylelint for styles; leave formatting to the formatter.
|
|
12
|
+
- Export the Oxlint `preset()` result as the root config, never inside `extends`. It returns `ignorePatterns`, `env`, and `options.typeAware`, which Oxlint does not inherit through `extends`.
|
|
13
|
+
- Do not add `eslint-plugin-oxlint` or typescript-eslint recommended configs. Do not re-enable rules that Oxlint already runs. Pass project-specific ESLint rules to `preset(...configs)`.
|
|
14
|
+
- Keep warnings non-blocking. Do not add `--max-warnings 0` to lint scripts or CI.
|
|
15
|
+
|
|
16
|
+
## Detect
|
|
17
|
+
|
|
18
|
+
1. Read the consumer's manifests, lockfile, Node pin, workspace layout, lint configs, scripts, and CI. Choose the package or workspace that owns each config.
|
|
19
|
+
2. Check source extensions, framework dependencies, and tsconfig coverage. Identify JavaScript, TypeScript, Astro, CSS, and Tailwind CSS v4.
|
|
20
|
+
3. In a migration, keep project-specific rules, ignores, and globals. Remove replaced configs and dependencies and update scripts and CI.
|
|
21
|
+
|
|
22
|
+
## Decision table
|
|
23
|
+
|
|
24
|
+
| Detected | Select |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| JavaScript only | `preset({ typescript: false })` disables both TypeScript and type-aware rules. |
|
|
27
|
+
| TypeScript | Keep the defaults: `typescript` and `typeAware` are on. Set `typeAware: false` only to disable type-aware rules while keeping the TypeScript plugin. |
|
|
28
|
+
| Runtime or framework | Select only matching profiles. Read the option table in the installed `node_modules/@sonsu-lee/oxlint-config/README.md`: options missing from the installed version are ignored without an error. |
|
|
29
|
+
| Next.js or TanStack Query | Select `nextjs` or `tanstackQuery`. Both enable and require `react`. |
|
|
30
|
+
| NestJS | Select `nestjs`. It requires `typescript` and enables and requires `node` (and `server` on 0.2.0+). |
|
|
31
|
+
| TypeScript with `sonsu-lee-eslint` typed rules needed for ignored rejections, TanStack Query rest destructuring, or void `queryFn` | Add `@sonsu-lee/eslint-config` by default when `tanstackQuery` is selected in a TypeScript project; otherwise add the typed layer only on request. |
|
|
32
|
+
| Astro components | Use the ESLint `./astro` export if supported. |
|
|
33
|
+
| CSS, CSS Modules, Tailwind CSS v4, or Astro styles | Add `@sonsu-lee/stylelint-config`. Astro styles require 0.2.0+. |
|
|
34
|
+
|
|
35
|
+
Explicitly disabling a required profile throws, as does `{ typescript: false, typeAware: true }`.
|
|
36
|
+
|
|
37
|
+
`server`, `tanstackRouter`, `reactRouter`, `stylex`, the typed TanStack Query ESLint rules, and Astro support start in 0.2.0. If the installed version is older, report any missing profile or Astro support instead of configuring it. Do not add ESLint for `tanstackQuery` by default when the installed version lacks those rules. If the installed Oxlint preset lacks the `.astro` ignore, pass `ignores: ['**/*.astro']` to `preset` so Oxlint does not parse components as JavaScript.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Use the consumer's package manager. Install only the selected linters as dev dependencies. The Oxlint and ESLint presets install their own `@sonsu-lee` plugins.
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pnpm add -D oxlint @sonsu-lee/oxlint-config
|
|
45
|
+
pnpm add -D oxlint-tsgolint # Only when Oxlint type-aware rules are on.
|
|
46
|
+
pnpm add -D eslint @sonsu-lee/eslint-config # ESLint layer.
|
|
47
|
+
pnpm add -D stylelint @sonsu-lee/stylelint-config # Styles.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Treat `oxlint` and `oxlint-tsgolint` as a pair when installing or upgrading. Check the selected Oxlint release's peer range before resolving tsgolint. A stale tsgolint can panic and leave Oxlint with no report.
|
|
51
|
+
|
|
52
|
+
If a selected Oxlint profile needs a missing peer, the preset throws an error naming the peer.
|
|
53
|
+
|
|
54
|
+
When adding ESLint, keep an installed TypeScript version below 6.1 if it satisfies the preset's peer range. If TypeScript is absent, install `typescript@6`. If the installed version is unsupported (including TypeScript 7 or later), report that the ESLint layer needs a supported compiler and ask before replacing it. This applies with `typed: false` too.
|
|
55
|
+
|
|
56
|
+
When `.astro` files are present and the installed version supports Astro, follow the Astro section of the installed `@sonsu-lee/eslint-config` README.
|
|
57
|
+
|
|
58
|
+
## Config skeletons
|
|
59
|
+
|
|
60
|
+
`oxlint.config.mts` (Node.js 22.18+). On older Node.js versions, use `oxlint.config.mjs` and pass `-c oxlint.config.mjs` in every Oxlint script. The `-c` flag disables nested config lookup, so use one root config with this fallback. Pass the selected profiles as the first argument and project-specific Oxlint config as the second.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { preset } from '@sonsu-lee/oxlint-config';
|
|
64
|
+
import { defineConfig } from 'oxlint';
|
|
65
|
+
|
|
66
|
+
export default defineConfig(preset());
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`eslint.config.mjs` (only if ESLint was selected):
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { preset } from '@sonsu-lee/eslint-config';
|
|
73
|
+
|
|
74
|
+
export default preset();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For Astro, compose the two exports as shown in the installed README:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
import { preset } from '@sonsu-lee/eslint-config';
|
|
81
|
+
import { astro } from '@sonsu-lee/eslint-config/astro';
|
|
82
|
+
|
|
83
|
+
export default [...preset(), ...astro()];
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`stylelint.config.mjs`:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
export default { extends: ['@sonsu-lee/stylelint-config'] };
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Pitfalls
|
|
93
|
+
|
|
94
|
+
- Oxlint auto-discovers `.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts`, and `oxlint.config.mts`. Retire old configs when switching.
|
|
95
|
+
- With type-aware Oxlint on, tsgolint uses bundled TypeScript 7. If the tsconfig has `baseUrl`, fold its prefix into `paths` (e.g. `"@/*": ["*"]` under `baseUrl: './src'` becomes `"@/*": ["./src/*"]`) and remove `baseUrl`. If it has `moduleResolution: node`, use `bundler` or `nodenext` to match the project. After edits, run the project's typecheck and build. If the tsconfig cannot change, set `typeAware: false` and report it.
|
|
96
|
+
- Run ESLint from the project root with paths covered by the tsconfig, for example `eslint src`. Do not run bare `eslint`: it can pick up config files outside the tsconfig. For Astro without typed linting and no tsconfig, target the component directory.
|
|
97
|
+
- In a monorepo, run Oxlint per package for package-specific profiles, or use `--disable-nested-config` for a single root config. A nested config with `options.typeAware` fails to load.
|
|
98
|
+
- When ESLint also runs, it reports an `eslint-disable` naming an Oxlint-only rule as an unknown rule. Use `// oxlint-disable-next-line <rule> -- <reason>` instead.
|
|
99
|
+
|
|
100
|
+
## Verify
|
|
101
|
+
|
|
102
|
+
1. Wire the selected commands into the consumer's lint scripts and CI: `oxlint`, `eslint src` (substitute the actual paths), and Stylelint with the quoted glob `"**/*.{css,astro}"` on 0.2.0+ or `"**/*.css"` before it.
|
|
103
|
+
2. Create temporary canaries inside the paths those scripts lint:
|
|
104
|
+
- Type-aware Oxlint: `Promise.resolve('canary');` in a TypeScript file must trigger `typescript(no-floating-promises)`.
|
|
105
|
+
- Any Oxlint configuration: a ternary such as `flag ? 1 : 0` must trigger `no-ternary`.
|
|
106
|
+
- Typed ESLint: `await Promise.resolve('canary').catch(() => {});` in a TypeScript module or Astro frontmatter must trigger `sonsu-lee-eslint/no-ignored-rejection`.
|
|
107
|
+
- Untyped Astro: `<div set:html={"<b>"} />` must trigger `astro/no-set-html-directive`.
|
|
108
|
+
- Stylelint: `.lint-canary { colr: red; }` in CSS or (on 0.2.0+) in an Astro `<style>` block must trigger `property-no-unknown`.
|
|
109
|
+
3. Run each linter separately with its intended arguments. Check the expected diagnostic, not just the exit code, and confirm Oxlint ignores Astro components. Delete all canaries even on failure, then run the normal scripts and report project findings separately from setup failures.
|
|
110
|
+
|
|
111
|
+
## Read more
|
|
112
|
+
|
|
113
|
+
Read the installed `node_modules/@sonsu-lee/*/README.md` for the presets in use.
|