@apify/oxlint-config 0.2.1 → 0.2.3
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 +20 -11
- package/index.d.ts +21 -7
- package/index.js +44 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,23 +16,35 @@ If you want type-aware rules (`typescript/no-floating-promises`, `typescript/awa
|
|
|
16
16
|
npm install --save-dev oxlint-tsgolint
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Add an `oxlint.config.ts` (or `.js`/`.mjs`) at your project root and
|
|
19
|
+
Add an `oxlint.config.ts` (or `.js`/`.mjs`) at your project root and call the package's `defineConfig` with any project-local additions:
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import { defineConfig } from 'oxlint';
|
|
23
|
-
import sharedConfig from '@apify/oxlint-config';
|
|
22
|
+
import { defineConfig } from '@apify/oxlint-config';
|
|
24
23
|
|
|
25
24
|
export default defineConfig({
|
|
26
|
-
...sharedConfig,
|
|
27
25
|
// local plugin additions, e.g. for React projects:
|
|
28
|
-
plugins: [
|
|
26
|
+
plugins: ['react'],
|
|
29
27
|
overrides: [
|
|
30
|
-
...sharedConfig.overrides,
|
|
31
28
|
// local overrides
|
|
32
29
|
],
|
|
33
30
|
});
|
|
34
31
|
```
|
|
35
32
|
|
|
33
|
+
`defineConfig` merges your config on top of the Apify preset (arrays concatenated, objects shallow-merged with consumer winning) and returns a typed `OxlintConfig` that's safe to default-export under `composite` / `--isolatedDeclarations` TypeScript projects.
|
|
34
|
+
|
|
35
|
+
If you'd rather spread the preset manually, the raw config is still the package's default export:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { defineConfig } from 'oxlint';
|
|
39
|
+
import sharedConfig from '@apify/oxlint-config';
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
...sharedConfig,
|
|
43
|
+
plugins: [...sharedConfig.plugins, 'react'],
|
|
44
|
+
overrides: [...sharedConfig.overrides, /* local */],
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
36
48
|
Run lint:
|
|
37
49
|
|
|
38
50
|
```bash
|
|
@@ -43,7 +55,7 @@ npx oxlint --type-aware
|
|
|
43
55
|
|
|
44
56
|
The shared config provides:
|
|
45
57
|
|
|
46
|
-
- **Plugins** — `typescript`, `import`, `unicorn`, `jest`, `promise` (Rust-side, no install required). React plugins are intentionally **not** included; consumers add `'react'` to `plugins` if their project uses React. (Note: oxlint's `react` plugin already covers React Hooks rules; there's no separate `react-hooks` plugin.)
|
|
58
|
+
- **Plugins** — `typescript`, `import`, `unicorn`, `jest`, `vitest`, `promise` (Rust-side, no install required). Both `jest` and `vitest` are enabled because vitest's API is jest-compatible — most of the test best-practices we care about live in the `jest/*` rules and apply equally to vitest tests. The `vitest` plugin adds a few framework-specific rules (e.g. `vitest/hoisted-apis-on-top`, `vitest/no-conditional-tests`) on top. React plugins are intentionally **not** included; consumers add `'react'` to `plugins` if their project uses React. (Note: oxlint's `react` plugin already covers React Hooks rules; there's no separate `react-hooks` plugin.)
|
|
47
59
|
- **Rules** — the Apify house rules: `typescript/consistent-type-imports`, `typescript/no-floating-promises`, `unicorn/prefer-node-protocol`, `import/no-default-export`, `unicorn/no-await-in-promise-methods`, plus the curated `off` list of TypeScript strict rules we don't want.
|
|
48
60
|
- **Overrides** — relaxed rules for test files, vite/jest/vitest config files, story files, and integration test directories.
|
|
49
61
|
|
|
@@ -55,7 +67,6 @@ The shared config does **not** declare `jsPlugins` (the JS-side plugins like `es
|
|
|
55
67
|
|
|
56
68
|
```ts
|
|
57
69
|
export default defineConfig({
|
|
58
|
-
...sharedConfig,
|
|
59
70
|
jsPlugins: [
|
|
60
71
|
{ name: 'storybook', specifier: 'eslint-plugin-storybook' },
|
|
61
72
|
{ name: 'playwright', specifier: 'eslint-plugin-playwright' },
|
|
@@ -65,13 +76,11 @@ export default defineConfig({
|
|
|
65
76
|
|
|
66
77
|
## Overriding rules
|
|
67
78
|
|
|
68
|
-
|
|
79
|
+
Add a `rules` block — your entries win over the preset:
|
|
69
80
|
|
|
70
81
|
```ts
|
|
71
82
|
export default defineConfig({
|
|
72
|
-
...sharedConfig,
|
|
73
83
|
rules: {
|
|
74
|
-
...sharedConfig.rules,
|
|
75
84
|
'no-console': 'off',
|
|
76
85
|
},
|
|
77
86
|
});
|
package/index.d.ts
CHANGED
|
@@ -3,13 +3,7 @@ import type { OxlintConfig } from 'oxlint';
|
|
|
3
3
|
/**
|
|
4
4
|
* Narrow {@link OxlintConfig} so the keys this preset always populates
|
|
5
5
|
* (`plugins`, `overrides`, `rules`, `env`) are non-optional. That lets
|
|
6
|
-
* consumers spread them directly without a non-null assertion
|
|
7
|
-
*
|
|
8
|
-
* export default defineConfig({
|
|
9
|
-
* ...sharedConfig,
|
|
10
|
-
* plugins: [...sharedConfig.plugins, 'react'],
|
|
11
|
-
* overrides: [...sharedConfig.overrides, { ... }],
|
|
12
|
-
* });
|
|
6
|
+
* consumers spread them directly without a non-null assertion.
|
|
13
7
|
*/
|
|
14
8
|
export type ApifyOxlintConfig = OxlintConfig & {
|
|
15
9
|
plugins: NonNullable<OxlintConfig['plugins']>;
|
|
@@ -18,5 +12,25 @@ export type ApifyOxlintConfig = OxlintConfig & {
|
|
|
18
12
|
env: NonNullable<OxlintConfig['env']>;
|
|
19
13
|
};
|
|
20
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Wraps oxlint's `defineConfig` to merge a project-local config on top of
|
|
17
|
+
* the Apify preset. Arrays (`plugins`, `overrides`) are concatenated;
|
|
18
|
+
* objects (`rules`, `env`) are shallow-merged with the consumer winning;
|
|
19
|
+
* everything else (`ignorePatterns`, `jsPlugins`, `categories`, …) is
|
|
20
|
+
* passed through unchanged.
|
|
21
|
+
*
|
|
22
|
+
* Returns `OxlintConfig` (not the narrower `ApifyOxlintConfig`), which is
|
|
23
|
+
* re-exported from oxlint, so default-exporting the result is safe under
|
|
24
|
+
* `composite` / `--isolatedDeclarations` TypeScript projects.
|
|
25
|
+
*
|
|
26
|
+
* import { defineConfig } from '@apify/oxlint-config';
|
|
27
|
+
*
|
|
28
|
+
* export default defineConfig({
|
|
29
|
+
* plugins: ['react'],
|
|
30
|
+
* overrides: [{ files: [...], rules: {...} }],
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export function defineConfig(overrides?: Partial<OxlintConfig>): OxlintConfig;
|
|
34
|
+
|
|
21
35
|
declare const config: ApifyOxlintConfig;
|
|
22
36
|
export default config;
|
package/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
+
import { defineConfig as oxlintDefineConfig } from 'oxlint';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Shared oxlint preset for Apify projects.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* Most consumers should call {@link defineConfig} below — it merges the
|
|
7
|
+
* preset with project-local additions and returns a typed `OxlintConfig`,
|
|
8
|
+
* which avoids declaration-emit issues in `composite` TS projects:
|
|
5
9
|
*
|
|
6
|
-
* import { defineConfig } from 'oxlint';
|
|
7
|
-
* import sharedConfig from '@apify/oxlint-config';
|
|
10
|
+
* import { defineConfig } from '@apify/oxlint-config';
|
|
8
11
|
*
|
|
9
12
|
* export default defineConfig({
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* overrides: [
|
|
13
|
-
* ...sharedConfig.overrides,
|
|
14
|
-
* // local overrides go here
|
|
15
|
-
* ],
|
|
13
|
+
* plugins: ['react'],
|
|
14
|
+
* overrides: [{ files: [...], rules: {...} }],
|
|
16
15
|
* });
|
|
16
|
+
*
|
|
17
|
+
* The raw preset is still exported as the default if you want to spread
|
|
18
|
+
* manually.
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
plugins: ['typescript', 'import', 'unicorn', 'jest', 'promise'],
|
|
20
|
+
const sharedConfig = {
|
|
21
|
+
plugins: ['typescript', 'import', 'unicorn', 'jest', 'vitest', 'promise'],
|
|
20
22
|
env: {
|
|
21
23
|
node: true,
|
|
22
24
|
browser: true,
|
|
@@ -146,6 +148,8 @@ export default {
|
|
|
146
148
|
'jest/no-conditional-expect': 'error',
|
|
147
149
|
'jest/no-focused-tests': 'error',
|
|
148
150
|
'jest/valid-expect': 'off',
|
|
151
|
+
'vitest/hoisted-apis-on-top': 'error',
|
|
152
|
+
'vitest/no-conditional-tests': 'error',
|
|
149
153
|
'import/no-default-export': 'off',
|
|
150
154
|
},
|
|
151
155
|
},
|
|
@@ -167,3 +171,32 @@ export default {
|
|
|
167
171
|
},
|
|
168
172
|
],
|
|
169
173
|
};
|
|
174
|
+
|
|
175
|
+
export default sharedConfig;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Wraps oxlint's `defineConfig` to merge a project-local config on top of
|
|
179
|
+
* the Apify preset. Arrays (`plugins`, `overrides`) are concatenated;
|
|
180
|
+
* objects (`rules`, `env`) are shallow-merged with the consumer winning;
|
|
181
|
+
* everything else (`ignorePatterns`, `jsPlugins`, `categories`, …) is
|
|
182
|
+
* passed through unchanged.
|
|
183
|
+
*
|
|
184
|
+
* @param {Partial<import('oxlint').OxlintConfig>} [overrides]
|
|
185
|
+
* @returns {import('oxlint').OxlintConfig}
|
|
186
|
+
*/
|
|
187
|
+
export function defineConfig(overrides = {}) {
|
|
188
|
+
return oxlintDefineConfig({
|
|
189
|
+
...sharedConfig,
|
|
190
|
+
...overrides,
|
|
191
|
+
plugins: overrides.plugins
|
|
192
|
+
? [...sharedConfig.plugins, ...overrides.plugins]
|
|
193
|
+
: sharedConfig.plugins,
|
|
194
|
+
overrides: overrides.overrides
|
|
195
|
+
? [...sharedConfig.overrides, ...overrides.overrides]
|
|
196
|
+
: sharedConfig.overrides,
|
|
197
|
+
rules: overrides.rules
|
|
198
|
+
? { ...sharedConfig.rules, ...overrides.rules }
|
|
199
|
+
: sharedConfig.rules,
|
|
200
|
+
env: overrides.env ? { ...sharedConfig.env, ...overrides.env } : sharedConfig.env,
|
|
201
|
+
});
|
|
202
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/oxlint-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Apify oxlint preset to be shared between projects.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/apify/apify-oxlint-config"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "echo \"No tests specified\" && exit 0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"oxlint": "
|
|
25
|
+
"oxlint": "^1.61.0"
|
|
26
26
|
},
|
|
27
27
|
"author": "Apify team <info@apify.com>",
|
|
28
28
|
"license": "Apache-2.0"
|