@tb-dev/eslint-config 5.2.4 → 5.3.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/dist/index.cjs CHANGED
@@ -28,12 +28,31 @@ async function interopDefault(promise) {
28
28
  const result = await promise;
29
29
  return result.default ?? result;
30
30
  }
31
+ function isEnabled(config, feature) {
32
+ if (Array.isArray(config)) {
33
+ return config.includes(feature);
34
+ } else if (typeof config === "boolean") {
35
+ return config;
36
+ }
37
+ switch (feature) {
38
+ case "perfectionist":
39
+ return config?.perfectionist ?? true;
40
+ case "tailwind":
41
+ return config?.tailwind ?? false;
42
+ case "unicorn":
43
+ return config?.unicorn ?? true;
44
+ case "vue":
45
+ return config?.vue ?? false;
46
+ default:
47
+ return false;
48
+ }
49
+ }
31
50
  function getIgnores() {
32
51
  return Object.values(GlobIgnore);
33
52
  }
34
53
 
35
54
  async function vue(options) {
36
- if (!options.features?.vue) return [];
55
+ if (!isEnabled(options.features, "vue")) return [];
37
56
  const [vuePlugin, vueParser, tsParser] = await Promise.all([
38
57
  // @ts-expect-error no types
39
58
  interopDefault(import('eslint-plugin-vue')),
@@ -258,8 +277,7 @@ async function vue(options) {
258
277
  }
259
278
 
260
279
  async function unicorn(options) {
261
- const { unicorn: enabled = true } = options.features ?? {};
262
- if (!enabled) return {};
280
+ if (!isEnabled(options.features, "unicorn")) return {};
263
281
  const plugin = await interopDefault(import('eslint-plugin-unicorn'));
264
282
  return {
265
283
  plugins: { unicorn: plugin },
@@ -310,7 +328,7 @@ async function unicorn(options) {
310
328
  }
311
329
 
312
330
  async function tailwind(options) {
313
- if (!options.features?.tailwind) return {};
331
+ if (!isEnabled(options.features, "tailwind")) return {};
314
332
  const plugin = await interopDefault(import('eslint-plugin-tailwindcss'));
315
333
  const callees = ["classnames", "clsx", "cn", "ctl", "cva", "tv"];
316
334
  const rules = {
@@ -326,7 +344,9 @@ async function tailwind(options) {
326
344
 
327
345
  function javascript(options) {
328
346
  const files = [Glob.All];
329
- if (options.features?.vue) files.push(Glob.Vue);
347
+ if (isEnabled(options.features, "vue")) {
348
+ files.push(Glob.Vue);
349
+ }
330
350
  return {
331
351
  files,
332
352
  languageOptions: {
@@ -483,7 +503,9 @@ async function typescript(options) {
483
503
  interopDefault(import('@typescript-eslint/eslint-plugin'))
484
504
  ]);
485
505
  const files = [Glob.Typescript];
486
- if (options.features?.vue) files.push(Glob.Vue);
506
+ if (isEnabled(options.features, "vue")) {
507
+ files.push(Glob.Vue);
508
+ }
487
509
  const rules = {
488
510
  "@typescript-eslint/adjacent-overload-signatures": "error",
489
511
  "no-array-constructor": "off",
@@ -729,6 +751,10 @@ async function typescript(options) {
729
751
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
730
752
  ...options.overrides?.typescript
731
753
  };
754
+ const extraFileExtensions = [];
755
+ if (isEnabled(options.features, "vue")) {
756
+ extraFileExtensions.push(".vue");
757
+ }
732
758
  return {
733
759
  files,
734
760
  languageOptions: {
@@ -738,7 +764,7 @@ async function typescript(options) {
738
764
  parserOptions: {
739
765
  project: options.project,
740
766
  tsconfigRootDir: process.cwd(),
741
- extraFileExtensions: options.features?.vue ? [".vue"] : []
767
+ extraFileExtensions
742
768
  }
743
769
  },
744
770
  plugins: { "@typescript-eslint": tsPlugin },
@@ -747,8 +773,7 @@ async function typescript(options) {
747
773
  }
748
774
 
749
775
  async function perfectionist(options) {
750
- const { perfectionist: enabled = true } = options.features ?? {};
751
- if (!enabled) return {};
776
+ if (!isEnabled(options.features, "perfectionist")) return {};
752
777
  const plugin = await interopDefault(import('eslint-plugin-perfectionist'));
753
778
  return {
754
779
  plugins: { perfectionist: plugin },
@@ -792,6 +817,7 @@ async function perfectionist(options) {
792
817
  {
793
818
  type: "natural",
794
819
  order: "asc",
820
+ ignoreCase: true,
795
821
  partitionByNewLine: true
796
822
  }
797
823
  ],
package/dist/index.d.ts CHANGED
@@ -15,16 +15,7 @@ declare interface ConfigObject {
15
15
  }
16
16
 
17
17
  declare interface ConfigOptions {
18
- features?: {
19
- /** @default true */
20
- perfectionist?: boolean;
21
- /** @default false */
22
- tailwind?: boolean;
23
- /** @default true */
24
- unicorn?: boolean;
25
- /** @default false */
26
- vue?: boolean;
27
- };
18
+ features?: FeaturesObject | (keyof FeaturesObject)[] | boolean;
28
19
  /** `tsconfig.json` files for TypeScript. */
29
20
  project: string[];
30
21
  ignores?: Ignores['ignores'];
@@ -42,6 +33,17 @@ declare interface ConfigOptions {
42
33
 
43
34
  export declare function defineConfig(options: ConfigOptions): Promise<Partial<ConfigObject>[]>;
44
35
 
36
+ declare interface FeaturesObject {
37
+ /** @default true */
38
+ perfectionist?: boolean;
39
+ /** @default false */
40
+ tailwind?: boolean;
41
+ /** @default true */
42
+ unicorn?: boolean;
43
+ /** @default false */
44
+ vue?: boolean;
45
+ }
46
+
45
47
  declare interface Ignores {
46
48
  ignores: string[];
47
49
  }
package/dist/index.js CHANGED
@@ -24,12 +24,31 @@ async function interopDefault(promise) {
24
24
  const result = await promise;
25
25
  return result.default ?? result;
26
26
  }
27
+ function isEnabled(config, feature) {
28
+ if (Array.isArray(config)) {
29
+ return config.includes(feature);
30
+ } else if (typeof config === "boolean") {
31
+ return config;
32
+ }
33
+ switch (feature) {
34
+ case "perfectionist":
35
+ return config?.perfectionist ?? true;
36
+ case "tailwind":
37
+ return config?.tailwind ?? false;
38
+ case "unicorn":
39
+ return config?.unicorn ?? true;
40
+ case "vue":
41
+ return config?.vue ?? false;
42
+ default:
43
+ return false;
44
+ }
45
+ }
27
46
  function getIgnores() {
28
47
  return Object.values(GlobIgnore);
29
48
  }
30
49
 
31
50
  async function vue(options) {
32
- if (!options.features?.vue) return [];
51
+ if (!isEnabled(options.features, "vue")) return [];
33
52
  const [vuePlugin, vueParser, tsParser] = await Promise.all([
34
53
  // @ts-expect-error no types
35
54
  interopDefault(import('eslint-plugin-vue')),
@@ -254,8 +273,7 @@ async function vue(options) {
254
273
  }
255
274
 
256
275
  async function unicorn(options) {
257
- const { unicorn: enabled = true } = options.features ?? {};
258
- if (!enabled) return {};
276
+ if (!isEnabled(options.features, "unicorn")) return {};
259
277
  const plugin = await interopDefault(import('eslint-plugin-unicorn'));
260
278
  return {
261
279
  plugins: { unicorn: plugin },
@@ -306,7 +324,7 @@ async function unicorn(options) {
306
324
  }
307
325
 
308
326
  async function tailwind(options) {
309
- if (!options.features?.tailwind) return {};
327
+ if (!isEnabled(options.features, "tailwind")) return {};
310
328
  const plugin = await interopDefault(import('eslint-plugin-tailwindcss'));
311
329
  const callees = ["classnames", "clsx", "cn", "ctl", "cva", "tv"];
312
330
  const rules = {
@@ -322,7 +340,9 @@ async function tailwind(options) {
322
340
 
323
341
  function javascript(options) {
324
342
  const files = [Glob.All];
325
- if (options.features?.vue) files.push(Glob.Vue);
343
+ if (isEnabled(options.features, "vue")) {
344
+ files.push(Glob.Vue);
345
+ }
326
346
  return {
327
347
  files,
328
348
  languageOptions: {
@@ -479,7 +499,9 @@ async function typescript(options) {
479
499
  interopDefault(import('@typescript-eslint/eslint-plugin'))
480
500
  ]);
481
501
  const files = [Glob.Typescript];
482
- if (options.features?.vue) files.push(Glob.Vue);
502
+ if (isEnabled(options.features, "vue")) {
503
+ files.push(Glob.Vue);
504
+ }
483
505
  const rules = {
484
506
  "@typescript-eslint/adjacent-overload-signatures": "error",
485
507
  "no-array-constructor": "off",
@@ -725,6 +747,10 @@ async function typescript(options) {
725
747
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
726
748
  ...options.overrides?.typescript
727
749
  };
750
+ const extraFileExtensions = [];
751
+ if (isEnabled(options.features, "vue")) {
752
+ extraFileExtensions.push(".vue");
753
+ }
728
754
  return {
729
755
  files,
730
756
  languageOptions: {
@@ -734,7 +760,7 @@ async function typescript(options) {
734
760
  parserOptions: {
735
761
  project: options.project,
736
762
  tsconfigRootDir: process.cwd(),
737
- extraFileExtensions: options.features?.vue ? [".vue"] : []
763
+ extraFileExtensions
738
764
  }
739
765
  },
740
766
  plugins: { "@typescript-eslint": tsPlugin },
@@ -743,8 +769,7 @@ async function typescript(options) {
743
769
  }
744
770
 
745
771
  async function perfectionist(options) {
746
- const { perfectionist: enabled = true } = options.features ?? {};
747
- if (!enabled) return {};
772
+ if (!isEnabled(options.features, "perfectionist")) return {};
748
773
  const plugin = await interopDefault(import('eslint-plugin-perfectionist'));
749
774
  return {
750
775
  plugins: { perfectionist: plugin },
@@ -788,6 +813,7 @@ async function perfectionist(options) {
788
813
  {
789
814
  type: "natural",
790
815
  order: "asc",
816
+ ignoreCase: true,
791
817
  partitionByNewLine: true
792
818
  }
793
819
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/eslint-config",
3
- "version": "5.2.4",
3
+ "version": "5.3.1",
4
4
  "description": "ESLint config",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "prettier": "^3.3.3",
41
41
  "tslib": "^2.7.0",
42
42
  "typescript": "^5.6.2",
43
- "vite": "^5.4.3",
43
+ "vite": "^5.4.4",
44
44
  "vite-plugin-dts": "^4.2.1"
45
45
  },
46
46
  "peerDependencies": {