@sonsu-lee/oxlint-config 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +335 -2
- package/dist/index.d.mts +37 -0
- package/dist/index.mjs +257 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sonsu Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,336 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sonsu-lee/oxlint-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Oxlint preset with selectable profiles and per-project rule settings.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D oxlint oxlint-tsgolint @sonsu-lee/oxlint-config
|
|
9
|
+
```
|
|
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 skip `oxlint-tsgolint`.
|
|
12
|
+
|
|
13
|
+
Upgrade `oxlint-tsgolint` together with `oxlint`. An older tsgolint panics on a rule that a newer Oxlint hands it, and Oxlint then prints no report at all.
|
|
14
|
+
|
|
15
|
+
The preset requires Node.js 20.6 or newer: it resolves `@sonsu-lee/oxlint-plugin` with `import.meta.resolve`, which works without a CLI flag from that version.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// oxlint.config.ts
|
|
21
|
+
import { preset } from '@sonsu-lee/oxlint-config';
|
|
22
|
+
import { defineConfig } from 'oxlint';
|
|
23
|
+
|
|
24
|
+
export default defineConfig(
|
|
25
|
+
preset({ node: true, vitest: true, ignores: ['gen/**'] }, { rules: { 'no-console': 'off' } }),
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Use `preset()` as the root config. Do not put it inside another config's `extends`: Oxlint does not inherit `ignorePatterns`, `env`, `globals`, or `settings` through `extends`, so those settings would be lost.
|
|
30
|
+
|
|
31
|
+
The preset includes the rules of [`@sonsu-lee/oxlint-plugin`](../oxlint-plugin) under the `sonsu-lee` namespace. The plugin is installed with the preset, so you do not need to install it separately. To turn a rule off:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
preset({}, { rules: { 'sonsu-lee/no-double-assertion': 'off' } });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Root `rules` take precedence over rule settings in extended configs, but not over their matching `overrides`. To change a rule for those files, add a matching entry to `userConfig.overrides` and list the plugin in that entry. For example, to allow `it.only` in `*.test.ts` files:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
preset(
|
|
41
|
+
{ vitest: true },
|
|
42
|
+
{
|
|
43
|
+
overrides: [
|
|
44
|
+
{
|
|
45
|
+
files: ['**/*.test.ts'],
|
|
46
|
+
plugins: ['vitest'],
|
|
47
|
+
rules: { 'vitest/no-focused-tests': 'off' },
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
### `preset(options?, userConfig?)`
|
|
57
|
+
|
|
58
|
+
Returns a complete Oxlint root config. Oxlint's `correctness`, `suspicious`, `perf`, and `pedantic` categories are on for the plugins of every selected profile; `style`, `restriction`, and `nursery` are off.
|
|
59
|
+
|
|
60
|
+
| Option | Default | Description |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `ignores` | `[]` | Paths to ignore in addition to `**/dist/**` and `**/coverage/**` |
|
|
63
|
+
| `typescript` | `true` | TypeScript plugin |
|
|
64
|
+
| `typeAware` | same as `typescript` | Type-aware rules, replacing overlapping rules. Needs `typescript` |
|
|
65
|
+
| `node` | `false` | Node.js plugin and globals |
|
|
66
|
+
| `browser` | `false` | Browser globals |
|
|
67
|
+
| `react` | `false` | React and React Hooks plugin |
|
|
68
|
+
| `nextjs` | `false` | Next.js core-web-vitals rules; enables React |
|
|
69
|
+
| `tanstackQuery` | `false` | Enables React and two cache rules. Install the peer with `pnpm add -D @tanstack/eslint-plugin-query` |
|
|
70
|
+
| `xstate` | `false` | Five XState v5 machine rules; independent of React |
|
|
71
|
+
| `stylex` | `false` | StyleX rules; install the peer with `pnpm add -D @stylexjs/eslint-plugin` |
|
|
72
|
+
| `vitest` | `false` | Vitest plugin for `*.test.*`, `*.spec.*`, and `*.e2e-spec.*` files |
|
|
73
|
+
| `nestjs` | `false` | Allows code the NestJS CLI generates. Needs `typescript` and turns on `node` |
|
|
74
|
+
|
|
75
|
+
Passing `typescript: false` with `typeAware: true` or `nestjs: true`, or `node: false` with `nestjs: true`, throws an error. 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).
|
|
76
|
+
|
|
77
|
+
If both arguments set `typeAware`, `userConfig.options.typeAware` wins. The same TypeScript requirement applies to that value.
|
|
78
|
+
|
|
79
|
+
`userConfig` is merged as follows:
|
|
80
|
+
|
|
81
|
+
| Field | Behavior |
|
|
82
|
+
| ---------------- | -------------------------------------------------------------- |
|
|
83
|
+
| `ignorePatterns` | Appended after the defaults and `ignores` |
|
|
84
|
+
| `extends` | Applied after the preset, so it takes precedence |
|
|
85
|
+
| `plugins` | Added to the plugins that the selected profiles enable |
|
|
86
|
+
| `env` | Merged by key over the profiles' environments; user values win |
|
|
87
|
+
| `options` | Overrides the preset |
|
|
88
|
+
| Other fields | Used as given |
|
|
89
|
+
|
|
90
|
+
A config in `extends` that omits `plugins` turns Oxlint's default plugins (`unicorn`, `typescript`, `oxc`) back on, so set `plugins: []` or list the plugins it needs.
|
|
91
|
+
|
|
92
|
+
## What the preset reports
|
|
93
|
+
|
|
94
|
+
### Promises nobody waits for
|
|
95
|
+
|
|
96
|
+
**Failure it prevents.** The warehouse rejects a transfer after the order has already been marked as synced.
|
|
97
|
+
|
|
98
|
+
**Reported**
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
void pushToWarehouse(order);
|
|
102
|
+
markSynced(order);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Allowed**
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
await pushToWarehouse(order);
|
|
109
|
+
markSynced(order);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Profile and severity.** The type-aware profile reports an error. Return the promise, await it, or attach a rejection handler. The NestJS profile allows `void bootstrap()` in `main.ts`.
|
|
113
|
+
|
|
114
|
+
**What it cannot see.** JavaScript-only presets without type-aware linting and calls on `any` do not provide the promise type this check needs.
|
|
115
|
+
|
|
116
|
+
### Rejections that are silently dropped
|
|
117
|
+
|
|
118
|
+
**Failure it prevents.** Cache warmup fails but the caller still marks the region ready.
|
|
119
|
+
|
|
120
|
+
**Reported**
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
await warmCache(region).catch(() => {});
|
|
124
|
+
markWarm(region);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Allowed**
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const cached = await readCache(key).catch(() => undefined);
|
|
131
|
+
return cached ?? loadFromDatabase(key);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Profile and severity.** `@sonsu-lee/eslint-config`, not Oxlint, reports `sonsu-lee-eslint/no-ignored-rejection` as an error.
|
|
135
|
+
|
|
136
|
+
**What it cannot see.** The rule does not follow a handler passed by reference or decide whether a log message provides adequate recovery.
|
|
137
|
+
|
|
138
|
+
### Ternaries
|
|
139
|
+
|
|
140
|
+
**Failure it prevents.** A second shipping threshold can be added to the wrong arm of a nested fee calculation.
|
|
141
|
+
|
|
142
|
+
**Reported:** `return member ? 0 : subtotal >= 50 ? 0 : 5;`
|
|
143
|
+
|
|
144
|
+
**Allowed:** `if (member || subtotal >= 50) return 0; return 5;`
|
|
145
|
+
|
|
146
|
+
**Profile and severity.** Base, error, including JSX.
|
|
147
|
+
|
|
148
|
+
**What it cannot see.** The rule detects the operator, not whether the thresholds are correct.
|
|
149
|
+
|
|
150
|
+
### Implicit boolean checks
|
|
151
|
+
|
|
152
|
+
**Failure it prevents.** A missing feature flag takes the disabled path instead of using the account default.
|
|
153
|
+
|
|
154
|
+
**Reported:** `if (flags.betaCheckout)` for an optional boolean; `!!coupon`.
|
|
155
|
+
|
|
156
|
+
**Allowed:** `flags.betaCheckout === true`, `flags.betaCheckout ?? defaults.betaCheckout`, and `Boolean(coupon)`.
|
|
157
|
+
|
|
158
|
+
**Profile and severity.** Base reports double negation; the type-aware profile reports nullable booleans in conditions. Both are errors.
|
|
159
|
+
|
|
160
|
+
**What it cannot see.** `Boolean({ ok: false })` is true. Read `.ok` when the result object carries a success flag. Numeric conversion such as `+quantityText` remains allowed.
|
|
161
|
+
|
|
162
|
+
### Complex inline conditions
|
|
163
|
+
|
|
164
|
+
**Failure it prevents.** A reviewer can miss which checks apply to an administrator and which apply only to the owner.
|
|
165
|
+
|
|
166
|
+
**Reported:** `if (isAdmin || (ownerId === userId && !lockedAt))`.
|
|
167
|
+
|
|
168
|
+
**Allowed:** `if (isAdmin || canEditOwnOrder)`; a two-sided range check such as `price >= min && price <= max`.
|
|
169
|
+
|
|
170
|
+
**Profile and severity.** Base, warning. Keep a short-circuit check inline if extracting it would evaluate a costly callback early and a helper would obscure the order.
|
|
171
|
+
|
|
172
|
+
**What it cannot see.** The rule does not judge names or know what a callback costs. It does not rewrite the expression.
|
|
173
|
+
|
|
174
|
+
### React Hooks
|
|
175
|
+
|
|
176
|
+
**Failure it prevents.** A memo or callback keeps the previous search term when its dependency array omits that term.
|
|
177
|
+
|
|
178
|
+
**Reported:** `useMemo(() => search(term), [])`.
|
|
179
|
+
|
|
180
|
+
**Allowed:** `useMemo(() => search(term), [term])`.
|
|
181
|
+
|
|
182
|
+
**Profile and severity.** The React profile follows the [React Hooks recommended config](https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/index.ts) for these rules:
|
|
183
|
+
|
|
184
|
+
| Rule | Severity |
|
|
185
|
+
| --- | --- |
|
|
186
|
+
| `rules-of-hooks`, `set-state-in-effect`, `set-state-in-render` | Error |
|
|
187
|
+
| `exhaustive-deps`, `incompatible-library` | Warning |
|
|
188
|
+
| `exhaustive-effect-dependencies`, `memo-dependencies`, `no-deriving-state-in-effects` | Off; duplicate findings |
|
|
189
|
+
|
|
190
|
+
**What it cannot see.** A complete dependency list does not establish that a component needs an Effect.
|
|
191
|
+
|
|
192
|
+
### Effects
|
|
193
|
+
|
|
194
|
+
**Failure it prevents.** Copying a derived prop to state in an Effect makes the first render show the previous value.
|
|
195
|
+
|
|
196
|
+
**Reported:** a call to `useEffect`, `useLayoutEffect`, or `useInsertionEffect` without a reason.
|
|
197
|
+
|
|
198
|
+
**Allowed:**
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
// effect: Keep the chat connection subscribed to the room on screen.
|
|
202
|
+
useEffect(() => connect(roomId), [roomId]);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Profile and severity.** React, error. The reason does not suppress dependency or state checks.
|
|
206
|
+
|
|
207
|
+
**What it cannot see.** Re-exports, destructured namespace members, and whether a stated reason is true. For alternatives, see [You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect).
|
|
208
|
+
|
|
209
|
+
### Next.js
|
|
210
|
+
|
|
211
|
+
**Failure it prevents.** A synchronous script delays rendering, and a plain image bypasses Next.js image optimization.
|
|
212
|
+
|
|
213
|
+
**Reported:** `<script src="/checkout.js" />` and `<img src="/hero.png" alt="" />`.
|
|
214
|
+
|
|
215
|
+
**Allowed:** `next/script` and `next/image`.
|
|
216
|
+
|
|
217
|
+
**Profile and severity.** `nextjs` follows the supported rules in `@next/eslint-plugin-next`'s `core-web-vitals` config:
|
|
218
|
+
|
|
219
|
+
| Examples | Severity |
|
|
220
|
+
| ------------------------------------------------------------------------- | -------- |
|
|
221
|
+
| `no-img-element`, `no-head-element`, `no-async-client-component` | Warning |
|
|
222
|
+
| `no-sync-scripts`, `no-html-link-for-pages`, `no-head-import-in-document` | Error |
|
|
223
|
+
|
|
224
|
+
**What it cannot see.** This is not the full `eslint-config-next`: it does not add jsx-a11y or import rules. It sets no global environment because server and client files share a project.
|
|
225
|
+
|
|
226
|
+
### TanStack Query
|
|
227
|
+
|
|
228
|
+
**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.
|
|
229
|
+
|
|
230
|
+
**Reported:** `useQuery({ queryKey: ['order'], queryFn: () => fetchOrder(orderId) })`.
|
|
231
|
+
|
|
232
|
+
**Allowed:** add `orderId` to the key and keep the `QueryClient` at module scope or in a lazy state initializer.
|
|
233
|
+
|
|
234
|
+
**Profile and severity.** `tanstackQuery`, error for `exhaustive-deps` and `stable-query-client`.
|
|
235
|
+
|
|
236
|
+
**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.
|
|
237
|
+
|
|
238
|
+
### XState
|
|
239
|
+
|
|
240
|
+
**Failure it prevents.** Creating an actor during render can leave actors behind. Mutating context changes what earlier snapshots show. An unhandled reservation failure can leave the checkout screen waiting for a transition.
|
|
241
|
+
|
|
242
|
+
**Reported:** `context.items.push(item)` inside `assign`; `createActor(machine)` directly inside a component.
|
|
243
|
+
|
|
244
|
+
**Allowed:** return a new array from `assign`; create the machine at module scope and pass changing values as `input`.
|
|
245
|
+
|
|
246
|
+
**Profile and severity.** `xstate` reports mutation and creation during render as errors. It warns about bare `createMachine`, an invoke with `onDone` but no `onError`, and an object or array selector without a comparator.
|
|
247
|
+
|
|
248
|
+
**What it cannot see.** Re-exports, mutation through a context alias, and selectors on actor contexts imported from another file are outside these syntax checks.
|
|
249
|
+
|
|
250
|
+
Projects that reserve state management for XState can restrict competing packages in their root config:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
preset(
|
|
254
|
+
{ xstate: true },
|
|
255
|
+
{
|
|
256
|
+
rules: {
|
|
257
|
+
'no-restricted-imports': [
|
|
258
|
+
'error',
|
|
259
|
+
{
|
|
260
|
+
paths: [
|
|
261
|
+
'redux',
|
|
262
|
+
'@reduxjs/toolkit',
|
|
263
|
+
'react-redux',
|
|
264
|
+
'zustand',
|
|
265
|
+
'jotai',
|
|
266
|
+
'recoil',
|
|
267
|
+
'mobx',
|
|
268
|
+
'mobx-react-lite',
|
|
269
|
+
'valtio',
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
);
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The profile does not impose this list: a project's root `no-restricted-imports` replaces the whole inherited rule.
|
|
279
|
+
|
|
280
|
+
### StyleX
|
|
281
|
+
|
|
282
|
+
**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.
|
|
283
|
+
|
|
284
|
+
**Reported:** `disply: 'flex'`, `padding: '10px 20px'`, and `<div {...stylex.props(styles.root)} className="row" />`.
|
|
285
|
+
|
|
286
|
+
**Allowed:** the supported property, `paddingTop` and `paddingBottom` in place of the shorthand, and the spread alone.
|
|
287
|
+
|
|
288
|
+
**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.
|
|
289
|
+
|
|
290
|
+
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.
|
|
291
|
+
|
|
292
|
+
**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.
|
|
293
|
+
|
|
294
|
+
## Import boundaries
|
|
295
|
+
|
|
296
|
+
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.
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
preset(
|
|
300
|
+
{ node: true },
|
|
301
|
+
{
|
|
302
|
+
rules: {
|
|
303
|
+
'no-restricted-imports': [
|
|
304
|
+
'error',
|
|
305
|
+
{
|
|
306
|
+
paths: [
|
|
307
|
+
{
|
|
308
|
+
name: '@/vendor/analytics-sdk',
|
|
309
|
+
message: 'Send events through @/logging/track so every event is masked the same way.',
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
patterns: [
|
|
313
|
+
{
|
|
314
|
+
group: ['@/features/*/internal', '@/features/*/internal/**'],
|
|
315
|
+
message: 'Import from the feature entry point, for example @/features/orders.',
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
overrides: [
|
|
322
|
+
{ files: ['src/boundaries/logging/**'], rules: { 'no-restricted-imports': 'off' } },
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
);
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
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.
|
|
329
|
+
|
|
330
|
+
## Contributing
|
|
331
|
+
|
|
332
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md).
|
|
333
|
+
|
|
334
|
+
## License
|
|
335
|
+
|
|
336
|
+
[MIT](LICENSE) © Sonsu Lee
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { OxlintConfig } from "oxlint";
|
|
2
|
+
interface Options {
|
|
3
|
+
/** Paths to ignore in addition to the defaults. */
|
|
4
|
+
ignores?: string[];
|
|
5
|
+
/** TypeScript rules. Default `true`. */
|
|
6
|
+
typescript?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Rules that need type information; needs `oxlint-tsgolint` and `typescript`. Only the root config
|
|
9
|
+
* can enable this, so the preset sets it. Defaults to the value of `typescript`.
|
|
10
|
+
*/
|
|
11
|
+
typeAware?: boolean;
|
|
12
|
+
/** Node.js globals and rules. */
|
|
13
|
+
node?: boolean;
|
|
14
|
+
/** Browser globals. */
|
|
15
|
+
browser?: boolean;
|
|
16
|
+
/** React and React Hooks rules. Turned on by nextjs and tanstackQuery. */
|
|
17
|
+
react?: boolean;
|
|
18
|
+
/** Next.js core-web-vitals severities. Turns on react. */
|
|
19
|
+
nextjs?: boolean;
|
|
20
|
+
/** TanStack Query rules for React; needs @tanstack/eslint-plugin-query. Turns on react. */
|
|
21
|
+
tanstackQuery?: boolean;
|
|
22
|
+
/** XState v5 machine rules. */
|
|
23
|
+
xstate?: boolean;
|
|
24
|
+
/** StyleX rules; needs @stylexjs/eslint-plugin. */
|
|
25
|
+
stylex?: boolean;
|
|
26
|
+
/** Vitest rules for test files. */
|
|
27
|
+
vitest?: boolean;
|
|
28
|
+
/** Adjusts the TypeScript rules for NestJS. Needs `typescript` and turns on `node`. */
|
|
29
|
+
nestjs?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns a complete root config.
|
|
33
|
+
* Oxlint's `extends` does not inherit ignorePatterns, env, globals, or settings,
|
|
34
|
+
* so they are set here instead of in configs/. Do not put the result inside another config's `extends`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function preset(options?: Options, userConfig?: OxlintConfig): OxlintConfig;
|
|
37
|
+
export type { Options };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// src/configs/base.ts
|
|
2
|
+
const base = {
|
|
3
|
+
plugins: ["unicorn", "oxc"],
|
|
4
|
+
categories: {
|
|
5
|
+
correctness: "error",
|
|
6
|
+
suspicious: "error",
|
|
7
|
+
perf: "error",
|
|
8
|
+
pedantic: "error"
|
|
9
|
+
},
|
|
10
|
+
jsPlugins: [{
|
|
11
|
+
name: "sonsu-lee",
|
|
12
|
+
specifier: import.meta.resolve("@sonsu-lee/oxlint-plugin")
|
|
13
|
+
}],
|
|
14
|
+
rules: {
|
|
15
|
+
"sonsu-lee/no-double-assertion": "error",
|
|
16
|
+
"unicorn/no-useless-undefined": ["error", { checkArrowFunctionBody: false }],
|
|
17
|
+
"no-ternary": "error",
|
|
18
|
+
"no-unneeded-ternary": "off",
|
|
19
|
+
"no-implicit-coercion": ["error", {
|
|
20
|
+
boolean: true,
|
|
21
|
+
number: false,
|
|
22
|
+
string: false
|
|
23
|
+
}],
|
|
24
|
+
"sonsu-lee/prefer-named-conditions": "warn"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// src/configs/nestjs.ts
|
|
28
|
+
const nestjs = {
|
|
29
|
+
plugins: [],
|
|
30
|
+
rules: { "typescript/no-extraneous-class": ["error", { allowWithDecorator: true }] },
|
|
31
|
+
overrides: [{
|
|
32
|
+
files: ["**/main.ts"],
|
|
33
|
+
rules: {
|
|
34
|
+
"unicorn/prefer-top-level-await": "off",
|
|
35
|
+
"typescript/no-floating-promises": ["error", { ignoreVoid: true }]
|
|
36
|
+
}
|
|
37
|
+
}]
|
|
38
|
+
};
|
|
39
|
+
// src/configs/nextjs.ts
|
|
40
|
+
const nextjs = {
|
|
41
|
+
plugins: ["nextjs"],
|
|
42
|
+
rules: {
|
|
43
|
+
"nextjs/google-font-display": "warn",
|
|
44
|
+
"nextjs/google-font-preconnect": "warn",
|
|
45
|
+
"nextjs/next-script-for-ga": "warn",
|
|
46
|
+
"nextjs/no-async-client-component": "warn",
|
|
47
|
+
"nextjs/no-before-interactive-script-outside-document": "warn",
|
|
48
|
+
"nextjs/no-css-tags": "warn",
|
|
49
|
+
"nextjs/no-head-element": "warn",
|
|
50
|
+
"nextjs/no-img-element": "warn",
|
|
51
|
+
"nextjs/no-page-custom-font": "warn",
|
|
52
|
+
"nextjs/no-styled-jsx-in-document": "warn",
|
|
53
|
+
"nextjs/no-title-in-document-head": "warn",
|
|
54
|
+
"nextjs/no-typos": "warn",
|
|
55
|
+
"nextjs/no-unwanted-polyfillio": "warn",
|
|
56
|
+
"react/jsx-no-target-blank": "off"
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// src/configs/node.ts
|
|
60
|
+
const node = { plugins: ["node"] };
|
|
61
|
+
// src/configs/react.ts
|
|
62
|
+
const react = {
|
|
63
|
+
plugins: ["react"],
|
|
64
|
+
rules: {
|
|
65
|
+
"react/hooks": "off",
|
|
66
|
+
"react/exhaustive-deps": "warn",
|
|
67
|
+
"react/incompatible-library": "warn",
|
|
68
|
+
"react/exhaustive-effect-dependencies": "off",
|
|
69
|
+
"react/memo-dependencies": "off",
|
|
70
|
+
"react/no-deriving-state-in-effects": "off",
|
|
71
|
+
"sonsu-lee/require-effect-reason": "error",
|
|
72
|
+
"react/react-in-jsx-scope": "off",
|
|
73
|
+
"typescript/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }]
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// src/configs/stylex.ts
|
|
77
|
+
function stylex() {
|
|
78
|
+
let specifier;
|
|
79
|
+
try {
|
|
80
|
+
specifier = import.meta.resolve("@stylexjs/eslint-plugin");
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new Error("stylex needs @stylexjs/eslint-plugin, but it is not installed.", { cause: error });
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
plugins: [],
|
|
86
|
+
jsPlugins: [{
|
|
87
|
+
name: "stylex",
|
|
88
|
+
specifier
|
|
89
|
+
}],
|
|
90
|
+
rules: {
|
|
91
|
+
"stylex/valid-styles": "error",
|
|
92
|
+
"stylex/valid-shorthands": "error",
|
|
93
|
+
"stylex/no-conflicting-props": "error",
|
|
94
|
+
"stylex/no-nonstandard-styles": "error",
|
|
95
|
+
"stylex/no-legacy-contextual-styles": "error",
|
|
96
|
+
"stylex/no-unused": "error",
|
|
97
|
+
"stylex/no-lookahead-selectors": "warn",
|
|
98
|
+
"stylex/sort-keys": "off",
|
|
99
|
+
"stylex/enforce-extension": "off"
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// src/configs/tanstack-query.ts
|
|
104
|
+
function tanstackQuery() {
|
|
105
|
+
let specifier;
|
|
106
|
+
try {
|
|
107
|
+
specifier = import.meta.resolve("@tanstack/eslint-plugin-query");
|
|
108
|
+
} catch (error) {
|
|
109
|
+
throw new Error("tanstackQuery needs @tanstack/eslint-plugin-query, but it is not installed.", { cause: error });
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
plugins: [],
|
|
113
|
+
jsPlugins: [{
|
|
114
|
+
name: "@tanstack/query",
|
|
115
|
+
specifier
|
|
116
|
+
}],
|
|
117
|
+
rules: {
|
|
118
|
+
"@tanstack/query/exhaustive-deps": "error",
|
|
119
|
+
"@tanstack/query/stable-query-client": "error"
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// src/configs/type-aware.ts
|
|
124
|
+
const typeAware = {
|
|
125
|
+
plugins: ["typescript"],
|
|
126
|
+
rules: {
|
|
127
|
+
"typescript/no-floating-promises": ["error", { ignoreVoid: false }],
|
|
128
|
+
"typescript/no-misused-promises": ["error", { checksVoidReturn: {
|
|
129
|
+
arguments: false,
|
|
130
|
+
attributes: false,
|
|
131
|
+
properties: false,
|
|
132
|
+
returns: false,
|
|
133
|
+
variables: false,
|
|
134
|
+
inheritedMethods: true
|
|
135
|
+
} }],
|
|
136
|
+
"typescript/strict-boolean-expressions": ["error", {
|
|
137
|
+
allowNumber: false,
|
|
138
|
+
allowNullableBoolean: false
|
|
139
|
+
}],
|
|
140
|
+
"typescript/prefer-readonly-parameter-types": "off",
|
|
141
|
+
"no-implied-eval": "off",
|
|
142
|
+
"prefer-promise-reject-errors": "off",
|
|
143
|
+
"no-throw-literal": "off",
|
|
144
|
+
"require-await": "off",
|
|
145
|
+
"unicorn/explicit-length-check": "off",
|
|
146
|
+
"unicorn/no-this-assignment": "off",
|
|
147
|
+
"unicorn/prefer-string-starts-ends-with": "off",
|
|
148
|
+
"typescript/use-unknown-in-catch-callback-variable": "error",
|
|
149
|
+
"typescript/prefer-optional-chain": "error",
|
|
150
|
+
"typescript/prefer-string-starts-ends-with": "error"
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
// src/configs/typescript.ts
|
|
154
|
+
const typescript = {
|
|
155
|
+
plugins: ["typescript"],
|
|
156
|
+
rules: { "typescript/ban-types": "off" }
|
|
157
|
+
};
|
|
158
|
+
const vitest = {
|
|
159
|
+
plugins: [],
|
|
160
|
+
overrides: [{
|
|
161
|
+
files: ["**/*.{test,spec}.{js,jsx,ts,tsx,mjs,cjs,mts,cts}", "**/*.e2e-spec.{js,jsx,ts,tsx,mjs,cjs,mts,cts}"],
|
|
162
|
+
plugins: ["vitest"],
|
|
163
|
+
rules: {
|
|
164
|
+
"typescript/no-unsafe-type-assertion": "off",
|
|
165
|
+
"max-lines-per-function": "off",
|
|
166
|
+
"vitest/expect-expect": ["error", { assertFunctionNames: [
|
|
167
|
+
"expect",
|
|
168
|
+
"expectTypeOf",
|
|
169
|
+
"assert",
|
|
170
|
+
"assertType",
|
|
171
|
+
"request.**.expect"
|
|
172
|
+
] }]
|
|
173
|
+
}
|
|
174
|
+
}]
|
|
175
|
+
};
|
|
176
|
+
// src/configs/xstate.ts
|
|
177
|
+
const xstate = {
|
|
178
|
+
plugins: [],
|
|
179
|
+
rules: {
|
|
180
|
+
"sonsu-lee/no-machine-in-render": "error",
|
|
181
|
+
"sonsu-lee/no-machine-context-mutation": "error",
|
|
182
|
+
"sonsu-lee/require-invoke-on-error": "warn",
|
|
183
|
+
"sonsu-lee/prefer-machine-setup": "warn",
|
|
184
|
+
"sonsu-lee/no-unstable-actor-selector": "warn"
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// src/ignores.ts
|
|
188
|
+
const defaultIgnores = ["**/dist/**", "**/coverage/**"];
|
|
189
|
+
// src/preset.ts
|
|
190
|
+
function selectProfiles(options, typeAwareOverride) {
|
|
191
|
+
const isTypeScript = options.typescript ?? true;
|
|
192
|
+
const needsReact = (options.nextjs ?? false) || (options.tanstackQuery ?? false);
|
|
193
|
+
const selected = {
|
|
194
|
+
typescript: isTypeScript,
|
|
195
|
+
typeAware: typeAwareOverride ?? options.typeAware ?? isTypeScript,
|
|
196
|
+
node: options.node ?? options.nestjs ?? false,
|
|
197
|
+
browser: options.browser ?? false,
|
|
198
|
+
react: options.react ?? needsReact,
|
|
199
|
+
nextjs: options.nextjs ?? false,
|
|
200
|
+
tanstackQuery: options.tanstackQuery ?? false,
|
|
201
|
+
xstate: options.xstate ?? false,
|
|
202
|
+
stylex: options.stylex ?? false,
|
|
203
|
+
vitest: options.vitest ?? false,
|
|
204
|
+
nestjs: options.nestjs ?? false
|
|
205
|
+
};
|
|
206
|
+
if (!selected.react && needsReact) throw new Error("nextjs and tanstackQuery need the react profile, but react is false.");
|
|
207
|
+
if (!selected.typescript && (selected.typeAware || selected.nestjs)) throw new Error("typeAware and nestjs need the typescript profile, but typescript is false.");
|
|
208
|
+
if (!selected.node && selected.nestjs) throw new Error("nestjs needs the node profile, but node is false.");
|
|
209
|
+
return selected;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns a complete root config.
|
|
213
|
+
* Oxlint's `extends` does not inherit ignorePatterns, env, globals, or settings,
|
|
214
|
+
* so they are set here instead of in configs/. Do not put the result inside another config's `extends`.
|
|
215
|
+
*/
|
|
216
|
+
function preset(options = {}, userConfig = {}) {
|
|
217
|
+
const selected = selectProfiles(options, userConfig.options?.typeAware);
|
|
218
|
+
const profiles = [
|
|
219
|
+
[selected.typescript, () => typescript],
|
|
220
|
+
[selected.typeAware, () => typeAware],
|
|
221
|
+
[selected.node, () => node],
|
|
222
|
+
[selected.react, () => react],
|
|
223
|
+
[selected.nextjs, () => nextjs],
|
|
224
|
+
[selected.tanstackQuery, tanstackQuery],
|
|
225
|
+
[selected.xstate, () => xstate],
|
|
226
|
+
[selected.stylex, stylex],
|
|
227
|
+
[selected.vitest, () => vitest],
|
|
228
|
+
[selected.nestjs, () => nestjs]
|
|
229
|
+
];
|
|
230
|
+
const extendsConfigs = [
|
|
231
|
+
base,
|
|
232
|
+
...profiles.filter(([isSelected]) => isSelected).map(([, build]) => build()),
|
|
233
|
+
...userConfig.extends ?? []
|
|
234
|
+
];
|
|
235
|
+
const env = {};
|
|
236
|
+
if (selected.node) env.node = true;
|
|
237
|
+
if (selected.browser) env.browser = true;
|
|
238
|
+
return {
|
|
239
|
+
...userConfig,
|
|
240
|
+
plugins: userConfig.plugins ?? [],
|
|
241
|
+
extends: extendsConfigs,
|
|
242
|
+
env: {
|
|
243
|
+
...env,
|
|
244
|
+
...userConfig.env
|
|
245
|
+
},
|
|
246
|
+
ignorePatterns: [
|
|
247
|
+
...defaultIgnores,
|
|
248
|
+
...options.ignores ?? [],
|
|
249
|
+
...userConfig.ignorePatterns ?? []
|
|
250
|
+
],
|
|
251
|
+
options: {
|
|
252
|
+
...userConfig.options,
|
|
253
|
+
typeAware: selected.typeAware
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export { preset };
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonsu-lee/oxlint-config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Oxlint preset with selectable profiles and @sonsu-lee/oxlint-plugin",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/sonsu-lee/style-guide.git",
|
|
9
|
+
"directory": "packages/oxlint-config"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@sonsu-lee/oxlint-plugin": "^0.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@stylexjs/eslint-plugin": "0.19.2",
|
|
29
|
+
"@tanstack/eslint-plugin-query": "5.108.4",
|
|
30
|
+
"@types/node": "24.19.2",
|
|
31
|
+
"oxlint": "1.90.0",
|
|
32
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
33
|
+
"tsdown": "0.23.4",
|
|
34
|
+
"typescript": "7.0.2",
|
|
35
|
+
"vitest": "5.0.5"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@stylexjs/eslint-plugin": "^0.19.0",
|
|
39
|
+
"@tanstack/eslint-plugin-query": "^5.108.0",
|
|
40
|
+
"oxlint": "^1.90.0",
|
|
41
|
+
"oxlint-tsgolint": "^7.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@stylexjs/eslint-plugin": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@tanstack/eslint-plugin-query": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.6.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"typecheck": "tsc",
|
|
58
|
+
"lint": "oxlint"
|
|
59
|
+
}
|
|
6
60
|
}
|