@tb-dev/eslint-config 5.2.4 → 5.3.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/dist/index.cjs CHANGED
@@ -28,12 +28,27 @@ 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)) return config.includes(feature);
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
+ }
31
46
  function getIgnores() {
32
47
  return Object.values(GlobIgnore);
33
48
  }
34
49
 
35
50
  async function vue(options) {
36
- if (!options.features?.vue) return [];
51
+ if (!isEnabled(options.features, "vue")) return [];
37
52
  const [vuePlugin, vueParser, tsParser] = await Promise.all([
38
53
  // @ts-expect-error no types
39
54
  interopDefault(import('eslint-plugin-vue')),
@@ -258,8 +273,7 @@ async function vue(options) {
258
273
  }
259
274
 
260
275
  async function unicorn(options) {
261
- const { unicorn: enabled = true } = options.features ?? {};
262
- if (!enabled) return {};
276
+ if (!isEnabled(options.features, "unicorn")) return {};
263
277
  const plugin = await interopDefault(import('eslint-plugin-unicorn'));
264
278
  return {
265
279
  plugins: { unicorn: plugin },
@@ -310,7 +324,7 @@ async function unicorn(options) {
310
324
  }
311
325
 
312
326
  async function tailwind(options) {
313
- if (!options.features?.tailwind) return {};
327
+ if (!isEnabled(options.features, "tailwind")) return {};
314
328
  const plugin = await interopDefault(import('eslint-plugin-tailwindcss'));
315
329
  const callees = ["classnames", "clsx", "cn", "ctl", "cva", "tv"];
316
330
  const rules = {
@@ -326,7 +340,9 @@ async function tailwind(options) {
326
340
 
327
341
  function javascript(options) {
328
342
  const files = [Glob.All];
329
- if (options.features?.vue) files.push(Glob.Vue);
343
+ if (isEnabled(options.features, "vue")) {
344
+ files.push(Glob.Vue);
345
+ }
330
346
  return {
331
347
  files,
332
348
  languageOptions: {
@@ -483,7 +499,9 @@ async function typescript(options) {
483
499
  interopDefault(import('@typescript-eslint/eslint-plugin'))
484
500
  ]);
485
501
  const files = [Glob.Typescript];
486
- if (options.features?.vue) files.push(Glob.Vue);
502
+ if (isEnabled(options.features, "vue")) {
503
+ files.push(Glob.Vue);
504
+ }
487
505
  const rules = {
488
506
  "@typescript-eslint/adjacent-overload-signatures": "error",
489
507
  "no-array-constructor": "off",
@@ -729,6 +747,10 @@ async function typescript(options) {
729
747
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
730
748
  ...options.overrides?.typescript
731
749
  };
750
+ const extraFileExtensions = [];
751
+ if (isEnabled(options.features, "vue")) {
752
+ extraFileExtensions.push(".vue");
753
+ }
732
754
  return {
733
755
  files,
734
756
  languageOptions: {
@@ -738,7 +760,7 @@ async function typescript(options) {
738
760
  parserOptions: {
739
761
  project: options.project,
740
762
  tsconfigRootDir: process.cwd(),
741
- extraFileExtensions: options.features?.vue ? [".vue"] : []
763
+ extraFileExtensions
742
764
  }
743
765
  },
744
766
  plugins: { "@typescript-eslint": tsPlugin },
@@ -747,8 +769,7 @@ async function typescript(options) {
747
769
  }
748
770
 
749
771
  async function perfectionist(options) {
750
- const { perfectionist: enabled = true } = options.features ?? {};
751
- if (!enabled) return {};
772
+ if (!isEnabled(options.features, "perfectionist")) return {};
752
773
  const plugin = await interopDefault(import('eslint-plugin-perfectionist'));
753
774
  return {
754
775
  plugins: { perfectionist: plugin },
@@ -792,6 +813,7 @@ async function perfectionist(options) {
792
813
  {
793
814
  type: "natural",
794
815
  order: "asc",
816
+ ignoreCase: true,
795
817
  partitionByNewLine: true
796
818
  }
797
819
  ],
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)[];
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,27 @@ 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)) return config.includes(feature);
29
+ switch (feature) {
30
+ case "perfectionist":
31
+ return config?.perfectionist ?? true;
32
+ case "tailwind":
33
+ return config?.tailwind ?? false;
34
+ case "unicorn":
35
+ return config?.unicorn ?? true;
36
+ case "vue":
37
+ return config?.vue ?? false;
38
+ default:
39
+ return false;
40
+ }
41
+ }
27
42
  function getIgnores() {
28
43
  return Object.values(GlobIgnore);
29
44
  }
30
45
 
31
46
  async function vue(options) {
32
- if (!options.features?.vue) return [];
47
+ if (!isEnabled(options.features, "vue")) return [];
33
48
  const [vuePlugin, vueParser, tsParser] = await Promise.all([
34
49
  // @ts-expect-error no types
35
50
  interopDefault(import('eslint-plugin-vue')),
@@ -254,8 +269,7 @@ async function vue(options) {
254
269
  }
255
270
 
256
271
  async function unicorn(options) {
257
- const { unicorn: enabled = true } = options.features ?? {};
258
- if (!enabled) return {};
272
+ if (!isEnabled(options.features, "unicorn")) return {};
259
273
  const plugin = await interopDefault(import('eslint-plugin-unicorn'));
260
274
  return {
261
275
  plugins: { unicorn: plugin },
@@ -306,7 +320,7 @@ async function unicorn(options) {
306
320
  }
307
321
 
308
322
  async function tailwind(options) {
309
- if (!options.features?.tailwind) return {};
323
+ if (!isEnabled(options.features, "tailwind")) return {};
310
324
  const plugin = await interopDefault(import('eslint-plugin-tailwindcss'));
311
325
  const callees = ["classnames", "clsx", "cn", "ctl", "cva", "tv"];
312
326
  const rules = {
@@ -322,7 +336,9 @@ async function tailwind(options) {
322
336
 
323
337
  function javascript(options) {
324
338
  const files = [Glob.All];
325
- if (options.features?.vue) files.push(Glob.Vue);
339
+ if (isEnabled(options.features, "vue")) {
340
+ files.push(Glob.Vue);
341
+ }
326
342
  return {
327
343
  files,
328
344
  languageOptions: {
@@ -479,7 +495,9 @@ async function typescript(options) {
479
495
  interopDefault(import('@typescript-eslint/eslint-plugin'))
480
496
  ]);
481
497
  const files = [Glob.Typescript];
482
- if (options.features?.vue) files.push(Glob.Vue);
498
+ if (isEnabled(options.features, "vue")) {
499
+ files.push(Glob.Vue);
500
+ }
483
501
  const rules = {
484
502
  "@typescript-eslint/adjacent-overload-signatures": "error",
485
503
  "no-array-constructor": "off",
@@ -725,6 +743,10 @@ async function typescript(options) {
725
743
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
726
744
  ...options.overrides?.typescript
727
745
  };
746
+ const extraFileExtensions = [];
747
+ if (isEnabled(options.features, "vue")) {
748
+ extraFileExtensions.push(".vue");
749
+ }
728
750
  return {
729
751
  files,
730
752
  languageOptions: {
@@ -734,7 +756,7 @@ async function typescript(options) {
734
756
  parserOptions: {
735
757
  project: options.project,
736
758
  tsconfigRootDir: process.cwd(),
737
- extraFileExtensions: options.features?.vue ? [".vue"] : []
759
+ extraFileExtensions
738
760
  }
739
761
  },
740
762
  plugins: { "@typescript-eslint": tsPlugin },
@@ -743,8 +765,7 @@ async function typescript(options) {
743
765
  }
744
766
 
745
767
  async function perfectionist(options) {
746
- const { perfectionist: enabled = true } = options.features ?? {};
747
- if (!enabled) return {};
768
+ if (!isEnabled(options.features, "perfectionist")) return {};
748
769
  const plugin = await interopDefault(import('eslint-plugin-perfectionist'));
749
770
  return {
750
771
  plugins: { perfectionist: plugin },
@@ -788,6 +809,7 @@ async function perfectionist(options) {
788
809
  {
789
810
  type: "natural",
790
811
  order: "asc",
812
+ ignoreCase: true,
791
813
  partitionByNewLine: true
792
814
  }
793
815
  ],
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.0",
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": {