@qlik/eslint-config 1.1.0 → 1.1.1

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 CHANGED
@@ -63,7 +63,7 @@ export default qlik.compose(
63
63
  ...qlik.configs.recommended, // adds linting on .js, .jsx, .mjs, .cjs, .ts, .tsx, .cts, .mts files. use for pure browser environment
64
64
  {
65
65
  ignores: ["dist", "npm", "node_modules"],
66
- }
66
+ },
67
67
  );
68
68
  ```
69
69
 
@@ -91,7 +91,7 @@ export default qlik.compose(
91
91
  ...qlik.configs.svelte, // based on the recommended config and adds svelte linting on .svelte files
92
92
  {
93
93
  ignores: ["dist", "node_modules"],
94
- }
94
+ },
95
95
  );
96
96
  ```
97
97
 
@@ -106,7 +106,7 @@ export default qlik.compose(
106
106
  ...qlik.configs.svelte,
107
107
  {
108
108
  ignores: ["dist", "node_modules"],
109
- }
109
+ },
110
110
  );
111
111
  ```
112
112
 
@@ -152,7 +152,7 @@ Example only use javascript rules with react
152
152
  import qlik, { recommendedJS, reactJS } from "@qlik/eslint-config";
153
153
 
154
154
  export default qlik.compose(
155
- reactJS
155
+ reactJS,
156
156
  )
157
157
  ```
158
158
 
@@ -163,7 +163,7 @@ import qlik, { recommendedJS, reactJS } from "@qlik/eslint-config";
163
163
 
164
164
  export default qlik.compose(
165
165
  reactJS,
166
- reactTS
166
+ reactTS,
167
167
  )
168
168
  ```
169
169
 
@@ -173,7 +173,7 @@ This is equal to:
173
173
  import qlik from "@qlik/eslint-config";
174
174
 
175
175
  export default qlik.compose(
176
- ...qlik.configs.react
176
+ ...qlik.configs.react,
177
177
  )
178
178
  ```
179
179
 
@@ -195,6 +195,86 @@ export default qlik.compose(
195
195
 
196
196
  ```
197
197
 
198
+ This will take the configs in the `extend` array and perform a deep merge of whatever is defined in the object containing
199
+ the `extend` property with the configs in the `extend` array and return them as separate configs. The deep merge has three
200
+ exceptions. `files`, `ignores` and `globals` are always overwritten by the later config.
201
+
202
+ ```js
203
+ import qlik, { esmJS } from "@qlik/eslint-config";
204
+
205
+ export default qlik.compose(
206
+ {
207
+ extend: [...qlik.configs.recommended], // contains two configs (recommendedJS and recommendedTS)
208
+ files: ["only_want_lint_here/**/*.js"],
209
+ },
210
+ )
211
+ ```
212
+
213
+ This will result in two configs, each with the given file pattern like this:
214
+
215
+ ```js
216
+ export default [
217
+ {
218
+ ...recommendedJS config
219
+ files: ["only_want_lint_here/**/*.js"],
220
+ },
221
+ {
222
+ ...recommendedTS config
223
+ files: ["only_want_lint_here/**/*.js"],
224
+ }
225
+ ]
226
+ ```
227
+
228
+ ### More examples with export
229
+
230
+ One GOTCHA about the flat configs. If there's no `files` property in one of the configs in the config array it is applied
231
+ to every file. So in the case of turning off a rule that belongs to specific config e.g. jest or vitest. The following
232
+ approach does NOT work.
233
+
234
+ ```js
235
+ // @ts-check
236
+ import qlik from "@qlik/eslint-config";
237
+
238
+ export default qlik.compose(
239
+ ...qlik.configs.recommended,
240
+ qlik.configs.vitest, // <-- this is applied to files inside __test(s)__ folders by default for our convenience
241
+ {
242
+ rules: {
243
+ // I want to change this rule, but it doesn't work because it is applied to all files
244
+ "vitest/max-nested-describe": [
245
+ "error",
246
+ {
247
+ "max": 3
248
+ },
249
+ ],
250
+ },
251
+ },
252
+ );
253
+ ```
254
+
255
+ Here the `extend` feature becomes helpful
256
+
257
+ ```js
258
+ // @ts-check
259
+ import qlik from "@qlik/eslint-config";
260
+
261
+ export default qlik.compose(
262
+ ...qlik.configs.recommended,
263
+ {
264
+ extend: [qlik.configs.vitest],
265
+ rules: {
266
+ // This will add or overwrite the rule in the default config
267
+ "vitest/max-nested-describe": [
268
+ "error",
269
+ {
270
+ "max": 3
271
+ },
272
+ ],
273
+ },
274
+ },
275
+ );
276
+ ```
277
+
198
278
  Example of changing the default file patterns on the vitest config.
199
279
 
200
280
  ```js
@@ -216,10 +296,33 @@ export default qlik.compose(
216
296
  ]
217
297
  }
218
298
  },
299
+ );
300
+ ```
301
+
302
+ This will result in a final config looking like this:
303
+
304
+ ```js
305
+ export default [
306
+ {
307
+ ...recommendedJS config
308
+ },
219
309
  {
220
- ignores: ["dist", "npm", "node_modules"],
310
+ ...recommendedTS config
221
311
  },
222
- );
312
+ {
313
+ files: ['**/my_tests_are_here/*.spec.ts'],
314
+ ...vitest config
315
+ rules: {
316
+ ... vitest config rules,
317
+ "vitest/max-nested-describe": [
318
+ "error",
319
+ {
320
+ "max": 3
321
+ }
322
+ ]
323
+ }
324
+ }
325
+ ]
223
326
  ```
224
327
 
225
328
  <!-- prettier-ignore-end -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlik/eslint-config",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Qlik's ESLint configs",
5
5
  "repository": "git@github.com:qlik-oss/dev-tools-js.git",
6
6
  "license": "ISC",
@@ -1,4 +1,7 @@
1
1
  // @ts-check
2
+
3
+ import { mergeConfigs } from "./config.js";
4
+
2
5
  /**
3
6
  * Utility function to make it easy to strictly type your "Flat" config file
4
7
  *
@@ -33,6 +36,7 @@ export default function compose(...configs) {
33
36
  if (extendArr == null || extendArr.length === 0) {
34
37
  return config;
35
38
  }
39
+
36
40
  const undefinedExtensions = extendArr.reduce((acc, extension, extensionIndex) => {
37
41
  const maybeExtension = extension;
38
42
  if (maybeExtension == null) {
@@ -52,14 +56,8 @@ export default function compose(...configs) {
52
56
  return [
53
57
  ...extendArr.map((extension) => {
54
58
  const name = [config.name, extension.name].filter(Boolean).join("__");
55
- return {
56
- ...extension,
57
- ...(config.files && { files: config.files }),
58
- ...(config.ignores && { ignores: config.ignores }),
59
- ...(name && { name }),
60
- };
59
+ return mergeConfigs(extension, config, name ? { name } : {});
61
60
  }),
62
- config,
63
61
  ];
64
62
  });
65
63
  }
@@ -1,6 +1,6 @@
1
1
  // these ones will only do shallow merge, but the merge function will do deep merge
2
2
  const noNeedToDeepMerge = ["plugins", "rules", "parser"];
3
- const overWrite = ["files", "globals"];
3
+ const overWrite = ["files", "globals", "ignores"];
4
4
 
5
5
  /**
6
6
  *