@vp-tw/eslint-config 0.0.23 → 0.0.25

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 (45) hide show
  1. package/dist/configs/mdx.js +3 -4
  2. package/dist/configs/packageJson.js +4 -3
  3. package/dist/configs/prettier.js +2 -3
  4. package/dist/configs/reactCompiler.d.ts +2 -2
  5. package/dist/configs/reactCompiler.js +3 -4
  6. package/dist/configs/storybook.js +3 -4
  7. package/dist/eslint-typegen.d.ts +1 -1
  8. package/dist/esm/configs/mdx.mjs +3 -3
  9. package/dist/esm/configs/packageJson.mjs +4 -2
  10. package/dist/esm/configs/prettier.mjs +6 -9
  11. package/dist/esm/configs/reactCompiler.d.ts +2 -2
  12. package/dist/esm/configs/reactCompiler.mjs +3 -3
  13. package/dist/esm/configs/storybook.mjs +3 -3
  14. package/dist/esm/eslint-typegen.d.ts +1 -1
  15. package/dist/esm/extends/imports.mjs +10 -13
  16. package/dist/esm/extends/javascript.mjs +6 -3
  17. package/dist/esm/extends/jsonc.mjs +10 -7
  18. package/dist/esm/extends/react.mjs +7 -4
  19. package/dist/esm/extends/sort.d.ts +11 -19
  20. package/dist/esm/extends/sort.mjs +65 -76
  21. package/dist/esm/extends/typescript.mjs +6 -3
  22. package/dist/esm/extends/yaml.mjs +7 -4
  23. package/dist/esm/globs.d.ts +2 -1
  24. package/dist/esm/globs.mjs +3 -1
  25. package/dist/esm/types.d.ts +8 -2
  26. package/dist/esm/utils/mergeConfig.d.ts +3 -0
  27. package/dist/esm/utils/mergeConfig.mjs +56 -0
  28. package/dist/esm/vdustr.d.ts +10 -11
  29. package/dist/esm/vdustr.mjs +37 -34
  30. package/dist/extends/imports.js +6 -7
  31. package/dist/extends/javascript.js +3 -4
  32. package/dist/extends/jsonc.js +5 -6
  33. package/dist/extends/react.js +4 -5
  34. package/dist/extends/sort.d.ts +11 -19
  35. package/dist/extends/sort.js +42 -54
  36. package/dist/extends/typescript.js +3 -4
  37. package/dist/extends/yaml.js +4 -4
  38. package/dist/globs.d.ts +2 -1
  39. package/dist/globs.js +3 -2
  40. package/dist/types.d.ts +8 -2
  41. package/dist/utils/mergeConfig.d.ts +3 -0
  42. package/dist/utils/mergeConfig.js +47 -0
  43. package/dist/vdustr.d.ts +10 -11
  44. package/dist/vdustr.js +27 -30
  45. package/package.json +1 -2
@@ -5,10 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.mdx = void 0;
7
7
  var _eslintConfig = require("@antfu/eslint-config");
8
- var _defu = _interopRequireDefault(require("defu"));
9
8
  var _esToolkit = require("es-toolkit");
