@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
@@ -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 typescript = (composer, options) => {
6
6
  extendsConfig(composer, "antfu/typescript/rules", (config) => {
7
- const modifiedConfig = defu(pick(options?.typescript ?? {}, ["files", "ignores"]), config);
7
+ const modifiedConfig = mergeConfig(
8
+ pick(options?.typescript ?? {}, ["files", "ignores"]),
9
+ config
10
+ );
8
11
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
9
- const rulesConfig = defu(
12
+ const rulesConfig = mergeConfig(
10
13
  omit(options?.typescript ?? {}, ["files", "ignores"]),
11
14
  {
12
15
  name: "vdustr/typescript/rules",
@@ -1,15 +1,18 @@
1
- import defu from "defu";
2
1
  import { omit, pick } from "es-toolkit";
3
2
  import eslintPluginYml from "eslint-plugin-yml";
4
3
  import { GLOB_PNPM_WORKSPACE_YAML } from "../globs.mjs";
5
4
  import { extendsConfig } from "../utils/extendsConfig.mjs";
5
+ import { mergeConfig } from "../utils/mergeConfig.mjs";
6
6
  import { renameRules } from "../utils/renameRules.mjs";
7
7
  import { ignoreKeys } from "./_utils.mjs";
8
8
  const yaml = (composer, options) => {
9
9
  extendsConfig(composer, "antfu/yaml/rules", (config) => {
10
- const modifiedConfig = defu(pick(options?.yaml ?? {}, ["files", "ignores"]), config);
10
+ const modifiedConfig = mergeConfig(
11
+ pick(options?.yaml ?? {}, ["files", "ignores"]),
12
+ config
13
+ );
11
14
  const omittedConfig = omit(modifiedConfig, ignoreKeys);
12
- const rulesConfig = defu(
15
+ const rulesConfig = mergeConfig(
13
16
  omit(options?.yaml ?? {}, ["files", "ignores"]),
14
17
  {
15
18
  name: "vdustr/yaml/rules",
@@ -26,7 +29,7 @@ const yaml = (composer, options) => {
26
29
  },
27
30
  omittedConfig
28
31
  );
29
- const sortKeysConfig = defu(options?.sortKeys, {
32
+ const sortKeysConfig = mergeConfig(options?.sortKeys, {
30
33
  ...omit(omittedConfig, ["files", "ignores"]),
31
34
  name: "vdustr/yaml/sort-keys/rules",
32
35
  files: [GLOB_PNPM_WORKSPACE_YAML],
@@ -3,4 +3,5 @@ declare const GLOB_PACKAGE_JSON: string;
3
3
  declare const GLOB_PNPM_WORKSPACE_YAML: string;
4
4
  declare const GLOB_CSPELL_JSON: string;
5
5
  declare const GLOB_CONFIG_JS: string;
6
- export { GLOB_CODE_WORKSPACE, GLOB_CONFIG_JS, GLOB_CSPELL_JSON, GLOB_PACKAGE_JSON, GLOB_PNPM_WORKSPACE_YAML, };
6
+ declare const GLOB_VITEST_WORKSPACE: string;
7
+ export { GLOB_CODE_WORKSPACE, GLOB_CONFIG_JS, GLOB_CSPELL_JSON, GLOB_PACKAGE_JSON, GLOB_PNPM_WORKSPACE_YAML, GLOB_VITEST_WORKSPACE, };
@@ -3,10 +3,12 @@ const GLOB_PACKAGE_JSON = "**/package.json";
3
3
  const GLOB_PNPM_WORKSPACE_YAML = "**/pnpm-workspace.y?(a)ml";
4
4
  const GLOB_CSPELL_JSON = "**/cspell.json";
5
5
  const GLOB_CONFIG_JS = "**/*.config.?([cm])[jt]s";
6
+ const GLOB_VITEST_WORKSPACE = "**/vitest.workspace.?([cm])[jt]s";
6
7
  export {
7
8
  GLOB_CODE_WORKSPACE,
8
9
  GLOB_CONFIG_JS,
9
10
  GLOB_CSPELL_JSON,
10
11
  GLOB_PACKAGE_JSON,
11
- GLOB_PNPM_WORKSPACE_YAML
12
+ GLOB_PNPM_WORKSPACE_YAML,
13
+ GLOB_VITEST_WORKSPACE
12
14
  };
@@ -1,6 +1,6 @@
1
1
  import type antfu from "@antfu/eslint-config";
2
2
  import type { ConfigNames as AntfuEslintConfigNames, Rules as AntfuEslintRules } from "@antfu/eslint-config";
3
- import type { DistributiveOmit } from "@mui/types";
3
+ import type { DistributiveOmit, Overwrite } from "@mui/types";
4
4
  import type { Linter } from "eslint";
5
5
  import type { FlatConfigComposer } from "eslint-flat-config-utils";
6
6
  import type { RuleOptions, ConfigNames as VpEslintConfigNames } from "./eslint-typegen";
@@ -18,7 +18,13 @@ type ConfigNames = VpEslintConfigNames | AntfuEslintConfigNames;
18
18
  type TypedFlatConfigItem = Omit<Linter.Config<Linter.RulesRecord & Rules>, "plugins"> & {
19
19
  plugins?: Record<string, any>;
20
20
  };
21
- interface ConfigOverrides extends DistributiveOmit<TypedFlatConfigItem, "process"> {
21
+ type Files = TypedFlatConfigItem["files"];
22
+ type Ignores = TypedFlatConfigItem["ignores"];
23
+ type Mutables<T> = T | ((config: T) => T);
24
+ interface ConfigOverrides extends Overwrite<DistributiveOmit<TypedFlatConfigItem, "process">, {
25
+ files?: Mutables<Files>;
26
+ ignores?: Mutables<Ignores>;
27
+ }> {
22
28
  }
23
29
  /**
24
30
  * Typed composer.
@@ -0,0 +1,3 @@
1
+ import type { ConfigOverrides, TypedFlatConfigItem } from "../types";
2
+ declare function mergeConfig(source?: ConfigOverrides, ...[def, ...defs]: [TypedFlatConfigItem, ...Array<TypedFlatConfigItem>]): TypedFlatConfigItem;
3
+ export { mergeConfig };
@@ -0,0 +1,56 @@
1
+ import { omit } from "es-toolkit";
2
+ const objectMergeKeys = ["rules", "plugins"];
3
+ const mutableMergeKeys = ["files", "ignores"];
4
+ function mergeConfig(source, ...[def, ...defs]) {
5
+ const reversedDefs = [def, ...defs].toReversed();
6
+ const mergedDef = {
7
+ ...Object.fromEntries(reversedDefs.flatMap((def2) => Object.entries(def2))),
8
+ ...Object.fromEntries(
9
+ objectMergeKeys.flatMap((key) => {
10
+ if (reversedDefs.every((def2) => !(key in def2))) return [];
11
+ const values = Object.fromEntries(
12
+ reversedDefs.flatMap((def2) => Object.entries(def2[key] ?? {}))
13
+ );
14
+ return [[key, values]];
15
+ })
16
+ )
17
+ };
18
+ if (!source) return mergedDef;
19
+ const merged = {
20
+ ...omit(mergedDef, [...objectMergeKeys, ...mutableMergeKeys]),
21
+ ...omit(source, [...objectMergeKeys, ...mutableMergeKeys]),
22
+ ...Object.fromEntries(
23
+ objectMergeKeys.flatMap((key) => {
24
+ if (!(key in source) && !(key in mergedDef)) return [];
25
+ return [
26
+ [
27
+ key,
28
+ {
29
+ ...mergedDef[key],
30
+ ...source[key]
31
+ }
32
+ ]
33
+ ];
34
+ })
35
+ ),
36
+ ...Object.fromEntries(
37
+ mutableMergeKeys.flatMap((key) => {
38
+ if (!(key in source) && !(key in mergedDef)) return [];
39
+ if (!(key in source)) return [[key, mergedDef[key]]];
40
+ const sourceValue = source[key];
41
+ if (sourceValue === void 0) return [];
42
+ if (typeof sourceValue === "function") {
43
+ const value = sourceValue(
44
+ // @ts-expect-error -- typeof files and ignores are different.
45
+ mergedDef[key]
46
+ );
47
+ if (value === void 0) return [];
48
+ return [[key, value]];
49
+ }
50
+ return [[key, sourceValue]];
51
+ })
52
+ )
53
+ };
54
+ return merged;
55
+ }
56
+ export { mergeConfig };
@@ -1,3 +1,4 @@
1
+ import type { sort } from "./extends/sort";
1
2
  import type { Config, ReplaceAntfuEslintRulesWithVpRulesDeeply, VpComposer } from "./types";
2
3
  import antfu from "@antfu/eslint-config";
3
4
  import { mdx } from "./configs/mdx";
@@ -8,21 +9,19 @@ import { imports } from "./extends/imports";
8
9
  import { javascript } from "./extends/javascript";
9
10
  import { jsonc } from "./extends/jsonc";
10
11
  import { react } from "./extends/react";
11
- import { sortJsonArrayValues, sortJsonKeys, sortPackageJson, sortTsconfigJson } from "./extends/sort";
12
12
  import { typescript } from "./extends/typescript";
13
13
  import { yaml } from "./extends/yaml";
14
14
  type Options = ReplaceAntfuEslintRulesWithVpRulesDeeply<NonNullable<Parameters<typeof antfu>[0]>> & {
15
- javascriptExtends?: javascript.Options;
16
- importsExtends?: imports.Options;
17
- typescriptExtends?: typescript.Options;
18
- jsoncExtends?: jsonc.Options;
19
- sortPackageJsonExtends?: sortPackageJson.Options;
20
- sortTsConfigJsonExtends?: sortTsconfigJson.Options;
21
- sortJsonKeysExtends?: sortJsonKeys.Options;
22
- sortJsonArrayValuesExtends?: sortJsonArrayValues.Options;
23
- yamlExtends?: yaml.Options;
15
+ extends?: {
16
+ javascript?: javascript.Options;
17
+ imports?: imports.Options;
18
+ typescript?: typescript.Options;
19
+ jsonc?: jsonc.Options;
20
+ sort?: sort.Options;
21
+ yaml?: yaml.Options;
22
+ react?: react.Options;
23
+ };
24
24
  packageJson?: boolean | packageJson.Options;
25
- reactExtends?: react.Options;
26
25
  mdx?: boolean | mdx.Options;
27
26
  storybook?: boolean | storybook.Options;
28
27
  prettier?: boolean | prettier.Options;
@@ -1,4 +1,5 @@
1
1
  import antfu from "@antfu/eslint-config";
2
+ import { omit, pick } from "es-toolkit";
2
3
  import { mdx } from "./configs/mdx.mjs";
3
4
  import { packageJson } from "./configs/packageJson.mjs";
4
5
  import { prettier } from "./configs/prettier.mjs";
@@ -15,53 +16,56 @@ import {
15
16
  } from "./extends/sort.mjs";
16
17
  import { typescript } from "./extends/typescript.mjs";
17
18
  import { yaml } from "./extends/yaml.mjs";
19
+ const ownedConfigNames = [
20
+ "extends",
21
+ "packageJson",
22
+ "mdx",
23
+ "storybook",
24
+ "prettier"
25
+ ];
18
26
  const vdustr = (options, ...userConfigs) => {
27
+ const antfuOptions = omit(
28
+ options ?? {},
29
+ ownedConfigNames
30
+ );
31
+ const vpOptions = pick(options ?? {}, ownedConfigNames);
32
+ const packageJsonEnabled = Boolean(vpOptions?.packageJson ?? true);
33
+ const storybookEnabled = Boolean(vpOptions?.storybook ?? false);
34
+ const mdxEnabled = Boolean(vpOptions?.mdx ?? false);
35
+ const prettierEnabled = Boolean(vpOptions?.prettier ?? true);
19
36
  let config = antfu({
20
- // Use `prettier` for formatting by default.
21
- stylistic: false,
22
- ...options
37
+ ...antfuOptions,
38
+ ...!prettierEnabled ? null : {
39
+ // Forcibly disable style rules if prettier is enabled.
40
+ stylistic: false
41
+ }
23
42
  });
24
- javascript(config, options?.javascriptExtends);
25
- imports(config, options?.importsExtends);
26
- typescript(config, options?.typescriptExtends);
27
- jsonc(config, options?.jsoncExtends);
28
- yaml(config, options?.yamlExtends);
29
- react(config, options?.reactExtends);
30
- const packageJsonEnabled = Boolean(options?.packageJson ?? true);
43
+ javascript(config, vpOptions?.extends?.javascript);
44
+ imports(config, vpOptions?.extends?.imports);
45
+ typescript(config, vpOptions?.extends?.typescript);
46
+ jsonc(config, vpOptions?.extends?.jsonc);
47
+ if (packageJsonEnabled)
48
+ sortPackageJson(config, vpOptions?.extends?.sort?.packageJson);
49
+ sortTsconfigJson(config, vpOptions?.extends?.sort?.tsconfigJson);
50
+ sortJsonKeys(config, vpOptions?.extends?.sort?.jsoncSortKeys);
51
+ sortJsonArrayValues(config, vpOptions?.extends?.sort?.jsoncSortArrayValues);
52
+ yaml(config, vpOptions?.extends?.yaml);
53
+ react(config, vpOptions?.extends?.react);
31
54
  if (packageJsonEnabled) {
32
- const packageJsonOptions = typeof options?.packageJson !== "object" ? void 0 : options.packageJson;
55
+ const packageJsonOptions = typeof vpOptions?.packageJson !== "object" ? void 0 : vpOptions.packageJson;
33
56
  config = config.append(
34
57
  packageJson(...!packageJsonOptions ? [] : [packageJsonOptions])
35
58
  );
36
59
  }
37
- const jsoncEnabled = Boolean(options?.jsonc ?? true);
38
- const sortPackageJsonExtendsEnabled = (
39
- /**
40
- * jsonc is required for the rules to work.
41
- */
42
- jsoncEnabled && packageJsonEnabled
43
- );
44
- if (sortPackageJsonExtendsEnabled) {
45
- const sortPackageJsonOptions = typeof options?.sortPackageJsonExtends !== "object" ? void 0 : options.sortPackageJsonExtends;
46
- sortPackageJson(
47
- config,
48
- ...!sortPackageJsonOptions ? [] : [sortPackageJsonOptions]
49
- );
50
- }
51
- sortTsconfigJson(config, options?.sortTsConfigJsonExtends);
52
- sortJsonKeys(config, options?.sortJsonKeysExtends);
53
- sortJsonArrayValues(config, options?.sortJsonArrayValuesExtends);
54
- const storybookEnabled = Boolean(options?.storybook ?? false);
55
60
  if (storybookEnabled) {
56
- const storybookOptions = typeof options?.storybook !== "object" ? void 0 : options.storybook;
61
+ const storybookOptions = typeof vpOptions?.storybook !== "object" ? void 0 : vpOptions.storybook;
57
62
  config = config.append(
58
63
  storybook(...!storybookOptions ? [] : [storybookOptions])
59
64
  );
60
65
  }
61
- const mdxEnabled = Boolean(options?.mdx ?? false);
62
66
  if (mdxEnabled) {
63
67
  const mdxOptions = {
64
- ...typeof options?.mdx !== "object" ? null : options.mdx
68
+ ...typeof vpOptions?.mdx !== "object" ? null : vpOptions.mdx
65
69
  };
66
70
  const mdxFlatCodeBlocksEnabled = Boolean(
67
71
  mdxOptions?.codeBlocks ?? true
@@ -76,9 +80,8 @@ const vdustr = (options, ...userConfigs) => {
76
80
  })
77
81
  );
78
82
  }
79
- const prettierEnabled = Boolean(options?.prettier ?? true);
80
83
  if (prettierEnabled) {
81
- const prettierOptions = typeof options?.prettier !== "object" ? void 0 : options.prettier;
84
+ const prettierOptions = typeof vpOptions?.prettier !== "object" ? void 0 : vpOptions.prettier;
82
85
  config = config.append(
83
86
  prettier(...!prettierOptions ? [] : [prettierOptions])
84
87
  );
@@ -5,17 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.imports = void 0;
7
7
  var _eslintConfig = require("@antfu/eslint-config");
8
- var _defu = _interopRequireDefault(require("defu"));
9
8
  var _esToolkit = require("es-toolkit");
10
9
  var _globs = require("../globs");
11
10
  var _extendsConfig = require("../utils/extendsConfig");
11
+ var _mergeConfig = require("../utils/mergeConfig");
12
12
  var _utils = require("./_utils");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  const imports = (composer, options) => {
15
14
  (0, _extendsConfig.extendsConfig)(composer, "antfu/imports/rules", config => {
16
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.imports ?? {}, ["files", "ignores"]), config);
15
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.imports ?? {}, ["files", "ignores"]), config);
17
16
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
18
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.imports ?? {}, ["files", "ignores"]), {
17
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.imports ?? {}, ["files", "ignores"]), {
19
18
  name: "vdustr/imports/rules",
20
19
  rules: {
21
20
  /**
@@ -29,7 +28,7 @@ const imports = (composer, options) => {
29
28
  "import/no-namespace": "error"
30
29
  }
31
30
  }, omittedConfig);
32
- const noDefaultExportConfig = (0, _defu.default)(options?.noDefaultExport, {
31
+ const noDefaultExportConfig = (0, _mergeConfig.mergeConfig)(options?.noDefaultExport, {
33
32
  name: "vdustr/imports/no-default-export/rules",
34
33
  rules: {
35
34
  /**
@@ -40,10 +39,10 @@ const imports = (composer, options) => {
40
39
  */
41
40
  "import/no-default-export": "error"
42
41
  },
43
- files: [_eslintConfig.GLOB_JS, _eslintConfig.GLOB_JSX, _eslintConfig.GLOB_TS, _eslintConfig.GLOB_TSX, ...(options?.noDefaultExport?.files || [])],
42
+ files: [_eslintConfig.GLOB_JS, _eslintConfig.GLOB_JSX, _eslintConfig.GLOB_TS, _eslintConfig.GLOB_TSX],
44
43
  ignores: [
45
44
  // Configuration files
46
- _globs.GLOB_CONFIG_JS, _eslintConfig.GLOB_MARKDOWN_CODE, _eslintConfig.GLOB_ASTRO_TS, ...(options?.noDefaultExport?.ignores || [])]
45
+ _globs.GLOB_CONFIG_JS, _eslintConfig.GLOB_MARKDOWN_CODE, _eslintConfig.GLOB_ASTRO_TS, _globs.GLOB_VITEST_WORKSPACE]
47
46
  }, (0, _esToolkit.omit)(omittedConfig, ["files", "ignores"]));
48
47
  return [modifiedConfig, rulesConfig, noDefaultExportConfig];
49
48
  });
@@ -4,16 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.javascript = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _extendsConfig = require("../utils/extendsConfig");
9
+ var _mergeConfig = require("../utils/mergeConfig");
10
10
  var _utils = require("./_utils");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  const javascript = (composer, options) => {
13
12
  (0, _extendsConfig.extendsConfig)(composer, "antfu/javascript/rules", config => {
14
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.javascript ?? {}, ["files", "ignores"]), config);
13
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.javascript ?? {}, ["files", "ignores"]), config);
15
14
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
16
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.javascript ?? {}, ["files", "ignores"]), {
15
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.javascript ?? {}, ["files", "ignores"]), {
17
16
  name: "vdustr/javascript/rules",
18
17
  rules: {
19
18
  /**
@@ -4,20 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.jsonc = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _globs = require("../globs");
10
9
  var _extendsConfig = require("../utils/extendsConfig");
10
+ var _mergeConfig = require("../utils/mergeConfig");
11
11
  var _utils = require("./_utils");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
12
  const jsonc = async (composer, options) => {
14
13
  (0, _extendsConfig.extendsConfig)(composer, "antfu/jsonc/rules", config => {
15
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.jsonc ?? {}, ["files", "ignores"]), config, {
16
- files: [_globs.GLOB_CODE_WORKSPACE],
17
- ignores: [_globs.GLOB_PACKAGE_JSON]
14
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.jsonc ?? {}, ["files", "ignores"]), {
15
+ ...config,
16
+ files: [...(config.files ?? []), _globs.GLOB_CODE_WORKSPACE]
18
17
  });
19
18
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
20
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.jsonc ?? {}, ["files", "ignores"]), {
19
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.jsonc ?? {}, ["files", "ignores"]), {
21
20
  name: "vdustr/jsonc/rules",
22
21
  rules: {
23
22
  /**
@@ -4,17 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.react = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _reactCompiler = require("../configs/reactCompiler");
10
9
  var _extendsConfig = require("../utils/extendsConfig");
10
+ var _mergeConfig = require("../utils/mergeConfig");
11
11
  var _utils = require("./_utils");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
12
  const react = (composer, options) => {
14
13
  (0, _extendsConfig.extendsConfig)(composer, "antfu/react/rules", async config => {
15
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.react ?? {}, ["files", "ignores"]), config);
14
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.react ?? {}, ["files", "ignores"]), config);
16
15
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
17
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.react ?? {}, ["files", "ignores"]), {
16
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.react ?? {}, ["files", "ignores"]), {
18
17
  name: "vdustr/react/rules",
19
18
  rules: {
20
19
  "react/prefer-destructuring-assignment": "off"
@@ -22,7 +21,7 @@ const react = (composer, options) => {
22
21
  }, omittedConfig);
23
22
  const reactCompilerConfigs = await (0, _reactCompiler.reactCompiler)({
24
23
  setup: options?.reactCompilerSetup ?? {},
25
- reactCompiler: (0, _defu.default)(options?.reactCompiler, (0, _esToolkit.pick)(omittedConfig, ["files", "ignores"]))
24
+ reactCompiler: (0, _mergeConfig.mergeConfig)(options?.reactCompiler, (0, _esToolkit.pick)(omittedConfig, ["files", "ignores"]))
26
25
  });
27
26
  return [modifiedConfig, rulesConfig, ...reactCompilerConfigs];
28
27
  });
@@ -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 };
@@ -4,52 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sortTsconfigJson = exports.sortPackageJson = exports.sortJsonKeys = exports.sortJsonArrayValues = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _globs = require("../globs");
10
9
  var _extendsConfig = require("../utils/extendsConfig");
10
+ var _mergeConfig = require("../utils/mergeConfig");
11
11
  var _utils = require("./_utils");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const defaultSortJsonKeys = ["error", {
13
+ pathPattern: ".*",
14
+ order: {
15
+ type: "asc",
16
+ caseSensitive: false,
17
+ natural: true
18
+ }
19
+ }];
20
+ const defaultSortJsonArrayValues = ["error", {
21
+ pathPattern: ".*",
22
+ order: {
23
+ type: "asc",
24
+ caseSensitive: false,
25
+ natural: true
26
+ }
27
+ }];
13
28
  const sortJsonKeys = async (composer, options) => {
14
- _extendsConfig.extendsConfig.pushOverations(composer, [async items => {
15
- const source = "vdustr/jsonc/rules";
16
- const configIndex = items.findIndex(item => item.name === source);
17
- const config = items[configIndex];
18
- if (!config) {
19
- return items;
20
- }
29
+ (0, _extendsConfig.extendsConfig)(composer, "vdustr/jsonc/rules", async config => {
21
30
  const omittedConfig = (0, _esToolkit.omit)(config, _utils.ignoreKeys);
22
- const rulesConfig = (0, _defu.default)(options?.sortKeys, {
31
+ const rulesConfig = (0, _mergeConfig.mergeConfig)(options, {
23
32
  name: "vdustr/sort/json-keys",
24
33
  rules: {
25
- "jsonc/sort-keys": ["error", {
26
- pathPattern: ".*",
27
- order: {
28
- type: "asc",
29
- caseSensitive: false,
30
- natural: true
31
- }
32
- }]
34
+ "jsonc/sort-keys": defaultSortJsonKeys
33
35
  }
34
36
  }, omittedConfig);
35
- return [...items, rulesConfig];
36
- }]);
37
+ return [config, rulesConfig];
38
+ });
37
39
  };
38
40
  exports.sortJsonKeys = sortJsonKeys;
39
41
  const sortPackageJson = async (composer, options) => {
40
42
  (0, _extendsConfig.extendsConfig)(composer, "antfu/sort/package-json", config => {
41
- const rules = config.rules;
42
- const ruleKeys = Object.keys(rules ?? {});
43
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.packageJson ?? {}, ["files", "ignores"]), config);
43
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options ?? {}, ["files", "ignores"]), config);
44
44
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
45
- const rulesConfig = (0, _defu.default)(options?.packageJson, {
45
+ const rulesConfig = (0, _mergeConfig.mergeConfig)(options, {
46
46
  name: "vdustr/sort/package-json",
47
- /**
48
- * Disable all rules. Handled by `eslint-config-package-json`.
49
- */
50
- rules: Object.fromEntries(ruleKeys.map(key => {
51
- return [key, "off"];
52
- }))
47
+ rules: {
48
+ "jsonc/sort-array-values": "off",
49
+ "jsonc/sort-keys": "off"
50
+ }
53
51
  }, omittedConfig);
54
52
  return [modifiedConfig, rulesConfig];
55
53
  });
@@ -57,38 +55,28 @@ const sortPackageJson = async (composer, options) => {
57
55
  exports.sortPackageJson = sortPackageJson;
58
56
  const sortTsconfigJson = async (composer, options) => {
59
57
  (0, _extendsConfig.extendsConfig)(composer, "antfu/sort/tsconfig-json", config => {
60
- const rules = config.rules;
61
- const ruleKeys = Object.keys(rules ?? {});
62
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.tsconfigJson ?? {}, ["files", "ignores"]), config);
58
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options ?? {}, ["files", "ignores"]), config);
63
59
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
64
- const rulesConfig = (0, _defu.default)(options?.tsconfigJson, {
60
+ const rulesConfig = (0, _mergeConfig.mergeConfig)(options, {
65
61
  name: "vdustr/sort/tsconfig-json",
66
- /**
67
- * Disable all rules.
68
- */
69
- rules: Object.fromEntries(ruleKeys.map(key => {
70
- return [key, "off"];
71
- }))
62
+ rules: {
63
+ "jsonc/sort-keys": defaultSortJsonKeys
64
+ }
72
65
  }, omittedConfig);
73
66
  return [modifiedConfig, rulesConfig];
74
67
  });
75
68
  };
76
69
  exports.sortTsconfigJson = sortTsconfigJson;
77
70
  const sortJsonArrayValues = async (composer, options) => {
78
- const sortArrayValuesConfig = (0, _defu.default)(options?.sortJsonArrayValues, {
79
- name: "vdustr/jsonc/sort-array-values/rules",
80
- files: [_globs.GLOB_CSPELL_JSON],
81
- rules: {
82
- "jsonc/sort-array-values": ["error", {
83
- pathPattern: ".*",
84
- order: {
85
- type: "asc",
86
- caseSensitive: false,
87
- natural: true
88
- }
89
- }]
90
- }
71
+ (0, _extendsConfig.extendsConfig)(composer, "vdustr/sort/json-keys", async config => {
72
+ const sortArrayValuesConfig = (0, _mergeConfig.mergeConfig)(options, {
73
+ name: "vdustr/sort/json-array-values",
74
+ files: [_globs.GLOB_CSPELL_JSON],
75
+ rules: {
76
+ "jsonc/sort-array-values": defaultSortJsonArrayValues
77
+ }
78
+ });
79
+ return [config, sortArrayValuesConfig];
91
80
  });
92
- composer.append(sortArrayValuesConfig);
93
81
  };
94
82
  exports.sortJsonArrayValues = sortJsonArrayValues;
@@ -4,16 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.typescript = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _extendsConfig = require("../utils/extendsConfig");
9
+ var _mergeConfig = require("../utils/mergeConfig");
10
10
  var _utils = require("./_utils");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  const typescript = (composer, options) => {
13
12
  (0, _extendsConfig.extendsConfig)(composer, "antfu/typescript/rules", config => {
14
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.typescript ?? {}, ["files", "ignores"]), config);
13
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.typescript ?? {}, ["files", "ignores"]), config);
15
14
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
16
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.typescript ?? {}, ["files", "ignores"]), {
15
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.typescript ?? {}, ["files", "ignores"]), {
17
16
  name: "vdustr/typescript/rules",
18
17
  rules: {
19
18
  /**