@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
@@ -4,25 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.yaml = void 0;
7
- var _defu = _interopRequireDefault(require("defu"));
8
7
  var _esToolkit = require("es-toolkit");
9
8
  var _eslintPluginYml = _interopRequireDefault(require("eslint-plugin-yml"));
10
9
  var _globs = require("../globs");
11
10
  var _extendsConfig = require("../utils/extendsConfig");
11
+ var _mergeConfig = require("../utils/mergeConfig");
12
12
  var _renameRules = require("../utils/renameRules");
13
13
  var _utils = require("./_utils");
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  const yaml = (composer, options) => {
16
16
  (0, _extendsConfig.extendsConfig)(composer, "antfu/yaml/rules", config => {
17
- const modifiedConfig = (0, _defu.default)((0, _esToolkit.pick)(options?.yaml ?? {}, ["files", "ignores"]), config);
17
+ const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.yaml ?? {}, ["files", "ignores"]), config);
18
18
  const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
19
- const rulesConfig = (0, _defu.default)((0, _esToolkit.omit)(options?.yaml ?? {}, ["files", "ignores"]), {
19
+ const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.yaml ?? {}, ["files", "ignores"]), {
20
20
  name: "vdustr/yaml/rules",
21
21
  rules: (0, _renameRules.renameRules)({
22
22
  ...Object.fromEntries([..._eslintPluginYml.default.configs["flat/recommended"].flatMap(config2 => Object.entries(config2.rules ?? {})), ..._eslintPluginYml.default.configs["flat/prettier"].flatMap(config2 => Object.entries(config2.rules ?? {}))])
23
23
  })
24
24
  }, omittedConfig);
25
- const sortKeysConfig = (0, _defu.default)(options?.sortKeys, {
25
+ const sortKeysConfig = (0, _mergeConfig.mergeConfig)(options?.sortKeys, {
26
26
  ...(0, _esToolkit.omit)(omittedConfig, ["files", "ignores"]),
27
27
  name: "vdustr/yaml/sort-keys/rules",
28
28
  files: [_globs.GLOB_PNPM_WORKSPACE_YAML],
package/dist/globs.d.ts CHANGED
@@ -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, };
package/dist/globs.js CHANGED
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.GLOB_PNPM_WORKSPACE_YAML = exports.GLOB_PACKAGE_JSON = exports.GLOB_CSPELL_JSON = exports.GLOB_CONFIG_JS = exports.GLOB_CODE_WORKSPACE = void 0;
6
+ exports.GLOB_VITEST_WORKSPACE = exports.GLOB_PNPM_WORKSPACE_YAML = exports.GLOB_PACKAGE_JSON = exports.GLOB_CSPELL_JSON = exports.GLOB_CONFIG_JS = exports.GLOB_CODE_WORKSPACE = void 0;
7
7
  const GLOB_CODE_WORKSPACE = exports.GLOB_CODE_WORKSPACE = "**/*.code-workspace";
8
8
  const GLOB_PACKAGE_JSON = exports.GLOB_PACKAGE_JSON = "**/package.json";
9
9
  const GLOB_PNPM_WORKSPACE_YAML = exports.GLOB_PNPM_WORKSPACE_YAML = "**/pnpm-workspace.y?(a)ml";
10
10
  const GLOB_CSPELL_JSON = exports.GLOB_CSPELL_JSON = "**/cspell.json";
11
- const GLOB_CONFIG_JS = exports.GLOB_CONFIG_JS = "**/*.config.?([cm])[jt]s";
11
+ const GLOB_CONFIG_JS = exports.GLOB_CONFIG_JS = "**/*.config.?([cm])[jt]s";
12
+ const GLOB_VITEST_WORKSPACE = exports.GLOB_VITEST_WORKSPACE = "**/vitest.workspace.?([cm])[jt]s";
package/dist/types.d.ts CHANGED
@@ -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,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergeConfig = mergeConfig;
7
+ var _esToolkit = require("es-toolkit");
8
+ const objectMergeKeys = ["rules", "plugins"];
9
+ const mutableMergeKeys = ["files", "ignores"];
10
+ function mergeConfig(source, ...[def, ...defs]) {
11
+ const reversedDefs = [def, ...defs].toReversed();
12
+ const mergedDef = {
13
+ ...Object.fromEntries(reversedDefs.flatMap(def2 => Object.entries(def2))),
14
+ ...Object.fromEntries(objectMergeKeys.flatMap(key => {
15
+ if (reversedDefs.every(def2 => !(key in def2))) return [];
16
+ const values = Object.fromEntries(reversedDefs.flatMap(def2 => Object.entries(def2[key] ?? {})));
17
+ return [[key, values]];
18
+ }))
19
+ };
20
+ if (!source) return mergedDef;
21
+ const merged = {
22
+ ...(0, _esToolkit.omit)(mergedDef, [...objectMergeKeys, ...mutableMergeKeys]),
23
+ ...(0, _esToolkit.omit)(source, [...objectMergeKeys, ...mutableMergeKeys]),
24
+ ...Object.fromEntries(objectMergeKeys.flatMap(key => {
25
+ if (!(key in source) && !(key in mergedDef)) return [];
26
+ return [[key, {
27
+ ...mergedDef[key],
28
+ ...source[key]
29
+ }]];
30
+ })),
31
+ ...Object.fromEntries(mutableMergeKeys.flatMap(key => {
32
+ if (!(key in source) && !(key in mergedDef)) return [];
33
+ if (!(key in source)) return [[key, mergedDef[key]]];
34
+ const sourceValue = source[key];
35
+ if (sourceValue === void 0) return [];
36
+ if (typeof sourceValue === "function") {
37
+ const value = sourceValue(
38
+ // @ts-expect-error -- typeof files and ignores are different.
39
+ mergedDef[key]);
40
+ if (value === void 0) return [];
41
+ return [[key, value]];
42
+ }
43
+ return [[key, sourceValue]];
44
+ }))
45
+ };
46
+ return merged;
47
+ }
package/dist/vdustr.d.ts CHANGED
@@ -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;
package/dist/vdustr.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.vdustr = void 0;
7
7
  var _eslintConfig = _interopRequireDefault(require("@antfu/eslint-config"));
8
+ var _esToolkit = require("es-toolkit");
8
9
  var _mdx = require("./configs/mdx");
9
10
  var _packageJson = require("./configs/packageJson");
10
11
  var _prettier = require("./configs/prettier");
@@ -17,45 +18,42 @@ var _sort = require("./extends/sort");
17
18
  var _typescript = require("./extends/typescript");
18
19
  var _yaml = require("./extends/yaml");
19
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ const ownedConfigNames = ["extends", "packageJson", "mdx", "storybook", "prettier"];
20
22
  const vdustr = (options, ...userConfigs) => {
23
+ const antfuOptions = (0, _esToolkit.omit)(options ?? {}, ownedConfigNames);
24
+ const vpOptions = (0, _esToolkit.pick)(options ?? {}, ownedConfigNames);
25
+ const packageJsonEnabled = Boolean(vpOptions?.packageJson ?? true);
26
+ const storybookEnabled = Boolean(vpOptions?.storybook ?? false);
27
+ const mdxEnabled = Boolean(vpOptions?.mdx ?? false);
28
+ const prettierEnabled = Boolean(vpOptions?.prettier ?? true);
21
29
  let config = (0, _eslintConfig.default)({
22
- // Use `prettier` for formatting by default.
23
- stylistic: false,
24
- ...options
30
+ ...antfuOptions,
31
+ ...(!prettierEnabled ? null : {
32
+ // Forcibly disable style rules if prettier is enabled.
33
+ stylistic: false
34
+ })
25
35
  });
26
- (0, _javascript.javascript)(config, options?.javascriptExtends);
27
- (0, _imports.imports)(config, options?.importsExtends);
28
- (0, _typescript.typescript)(config, options?.typescriptExtends);
29
- (0, _jsonc.jsonc)(config, options?.jsoncExtends);
30
- (0, _yaml.yaml)(config, options?.yamlExtends);
31
- (0, _react.react)(config, options?.reactExtends);
32
- const packageJsonEnabled = Boolean(options?.packageJson ?? true);
36
+ (0, _javascript.javascript)(config, vpOptions?.extends?.javascript);
37
+ (0, _imports.imports)(config, vpOptions?.extends?.imports);
38
+ (0, _typescript.typescript)(config, vpOptions?.extends?.typescript);
39
+ (0, _jsonc.jsonc)(config, vpOptions?.extends?.jsonc);
40
+ if (packageJsonEnabled) (0, _sort.sortPackageJson)(config, vpOptions?.extends?.sort?.packageJson);
41
+ (0, _sort.sortTsconfigJson)(config, vpOptions?.extends?.sort?.tsconfigJson);
42
+ (0, _sort.sortJsonKeys)(config, vpOptions?.extends?.sort?.jsoncSortKeys);
43
+ (0, _sort.sortJsonArrayValues)(config, vpOptions?.extends?.sort?.jsoncSortArrayValues);
44
+ (0, _yaml.yaml)(config, vpOptions?.extends?.yaml);
45
+ (0, _react.react)(config, vpOptions?.extends?.react);
33
46
  if (packageJsonEnabled) {
34
- const packageJsonOptions = typeof options?.packageJson !== "object" ? void 0 : options.packageJson;
47
+ const packageJsonOptions = typeof vpOptions?.packageJson !== "object" ? void 0 : vpOptions.packageJson;
35
48
  config = config.append((0, _packageJson.packageJson)(...(!packageJsonOptions ? [] : [packageJsonOptions])));
36
49
  }
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
- if (sortPackageJsonExtendsEnabled) {
44
- const sortPackageJsonOptions = typeof options?.sortPackageJsonExtends !== "object" ? void 0 : options.sortPackageJsonExtends;
45
- (0, _sort.sortPackageJson)(config, ...(!sortPackageJsonOptions ? [] : [sortPackageJsonOptions]));
46
- }
47
- (0, _sort.sortTsconfigJson)(config, options?.sortTsConfigJsonExtends);
48
- (0, _sort.sortJsonKeys)(config, options?.sortJsonKeysExtends);
49
- (0, _sort.sortJsonArrayValues)(config, options?.sortJsonArrayValuesExtends);
50
- const storybookEnabled = Boolean(options?.storybook ?? false);
51
50
  if (storybookEnabled) {
52
- const storybookOptions = typeof options?.storybook !== "object" ? void 0 : options.storybook;
51
+ const storybookOptions = typeof vpOptions?.storybook !== "object" ? void 0 : vpOptions.storybook;
53
52
  config = config.append((0, _storybook.storybook)(...(!storybookOptions ? [] : [storybookOptions])));
54
53
  }
55
- const mdxEnabled = Boolean(options?.mdx ?? false);
56
54
  if (mdxEnabled) {
57
55
  const mdxOptions = {
58
- ...(typeof options?.mdx !== "object" ? null : options.mdx)
56
+ ...(typeof vpOptions?.mdx !== "object" ? null : vpOptions.mdx)
59
57
  };
60
58
  const mdxFlatCodeBlocksEnabled = Boolean(mdxOptions?.codeBlocks ?? true);
61
59
  const mdxFlatCodeBlocksOptions = {
@@ -66,9 +64,8 @@ const vdustr = (options, ...userConfigs) => {
66
64
  codeBlocks: !mdxFlatCodeBlocksEnabled ? false : mdxFlatCodeBlocksOptions
67
65
  }));
68
66
  }
69
- const prettierEnabled = Boolean(options?.prettier ?? true);
70
67
  if (prettierEnabled) {
71
- const prettierOptions = typeof options?.prettier !== "object" ? void 0 : options.prettier;
68
+ const prettierOptions = typeof vpOptions?.prettier !== "object" ? void 0 : vpOptions.prettier;
72
69
  config = config.append((0, _prettier.prettier)(...(!prettierOptions ? [] : [prettierOptions])));
73
70
  }
74
71
  config.append(...userConfigs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vp-tw/eslint-config",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "ViPro's ESLint configuration",
5
5
  "homepage": "https://github.com/vdustr/eslint-config",
6
6
  "author": {
@@ -40,7 +40,6 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@mui/types": "^7.2.21",
43
- "defu": "^6.1.4",
44
43
  "es-toolkit": "^1.31.0",
45
44
  "eslint-flat-config-utils": "^2.0.0",
46
45
  "local-pkg": "^1.0.0"