9
+ var _mergeConfig = require("../utils/mergeConfig");
10
10
  var _renameRules = require("../utils/renameRules");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  const mdx = async ({
13
12
  codeBlocks = true,
14
13
  processorOptions,
@@ -28,7 +27,7 @@ const mdx = async ({
28
27
  }),
29
28
  name: "vdustr/mdx/processor"
30
29
  };
31
- const rulesConfig = (0, _defu.default)(options.mdx, {
30
+ const rulesConfig = (0, _mergeConfig.mergeConfig)(options.mdx, {
32
31
  ignores: [
33
32
  /**
34
33
  * Handled by `@eslint/markdown`.
@@ -42,7 +41,7 @@ const mdx = async ({
42
41
  });
43
42
  const configs = [setupConfig, processorConfig, rulesConfig];
44
43
  if (codeBlocks) {
45
- const codeBlocksConfig = (0, _defu.default)(codeBlocksOptions, {
44
+ const codeBlocksConfig = (0, _mergeConfig.mergeConfig)(codeBlocksOptions, {
46
45
  rules: {
47
46
  "import/no-default-export": "off"
48
47
  },
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.packageJson = void 0;
7
7
  var _eslintConfig = require("@antfu/eslint-config");
8
- var _defu = _interopRequireDefault(require("defu"));
9
8
  var _esToolkit = require("es-toolkit");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ var _mergeConfig = require("../utils/mergeConfig");
10
+ var _renameRules = require("../utils/renameRules");
11
11
  const packageJson = async options => {
12
12
  await (0, _eslintConfig.ensurePackages)(["eslint-plugin-package-json"]);
13
13
  const packageJson2 = await (0, _eslintConfig.interopDefault)(Promise.resolve().then(() => require("eslint-plugin-package-json/configs/recommended")));
@@ -15,8 +15,9 @@ const packageJson = async options => {
15
15
  plugins: packageJson2.plugins,
16
16
  name: "vdustr/package-json/setup"
17
17
  };
18
- const packageJsonRulesConfig = (0, _defu.default)(options?.packageJson, {
18
+ const packageJsonRulesConfig = (0, _mergeConfig.mergeConfig)(options?.packageJson, {
19
19
  ...(0, _esToolkit.omit)(packageJson2, ["name", "plugins"]),
20
+ rules: (0, _renameRules.renameRules)(packageJson2.rules),
20
21
  name: "vdustr/package-json/rules"
21
22
  });
22
23
  return [packageJsonSetupConfig, packageJsonRulesConfig];
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.prettier = void 0;
7
7
  var _eslintConfig = require("@antfu/eslint-config");
8
- var _defu = _interopRequireDefault(require("defu"));
8
+ var _mergeConfig = require("../utils/mergeConfig");
9
9
  var _renameRules = require("../utils/renameRules");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
10
  const prettier = async options => {
12
11
  await (0, _eslintConfig.ensurePackages)(["eslint-config-prettier"]);
13
12
  const eslintConfigPrettier = await (0, _eslintConfig.interopDefault)(Promise.resolve().then(() => require("eslint-config-prettier")));
14
- const rulesConfig = (0, _defu.default)(options?.prettier, {
13
+ const rulesConfig = (0, _mergeConfig.mergeConfig)(options?.prettier, {
15
14
  ...eslintConfigPrettier,
16
15
  rules: (0, _renameRules.renameRules)(eslintConfigPrettier.rules),
17
16
  name: "vdustr/prettier/rules"
@@ -1,9 +1,9 @@
1
- import type { ConfigOverrides, TypedFlatConfigItem } from "../types";
1
+ import type { ConfigOverrides } from "../types";
2
2
  declare namespace reactCompiler {
3
3
  interface Options {
4
4
  setup?: ConfigOverrides;
5
5
  reactCompiler?: ConfigOverrides;
6
6
  }
7
7
  }
8
- declare const reactCompiler: (options?: reactCompiler.Options) => Promise<TypedFlatConfigItem[]>;
8
+ declare const reactCompiler: (options?: reactCompiler.Options) => Promise<import("../types").TypedFlatConfigItem[]>;
9
9
  export { reactCompiler };
@@ -4,17 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.reactCompiler = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _eslintPluginReactCompiler = require("../lib/eslint-plugin-react-compiler");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ var _mergeConfig = require("../utils/mergeConfig");
10
9
  const reactCompiler = async options => {
11
- const reactCompilerSetupConfig = (0, _defu.default)(options?.setup, {
10
+ const reactCompilerSetupConfig = (0, _mergeConfig.mergeConfig)(options?.setup, {
12
11
  name: "vdustr/react/react-compiler/setup",
13
12
  plugins: {
14
13
  "react-compiler": await (0, _eslintPluginReactCompiler.reactCompiler)()
15
14
  }
16
15
  });
17
- const reactCompilerRulesConfig = (0, _defu.default)(options?.reactCompiler, {
16
+ const reactCompilerRulesConfig = (0, _mergeConfig.mergeConfig)(options?.reactCompiler, {
18
17
  name: "vdustr/react/react-compiler/rules",
19
18
  rules: {
20
19
  "react-compiler/react-compiler": "error"
@@ -5,10 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.storybook = void 0;
7
7
  var _eslintConfig = require("@antfu/eslint-config");
8
- var _defu = _interopRequireDefault(require("defu"));
9
8
  var _esToolkit = require("es-toolkit");
9
+ var _mergeConfig = require("../utils/mergeConfig");
10
10
  var _renameRules = require("../utils/renameRules");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  const storybook = async options => {
13
12
  await (0, _eslintConfig.ensurePackages)(["eslint-plugin-storybook"]);
14
13
  const storybookPlugin = await (0, _eslintConfig.interopDefault)(Promise.resolve().then(() => require("eslint-plugin-storybook")));
@@ -25,7 +24,7 @@ const storybook = async options => {
25
24
  ...(0, _esToolkit.pick)(originalSetupConfig, ["plugins"]),
26
25
  name: "vdustr/stroybook/setup"
27
26
  };
28
- const storyRulesConfig = (0, _defu.default)(options?.stories, {
27
+ const storyRulesConfig = (0, _mergeConfig.mergeConfig)(options?.stories, {
29
28
  name: "vdustr/storybook/stories/rules",
30
29
  rules: {
31
30
  "import/no-default-export": "off"
@@ -38,7 +37,7 @@ const storybook = async options => {
38
37
  ...originalCsfStrictConfig.rules
39
38
  })
40
39
  });
41
- const mainRulesConfig = (0, _defu.default)(options?.main, {
40
+ const mainRulesConfig = (0, _mergeConfig.mergeConfig)(options?.main, {
42
41
  name: "vdustr/storybook/main/rules"
43
42
  }, {
44
43
  ...originalMainRulesConfig,
@@ -99,5 +99,5 @@ type StorybookNoUninstalledAddons = []|[{
99
99
  [k: string]: unknown | undefined
100
100
  }]
101
101
  // Names of all the configs
102
- export type ConfigNames = 'vdustr/mdx/setup' | 'vdustr/mdx/processor' | 'vdustr/mdx/rules' | 'vdustr/mdx/code-blocks' | 'vdustr/prettier/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/stroybook/setup' | 'vdustr/storybook/stories/rules' | 'vdustr/storybook/main/rules' | 'vdustr/javascript/rules' | 'vdustr/imports/rules' | 'vdustr/imports/no-default-export/rules' | 'vdustr/typescript/rules' | 'vdustr/jsonc/rules' | 'vdustr/sort/tsconfig-json' | 'vdustr/yaml/rules' | 'vdustr/yaml/sort-keys/rules' | 'vdustr/sort/json-keys' | 'vdustr/jsonc/sort-array-values/rules'
102
+ export type ConfigNames = 'vdustr/mdx/setup' | 'vdustr/mdx/processor' | 'vdustr/mdx/rules' | 'vdustr/mdx/code-blocks' | 'vdustr/prettier/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/stroybook/setup' | 'vdustr/storybook/stories/rules' | 'vdustr/storybook/main/rules' | 'vdustr/javascript/rules' | 'vdustr/imports/rules' | 'vdustr/imports/no-default-export/rules' | 'vdustr/typescript/rules' | 'vdustr/react/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/jsonc/rules' | 'vdustr/sort/json-keys' | 'vdustr/sort/json-array-values' | 'vdustr/sort/tsconfig-json' | 'vdustr/yaml/rules' | 'vdustr/yaml/sort-keys/rules'
103
103
 
@@ -4,8 +4,8 @@ import {
4
4
  GLOB_MARKDOWN_CODE,
5
5
  interopDefault
6
6
  } from "@antfu/eslint-config";
7
- import defu from "defu";
8
7
  import { omit, pick } from "es-toolkit";
8
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
9
9
  import { renameRules } from "../utils/renameRules.mjs";
10
10
  const mdx = async ({
11
11
  codeBlocks = true,
@@ -26,7 +26,7 @@ const mdx = async ({
26
26
  }),
27
27
  name: "vdustr/mdx/processor"
28
28
  };
29
- const rulesConfig = defu(
29
+ const rulesConfig = mergeConfig(
30
30
  options.mdx,
31
31
  {
32
32
  ignores: [
@@ -45,7 +45,7 @@ const mdx = async ({
45
45
  );
46
46
  const configs = [setupConfig, processorConfig, rulesConfig];
47
47
  if (codeBlocks) {
48
- const codeBlocksConfig = defu(
48
+ const codeBlocksConfig = mergeConfig(
49
49
  codeBlocksOptions,
50
50
  {
51
51
  rules: {
@@ -1,6 +1,7 @@
1
1
  import { ensurePackages, interopDefault } from "@antfu/eslint-config";
2
- import defu from "defu";
3
2
  import { omit } from "es-toolkit";
3
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
4
+ import { renameRules } from "../utils/renameRules.mjs";
4
5
  const packageJson = async (options) => {
5
6
  await ensurePackages(["eslint-plugin-package-json"]);
6
7
  const packageJson2 = await interopDefault(
@@ -10,8 +11,9 @@ const packageJson = async (options) => {
10
11
  plugins: packageJson2.plugins,
11
12
  name: "vdustr/package-json/setup"
12
13
  };
13
- const packageJsonRulesConfig = defu(options?.packageJson, {
14
+ const packageJsonRulesConfig = mergeConfig(options?.packageJson, {
14
15
  ...omit(packageJson2, ["name", "plugins"]),
16
+ rules: renameRules(packageJson2.rules),
15
17
  name: "vdustr/package-json/rules"
16
18
  });
17
19
  return [packageJsonSetupConfig, packageJsonRulesConfig];
@@ -1,19 +1,16 @@
1
1
  import { ensurePackages, interopDefault } from "@antfu/eslint-config";
2
- import defu from "defu";
2
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
3
3
  import { renameRules } from "../utils/renameRules.mjs";
4
4
  const prettier = async (options) => {
5
5
  await ensurePackages(["eslint-config-prettier"]);
6
6
  const eslintConfigPrettier = await interopDefault(
7
7
  import("eslint-config-prettier")
8
8
  );
9
- const rulesConfig = defu(
10
- options?.prettier,
11
- {
12
- ...eslintConfigPrettier,
13
- rules: renameRules(eslintConfigPrettier.rules),
14
- name: "vdustr/prettier/rules"
15
- }
16
- );
9
+ const rulesConfig = mergeConfig(options?.prettier, {
10
+ ...eslintConfigPrettier,
11
+ rules: renameRules(eslintConfigPrettier.rules),
12
+ name: "vdustr/prettier/rules"
13
+ });
17
14
  return rulesConfig;
18
15
  };
19
16
  export { prettier };
@@ -1,9 +1,9 @@
1
- import type { ConfigOverrides, TypedFlatConfigItem } from "../types";
1
+ import type { ConfigOverrides } from "../types";
2
2
  declare namespace reactCompiler {
3
3
  interface Options {
4
4
  setup?: ConfigOverrides;
5
5
  reactCompiler?: ConfigOverrides;
6
6
  }
7
7
  }
8
- declare const reactCompiler: (options?: reactCompiler.Options) => Promise<TypedFlatConfigItem[]>;
8
+ declare const reactCompiler: (options?: reactCompiler.Options) => Promise<import("../types").TypedFlatConfigItem[]>;
9
9
  export { reactCompiler };
@@ -1,13 +1,13 @@
1
- import defu from "defu";
2
1
  import { reactCompiler as importLib } from "../lib/eslint-plugin-react-compiler.mjs";
2
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
3
3
  const reactCompiler = async (options) => {
4
- const reactCompilerSetupConfig = defu(options?.setup, {
4
+ const reactCompilerSetupConfig = mergeConfig(options?.setup, {
5
5
  name: "vdustr/react/react-compiler/setup",
6
6
  plugins: {
7
7
  "react-compiler": await importLib()
8
8
  }
9
9
  });
10
- const reactCompilerRulesConfig = defu(options?.reactCompiler, {
10
+ const reactCompilerRulesConfig = mergeConfig(options?.reactCompiler, {
11
11
  name: "vdustr/react/react-compiler/rules",
12
12
  rules: {
13
13
  "react-compiler/react-compiler": "error"
@@ -1,6 +1,6 @@
1
1
  import { ensurePackages, interopDefault } from "@antfu/eslint-config";
2
- import defu from "defu";
3
2
  import { pick } from "es-toolkit";
3
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
4
4
  import { renameRules } from "../utils/renameRules.mjs";
5
5
  const storybook = async (options) => {
6
6
  await ensurePackages(["eslint-plugin-storybook"]);
@@ -20,7 +20,7 @@ const storybook = async (options) => {
20
20
  ...pick(originalSetupConfig, ["plugins"]),
21
21
  name: "vdustr/stroybook/setup"
22
22
  };
23
- const storyRulesConfig = defu(
23
+ const storyRulesConfig = mergeConfig(
24
24
  options?.stories,
25
25
  {
26
26
  name: "vdustr/storybook/stories/rules",
@@ -37,7 +37,7 @@ const storybook = async (options) => {
37
37
  })
38
38
  }
39
39
  );
40
- const mainRulesConfig = defu(
40
+ const mainRulesConfig = mergeConfig(
41
41
  options?.main,
42
42
  {
43
43
  name: "vdustr/storybook/main/rules"
@@ -99,5 +99,5 @@ type StorybookNoUninstalledAddons = []|[{
99
99
  [k: string]: unknown | undefined
100
100
  }]
101
101
  // Names of all the configs
102
- export type ConfigNames = 'vdustr/mdx/setup' | 'vdustr/mdx/processor' | 'vdustr/mdx/rules' | 'vdustr/mdx/code-blocks' | 'vdustr/prettier/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/stroybook/setup' | 'vdustr/storybook/stories/rules' | 'vdustr/storybook/main/rules' | 'vdustr/javascript/rules' | 'vdustr/imports/rules' | 'vdustr/imports/no-default-export/rules' | 'vdustr/typescript/rules' | 'vdustr/jsonc/rules' | 'vdustr/sort/tsconfig-json' | 'vdustr/yaml/rules' | 'vdustr/yaml/sort-keys/rules' | 'vdustr/sort/json-keys' | 'vdustr/jsonc/sort-array-values/rules'
102
+ export type ConfigNames = 'vdustr/mdx/setup' | 'vdustr/mdx/processor' | 'vdustr/mdx/rules' | 'vdustr/mdx/code-blocks' | 'vdustr/prettier/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/stroybook/setup' | 'vdustr/storybook/stories/rules' | 'vdustr/storybook/main/rules' | 'vdustr/javascript/rules' | 'vdustr/imports/rules' | 'vdustr/imports/no-default-export/rules' | 'vdustr/typescript/rules' | 'vdustr/react/rules' | 'vdustr/react/react-compiler/setup' | 'vdustr/react/react-compiler/rules' | 'vdustr/jsonc/rules' | 'vdustr/sort/json-keys' | 'vdustr/sort/json-array-values' | 'vdustr/sort/tsconfig-json' | 'vdustr/yaml/rules' | 'vdustr/yaml/sort-keys/rules'
103
103
 
@@ -6,16 +6,19 @@ import {
6
6
  GLOB_TS,
7
7
  GLOB_TSX
8
8
  } from "@antfu/eslint-config";
9
- import defu from "defu";
10
9
  import { omit, pick } from "es-toolkit";
11
- import { GLOB_CONFIG_JS } from "../globs.mjs";
10
+ import { GLOB_CONFIG_JS, GLOB_VITEST_WORKSPACE } from "../globs.mjs";
12
11
  import { extendsConfig } from "../utils/extendsConfig.mjs";
12
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
13
13
  import { ignoreKeys } from "./_utils.mjs";
14
14
  const imports = (composer, options) => {
15
15
  extendsConfig(composer, "antfu/imports/rules", (config) => {
16
- const modifiedConfig = defu(pick(options?.imports ?? {}, ["files", "ignores"]), config);
16
+ const modifiedConfig = mergeConfig(
17
+ pick(options?.imports ?? {}, ["files", "ignores"]),
18
+ config
19
+ );
17
20
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
18
- const rulesConfig = defu(
21
+ const rulesConfig = mergeConfig(
19
22
  omit(options?.imports ?? {}, ["files", "ignores"]),
20
23
  {
21
24
  name: "vdustr/imports/rules",
@@ -33,7 +36,7 @@ const imports = (composer, options) => {
33
36
  },
34
37
  omittedConfig
35
38
  );
36
- const noDefaultExportConfig = defu(
39
+ const noDefaultExportConfig = mergeConfig(
37
40
  options?.noDefaultExport,
38
41
  {
39
42
  name: "vdustr/imports/no-default-export/rules",
@@ -46,19 +49,13 @@ const imports = (composer, options) => {
46
49
  */
47
50
  "import/no-default-export": "error"
48
51
  },
49
- files: [
50
- GLOB_JS,
51
- GLOB_JSX,
52
- GLOB_TS,
53
- GLOB_TSX,
54
- ...options?.noDefaultExport?.files || []
55
- ],
52
+ files: [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX],
56
53
  ignores: [
57
54
  // Configuration files
58
55
  GLOB_CONFIG_JS,
59
56
  GLOB_MARKDOWN_CODE,
60
57
  GLOB_ASTRO_TS,
61
- ...options?.noDefaultExport?.ignores || []
58
+ GLOB_VITEST_WORKSPACE
62
59
  ]
63
60
  },
64
61
  omit(omittedConfig, ["files", "ignores"])
@@ -1,12 +1,15 @@
1
- import defu from "defu";
2
1
  import { omit, pick } from "es-toolkit";
3
2
  import { extendsConfig } from "../utils/extendsConfig.mjs";
3
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
4
4
  import { ignoreKeys } from "./_utils.mjs";
5
5
  const javascript = (composer, options) => {
6
6
  extendsConfig(composer, "antfu/javascript/rules", (config) => {
7
- const modifiedConfig = defu(pick(options?.javascript ?? {}, ["files", "ignores"]), config);
7
+ const modifiedConfig = mergeConfig(
8
+ pick(options?.javascript ?? {}, ["files", "ignores"]),
9
+ config
10
+ );
8
11
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
9
- const rulesConfig = defu(
12
+ const rulesConfig = mergeConfig(
10
13
  omit(options?.javascript ?? {}, ["files", "ignores"]),
11
14
  {
12
15
  name: "vdustr/javascript/rules",
@@ -1,16 +1,19 @@
1
- import defu from "defu";
2
1
  import { omit, pick } from "es-toolkit";
3
- import { GLOB_CODE_WORKSPACE, GLOB_PACKAGE_JSON } from "../globs.mjs";
2
+ import { GLOB_CODE_WORKSPACE } from "../globs.mjs";
4
3
  import { extendsConfig } from "../utils/extendsConfig.mjs";
4
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
5
5
  import { ignoreKeys } from "./_utils.mjs";
6
6
  const jsonc = async (composer, options) => {
7
7
  extendsConfig(composer, "antfu/jsonc/rules", (config) => {
8
- const modifiedConfig = defu(pick(options?.jsonc ?? {}, ["files", "ignores"]), config, {
9
- files: [GLOB_CODE_WORKSPACE],
10
- ignores: [GLOB_PACKAGE_JSON]
11
- });
8
+ const modifiedConfig = mergeConfig(
9
+ pick(options?.jsonc ?? {}, ["files", "ignores"]),
10
+ {
11
+ ...config,
12
+ files: [...config.files ?? [], GLOB_CODE_WORKSPACE]
13
+ }
14
+ );
12
15
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
13
- const rulesConfig = defu(
16
+ const rulesConfig = mergeConfig(
14
17
  omit(options?.jsonc ?? {}, ["files", "ignores"]),
15
18
  {
16
19
  name: "vdustr/jsonc/rules",
@@ -1,13 +1,16 @@
1
- import defu from "defu";
2
1
  import { omit, pick } from "es-toolkit";
3
2
  import { reactCompiler } from "../configs/reactCompiler.mjs";
4
3
  import { extendsConfig } from "../utils/extendsConfig.mjs";
4
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
5
5
  import { ignoreKeys } from "./_utils.mjs";
6
6
  const react = (composer, options) => {
7
7
  extendsConfig(composer, "antfu/react/rules", async (config) => {
8
- const modifiedConfig = defu(pick(options?.react ?? {}, ["files", "ignores"]), config);
8
+ const modifiedConfig = mergeConfig(
9
+ pick(options?.react ?? {}, ["files", "ignores"]),
10
+ config
11
+ );
9
12
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
10
- const rulesConfig = defu(
13
+ const rulesConfig = mergeConfig(
11
14
  omit(options?.react ?? {}, ["files", "ignores"]),
12
15
  {
13
16
  name: "vdustr/react/rules",
@@ -19,7 +22,7 @@ const react = (composer, options) => {
19
22
  );
20
23
  const reactCompilerConfigs = await reactCompiler({
21
24
  setup: options?.reactCompilerSetup ?? {},
22
- reactCompiler: defu(
25
+ reactCompiler: mergeConfig(
23
26
  options?.reactCompiler,
24
27
  pick(omittedConfig, ["files", "ignores"])
25
28
  )
@@ -1,26 +1,18 @@
1
1
  import type { ConfigOverrides, VpComposer } from "../types";
2
- declare namespace sortJsonKeys {
3
- interface Options {
4
- sortKeys?: ConfigOverrides;
5
- }
6
- }
7
- declare const sortJsonKeys: (composer: VpComposer, options?: sortJsonKeys.Options) => Promise<void>;
8
- declare namespace sortPackageJson {
2
+ declare namespace sort {
9
3
  interface Options {
4
+ jsoncSortKeys?: ConfigOverrides;
5
+ jsoncSortArrayValues?: ConfigOverrides;
10
6
  packageJson?: ConfigOverrides;
11
- }
12
- }
13
- declare const sortPackageJson: (composer: VpComposer, options?: sortPackageJson.Options) => Promise<void>;
14
- declare namespace sortTsconfigJson {
15
- interface Options {
16
7
  tsconfigJson?: ConfigOverrides;
17
8
  }
18
9
  }
19
- declare const sortTsconfigJson: (composer: VpComposer, options?: sortTsconfigJson.Options) => Promise<void>;
20
- declare namespace sortJsonArrayValues {
21
- interface Options {
22
- sortJsonArrayValues?: ConfigOverrides;
23
- }
24
- }
25
- declare const sortJsonArrayValues: (composer: VpComposer, options?: sortJsonArrayValues.Options) => Promise<void>;
10
+ declare const sortJsonKeys: (composer: VpComposer, options?: sort.Options["jsoncSortKeys"]) => Promise<void>;
11
+ /**
12
+ * Disable rules conflicting with `eslint-config-package-json`.
13
+ */
14
+ declare const sortPackageJson: (composer: VpComposer, options?: sort.Options["packageJson"]) => Promise<void>;
15
+ declare const sortTsconfigJson: (composer: VpComposer, options?: sort.Options["tsconfigJson"]) => Promise<void>;
16
+ declare const sortJsonArrayValues: (composer: VpComposer, options?: sort.Options["jsoncSortArrayValues"]) => Promise<void>;
17
+ export type { sort };
26
18
  export { sortJsonArrayValues, sortJsonKeys, sortPackageJson, sortTsconfigJson };
@@ -1,60 +1,61 @@
1
- import defu from "defu";
2
1
  import { omit, pick } from "es-toolkit";
3
2
  import { GLOB_CSPELL_JSON } from "../globs.mjs";
4
3
  import { extendsConfig } from "../utils/extendsConfig.mjs";
4
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
5
5
  import { ignoreKeys } from "./_utils.mjs";
6
- const sortJsonKeys = async (composer, options) => {
7
- extendsConfig.pushOverations(composer, [
8
- async (items) => {
9
- const source = "vdustr/jsonc/rules";
10
- const configIndex = items.findIndex((item) => item.name === source);
11
- const config = items[configIndex];
12
- if (!config) {
13
- return items;
14
- }
15
- const omittedConfig = omit(config, ignoreKeys);
16
- const rulesConfig = defu(
17
- options?.sortKeys,
18
- {
19
- name: "vdustr/sort/json-keys",
20
- rules: {
21
- "jsonc/sort-keys": [
22
- "error",
23
- {
24
- pathPattern: ".*",
25
- order: {
26
- type: "asc",
27
- caseSensitive: false,
28
- natural: true
29
- }
30
- }
31
- ]
32
- }
33
- },
34
- omittedConfig
35
- );
36
- return [...items, rulesConfig];
6
+ const defaultSortJsonKeys = [
7
+ "error",
8
+ {
9
+ pathPattern: ".*",
10
+ order: {
11
+ type: "asc",
12
+ caseSensitive: false,
13
+ natural: true
14
+ }
15
+ }
16
+ ];
17
+ const defaultSortJsonArrayValues = [
18
+ "error",
19
+ {
20
+ pathPattern: ".*",
21
+ order: {
22
+ type: "asc",
23
+ caseSensitive: false,
24
+ natural: true
37
25
  }
38
- ]);
26
+ }
27
+ ];
28
+ const sortJsonKeys = async (composer, options) => {
29
+ extendsConfig(composer, "vdustr/jsonc/rules", async (config) => {
30
+ const omittedConfig = omit(config, ignoreKeys);
31
+ const rulesConfig = mergeConfig(
32
+ options,
33
+ {
34
+ name: "vdustr/sort/json-keys",
35
+ rules: {
36
+ "jsonc/sort-keys": defaultSortJsonKeys
37
+ }
38
+ },
39
+ omittedConfig
40
+ );
41
+ return [config, rulesConfig];
42
+ });
39
43
  };
40
44
  const sortPackageJson = async (composer, options) => {
41
45
  extendsConfig(composer, "antfu/sort/package-json", (config) => {
42
- const rules = config.rules;
43
- const ruleKeys = Object.keys(rules ?? {});
44
- const modifiedConfig = defu(pick(options?.packageJson ?? {}, ["files", "ignores"]), config);
46
+ const modifiedConfig = mergeConfig(
47
+ pick(options ?? {}, ["files", "ignores"]),
48
+ config
49
+ );
45
50
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
46
- const rulesConfig = defu(
47
- options?.packageJson,
51
+ const rulesConfig = mergeConfig(
52
+ options,
48
53
  {
49
54
  name: "vdustr/sort/package-json",
50
- /**
51
- * Disable all rules. Handled by `eslint-config-package-json`.
52
- */
53
- rules: Object.fromEntries(
54
- ruleKeys.map((key) => {
55
- return [key, "off"];
56
- })
57
- )
55
+ rules: {
56
+ "jsonc/sort-array-values": "off",
57
+ "jsonc/sort-keys": "off"
58
+ }
58
59
  },
59
60
  omittedConfig
60
61
  );
@@ -63,22 +64,18 @@ const sortPackageJson = async (composer, options) => {
63
64
  };
64
65
  const sortTsconfigJson = async (composer, options) => {
65
66
  extendsConfig(composer, "antfu/sort/tsconfig-json", (config) => {
66
- const rules = config.rules;
67
- const ruleKeys = Object.keys(rules ?? {});
68
- const modifiedConfig = defu(pick(options?.tsconfigJson ?? {}, ["files", "ignores"]), config);
67
+ const modifiedConfig = mergeConfig(
68
+ pick(options ?? {}, ["files", "ignores"]),
69
+ config
70
+ );
69
71
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
70
- const rulesConfig = defu(
71
- options?.tsconfigJson,
72
+ const rulesConfig = mergeConfig(
73
+ options,
72
74
  {
73
75
  name: "vdustr/sort/tsconfig-json",
74
- /**
75
- * Disable all rules.
76
- */
77
- rules: Object.fromEntries(
78
- ruleKeys.map((key) => {
79
- return [key, "off"];
80
- })
81
- )
76
+ rules: {
77
+ "jsonc/sort-keys": defaultSortJsonKeys
78
+ }
82
79
  },
83
80
  omittedConfig
84
81
  );
@@ -86,23 +83,15 @@ const sortTsconfigJson = async (composer, options) => {
86
83
  });
87
84
  };
88
85
  const sortJsonArrayValues = async (composer, options) => {
89
- const sortArrayValuesConfig = defu(options?.sortJsonArrayValues, {
90
- name: "vdustr/jsonc/sort-array-values/rules",
91
- files: [GLOB_CSPELL_JSON],
92
- rules: {
93
- "jsonc/sort-array-values": [
94
- "error",
95
- {
96
- pathPattern: ".*",
97
- order: {
98
- type: "asc",
99
- caseSensitive: false,
100
- natural: true
101
- }
102
- }
103
- ]
104
- }
86
+ extendsConfig(composer, "vdustr/sort/json-keys", async (config) => {
87
+ const sortArrayValuesConfig = mergeConfig(options, {
88
+ name: "vdustr/sort/json-array-values",
89
+ files: [GLOB_CSPELL_JSON],
90
+ rules: {
91
+ "jsonc/sort-array-values": defaultSortJsonArrayValues
92
+ }
93
+ });
94
+ return [config, sortArrayValuesConfig];
105
95
  });
106
- composer.append(sortArrayValuesConfig);
107
96
  };
108
97
  export { sortJsonArrayValues, sortJsonKeys, sortPackageJson, sortTsconfigJson };