@apify/oxlint-config 0.2.1 → 0.2.2

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.
Files changed (4) hide show
  1. package/README.md +19 -10
  2. package/index.d.ts +21 -7
  3. package/index.js +41 -10
  4. 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 spread the preset into it:
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: [...sharedConfig.plugins, 'react'],
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
@@ -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
- Spread the preset and add your own `rules` block — yours win over the preset:
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,21 +1,23 @@
1
+ import { defineConfig as oxlintDefineConfig } from 'oxlint';
2
+
1
3
  /**
2
4
  * Shared oxlint preset for Apify projects.
3
5
  *
4
- * Spread it into your `oxlint.config.{ts,js,mjs}`:
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
- * ...sharedConfig,
11
- * plugins: [...sharedConfig.plugins, 'react'],
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
- export default {
20
+ const sharedConfig = {
19
21
  plugins: ['typescript', 'import', 'unicorn', 'jest', 'promise'],
20
22
  env: {
21
23
  node: true,
@@ -167,3 +169,32 @@ export default {
167
169
  },
168
170
  ],
169
171
  };
172
+
173
+ export default sharedConfig;
174
+
175
+ /**
176
+ * Wraps oxlint's `defineConfig` to merge a project-local config on top of
177
+ * the Apify preset. Arrays (`plugins`, `overrides`) are concatenated;
178
+ * objects (`rules`, `env`) are shallow-merged with the consumer winning;
179
+ * everything else (`ignorePatterns`, `jsPlugins`, `categories`, …) is
180
+ * passed through unchanged.
181
+ *
182
+ * @param {Partial<import('oxlint').OxlintConfig>} [overrides]
183
+ * @returns {import('oxlint').OxlintConfig}
184
+ */
185
+ export function defineConfig(overrides = {}) {
186
+ return oxlintDefineConfig({
187
+ ...sharedConfig,
188
+ ...overrides,
189
+ plugins: overrides.plugins
190
+ ? [...sharedConfig.plugins, ...overrides.plugins]
191
+ : sharedConfig.plugins,
192
+ overrides: overrides.overrides
193
+ ? [...sharedConfig.overrides, ...overrides.overrides]
194
+ : sharedConfig.overrides,
195
+ rules: overrides.rules
196
+ ? { ...sharedConfig.rules, ...overrides.rules }
197
+ : sharedConfig.rules,
198
+ env: overrides.env ? { ...sharedConfig.env, ...overrides.env } : sharedConfig.env,
199
+ });
200
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/oxlint-config",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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": ">=1.60.0"
25
+ "oxlint": "^1.61.0"
26
26
  },
27
27
  "author": "Apify team <info@apify.com>",
28
28
  "license": "Apache-2.0"