@vp-tw/eslint-config 0.0.22 → 0.0.24
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/configs/mdx.js +3 -4
- package/dist/configs/packageJson.d.ts +9 -0
- package/dist/configs/packageJson.js +25 -0
- package/dist/configs/prettier.js +2 -3
- package/dist/configs/reactCompiler.d.ts +2 -2
- package/dist/configs/reactCompiler.js +3 -4
- package/dist/configs/storybook.js +3 -4
- package/dist/eslint-typegen.d.ts +1 -1
- package/dist/esm/configs/mdx.mjs +3 -3
- package/dist/esm/configs/packageJson.d.ts +9 -0
- package/dist/esm/configs/packageJson.mjs +21 -0
- package/dist/esm/configs/prettier.mjs +6 -9
- package/dist/esm/configs/reactCompiler.d.ts +2 -2
- package/dist/esm/configs/reactCompiler.mjs +3 -3
- package/dist/esm/configs/storybook.mjs +3 -3
- package/dist/esm/eslint-typegen.d.ts +1 -1
- package/dist/esm/extends/imports.mjs +10 -13
- package/dist/esm/extends/javascript.mjs +6 -3
- package/dist/esm/extends/jsonc.d.ts +0 -2
- package/dist/esm/extends/jsonc.mjs +23 -76
- package/dist/esm/extends/react.mjs +7 -4
- package/dist/esm/extends/sort.d.ts +29 -0
- package/dist/esm/extends/sort.mjs +100 -0
- package/dist/esm/extends/typescript.mjs +6 -3
- package/dist/esm/extends/yaml.mjs +7 -4
- package/dist/esm/globs.d.ts +2 -1
- package/dist/esm/globs.mjs +3 -1
- package/dist/esm/types.d.ts +9 -3
- package/dist/esm/utils/extendsConfig.d.ts +14 -1
- package/dist/esm/utils/extendsConfig.mjs +21 -24
- package/dist/esm/utils/mergeConfig.d.ts +3 -0
- package/dist/esm/utils/mergeConfig.mjs +56 -0
- package/dist/esm/vdustr.d.ts +15 -6
- package/dist/esm/vdustr.mjs +49 -15
- package/dist/extends/imports.js +6 -7
- package/dist/extends/javascript.js +3 -4
- package/dist/extends/jsonc.d.ts +0 -2
- package/dist/extends/jsonc.js +7 -42
- package/dist/extends/react.js +4 -5
- package/dist/extends/sort.d.ts +29 -0
- package/dist/extends/sort.js +82 -0
- package/dist/extends/typescript.js +3 -4
- package/dist/extends/yaml.js +4 -4
- package/dist/globs.d.ts +2 -1
- package/dist/globs.js +3 -2
- package/dist/types.d.ts +9 -3
- package/dist/utils/extendsConfig.d.ts +14 -1
- package/dist/utils/extendsConfig.js +14 -18
- package/dist/utils/mergeConfig.d.ts +3 -0
- package/dist/utils/mergeConfig.js +47 -0
- package/dist/vdustr.d.ts +15 -6
- package/dist/vdustr.js +32 -15
- package/package.json +1 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { omit, pick } from "es-toolkit";
|
|
2
|
+
import { GLOB_CSPELL_JSON } from "../globs.mjs";
|
|
3
|
+
import { extendsConfig } from "../utils/extendsConfig.mjs";
|
|
4
|
+
import { mergeConfig } from "../utils/mergeConfig.mjs";
|
|
5
|
+
import { ignoreKeys } from "./_utils.mjs";
|
|
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
|
|
25
|
+
}
|
|
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?.sortKeys,
|
|
33
|
+
{
|
|
34
|
+
name: "vdustr/sort/json-keys",
|
|
35
|
+
rules: {
|
|
36
|
+
"jsonc/sort-keys": defaultSortJsonKeys
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
omittedConfig
|
|
40
|
+
);
|
|
41
|
+
return [config, rulesConfig];
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const sortPackageJson = async (composer, options) => {
|
|
45
|
+
extendsConfig(composer, "antfu/sort/package-json", (config) => {
|
|
46
|
+
const modifiedConfig = mergeConfig(
|
|
47
|
+
pick(options?.packageJson ?? {}, ["files", "ignores"]),
|
|
48
|
+
config
|
|
49
|
+
);
|
|
50
|
+
const omittedConfig = omit(modifiedConfig, ignoreKeys);
|
|
51
|
+
const rulesConfig = mergeConfig(
|
|
52
|
+
options?.packageJson ?? {},
|
|
53
|
+
{
|
|
54
|
+
name: "vdustr/sort/package-json",
|
|
55
|
+
rules: {
|
|
56
|
+
"jsonc/sort-array-values": "off",
|
|
57
|
+
"jsonc/sort-keys": "off"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
omittedConfig
|
|
61
|
+
);
|
|
62
|
+
return [modifiedConfig, rulesConfig];
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const sortTsconfigJson = async (composer, options) => {
|
|
66
|
+
extendsConfig(composer, "antfu/sort/tsconfig-json", (config) => {
|
|
67
|
+
const modifiedConfig = mergeConfig(
|
|
68
|
+
pick(options?.tsconfigJson ?? {}, ["files", "ignores"]),
|
|
69
|
+
config
|
|
70
|
+
);
|
|
71
|
+
const omittedConfig = omit(modifiedConfig, ignoreKeys);
|
|
72
|
+
const rulesConfig = mergeConfig(
|
|
73
|
+
options?.tsconfigJson,
|
|
74
|
+
{
|
|
75
|
+
name: "vdustr/sort/tsconfig-json",
|
|
76
|
+
rules: {
|
|
77
|
+
"jsonc/sort-keys": defaultSortJsonKeys
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
omittedConfig
|
|
81
|
+
);
|
|
82
|
+
return [modifiedConfig, rulesConfig];
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const sortJsonArrayValues = async (composer, options) => {
|
|
86
|
+
extendsConfig(composer, "vdustr/sort/json-keys", async (config) => {
|
|
87
|
+
const sortArrayValuesConfig = mergeConfig(
|
|
88
|
+
options?.sortJsonArrayValues,
|
|
89
|
+
{
|
|
90
|
+
name: "vdustr/sort/json-array-values",
|
|
91
|
+
files: [GLOB_CSPELL_JSON],
|
|
92
|
+
rules: {
|
|
93
|
+
"jsonc/sort-array-values": defaultSortJsonArrayValues
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
return [config, sortArrayValuesConfig];
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
export { sortJsonArrayValues, sortJsonKeys, sortPackageJson, sortTsconfigJson };
|
|
@@ -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 =
|
|
7
|
+
const modifiedConfig = mergeConfig(
|
|
8
|
+
pick(options?.typescript ?? {}, ["files", "ignores"]),
|
|
9
|
+
config
|
|
10
|
+
);
|
|
8
11
|
const omittedConfig = omit(modifiedConfig, ignoreKeys);
|
|
9
|
-
const rulesConfig =
|
|
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 =
|
|
10
|
+
const modifiedConfig = mergeConfig(
|
|
11
|
+
pick(options?.yaml ?? {}, ["files", "ignores"]),
|
|
12
|
+
config
|
|
13
|
+
);
|
|
11
14
|
const omittedConfig = omit(modifiedConfig, ignoreKeys);
|
|
12
|
-
const rulesConfig =
|
|
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 =
|
|
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],
|
package/dist/esm/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
|
-
|
|
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/esm/globs.mjs
CHANGED
|
@@ -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
|
};
|
package/dist/esm/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,10 +18,16 @@ type ConfigNames = VpEslintConfigNames | AntfuEslintConfigNames;
|
|
|
18
18
|
type TypedFlatConfigItem = Omit<Linter.Config<Linter.RulesRecord & Rules>, "plugins"> & {
|
|
19
19
|
plugins?: Record<string, any>;
|
|
20
20
|
};
|
|
21
|
-
|
|
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.
|
|
25
31
|
*/
|
|
26
32
|
type VpComposer = FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;
|
|
27
|
-
export type { AnyObject, Config, ConfigNames, ConfigOverrides, ReplaceAntfuEslintRulesWithVpRulesDeeply, TypedFlatConfigItem, VpComposer, };
|
|
33
|
+
export type { AnyObject, Config, ConfigNames, ConfigOverrides, ReplaceAntfuEslintRulesWithVpRulesDeeply, Rules, TypedFlatConfigItem, VpComposer, };
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { Linter } from "eslint";
|
|
2
2
|
import type { Arrayable, Awaitable, DefaultConfigNamesMap, FlatConfigComposer, StringLiteralUnion } from "eslint-flat-config-utils";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* <https://github.com/antfu/eslint-flat-config-utils/blob/ac3a9b4/src/composer.ts#L492-L512>
|
|
5
|
+
*/
|
|
6
|
+
declare function getConfigIndex(configs: Array<Linter.Config>, nameOrIndex: string | number): number;
|
|
7
|
+
/**
|
|
8
|
+
* <https://github.com/antfu/eslint-flat-config-utils/blob/ac3a9b4/src/composer.ts#L91>
|
|
9
|
+
*/
|
|
10
|
+
type Operation<T extends object = Linter.Config> = (items: Array<T>) => Promise<Array<T>>;
|
|
11
|
+
declare function extendsConfigInternal<T extends object = Linter.Config, ConfigNames extends string = keyof DefaultConfigNamesMap>(composer: FlatConfigComposer<T, ConfigNames>, sourceOrIndex: StringLiteralUnion<ConfigNames, string | number>, config: Awaitable<Arrayable<T>> | ((config: T) => Awaitable<Arrayable<T>>)): void;
|
|
12
|
+
declare const extendsConfig: typeof extendsConfigInternal & {
|
|
13
|
+
getConfigIndex: typeof getConfigIndex;
|
|
14
|
+
tryGetConfigIndex: typeof getConfigIndex;
|
|
15
|
+
pushOverations: <T extends object = Linter.Config<Linter.RulesRecord>, ConfigNames extends string = never>(composer: FlatConfigComposer<T, ConfigNames>, operations: Array<Operation<T>>) => void;
|
|
16
|
+
};
|
|
4
17
|
export { extendsConfig };
|
|
@@ -28,29 +28,26 @@ const tryGetConfigIndex = (configs, nameOrIndex) => {
|
|
|
28
28
|
return -1;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
return
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const source = items[index];
|
|
48
|
-
if (!source) return items;
|
|
49
|
-
const newConfigs = await (async () => {
|
|
50
|
-
const awaited = typeof config === "function" ? await config(source) : await config;
|
|
51
|
-
return Array.isArray(awaited) ? awaited : [awaited];
|
|
52
|
-
})();
|
|
53
|
-
return [...items.slice(0, index), ...newConfigs, ...items.slice(index + 1)];
|
|
54
|
-
});
|
|
31
|
+
const pushOverations = (composer, operations) => {
|
|
32
|
+
composer._operations.push(...operations);
|
|
33
|
+
};
|
|
34
|
+
function extendsConfigInternal(composer, sourceOrIndex, config) {
|
|
35
|
+
pushOverations(composer, [
|
|
36
|
+
async (items) => {
|
|
37
|
+
const index = tryGetConfigIndex(items, sourceOrIndex);
|
|
38
|
+
const source = items[index];
|
|
39
|
+
if (!source) return items;
|
|
40
|
+
const newConfigs = await (async () => {
|
|
41
|
+
const awaited = typeof config === "function" ? await config(source) : await config;
|
|
42
|
+
return Array.isArray(awaited) ? awaited : [awaited];
|
|
43
|
+
})();
|
|
44
|
+
return items.toSpliced(index, 1, ...newConfigs);
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
55
47
|
}
|
|
48
|
+
const extendsConfig = Object.assign(extendsConfigInternal, {
|
|
49
|
+
getConfigIndex,
|
|
50
|
+
tryGetConfigIndex,
|
|
51
|
+
pushOverations
|
|
52
|
+
});
|
|
56
53
|
export { extendsConfig };
|
|
@@ -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 };
|
package/dist/esm/vdustr.d.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import type { Config, ReplaceAntfuEslintRulesWithVpRulesDeeply, VpComposer } from "./types";
|
|
2
2
|
import antfu from "@antfu/eslint-config";
|
|
3
3
|
import { mdx } from "./configs/mdx";
|
|
4
|
+
import { packageJson } from "./configs/packageJson";
|
|
4
5
|
import { prettier } from "./configs/prettier";
|
|
5
6
|
import { storybook } from "./configs/storybook";
|
|
6
7
|
import { imports } from "./extends/imports";
|
|
7
8
|
import { javascript } from "./extends/javascript";
|
|
8
9
|
import { jsonc } from "./extends/jsonc";
|
|
9
10
|
import { react } from "./extends/react";
|
|
11
|
+
import { sortJsonArrayValues, sortJsonKeys, sortPackageJson, sortTsconfigJson } from "./extends/sort";
|
|
10
12
|
import { typescript } from "./extends/typescript";
|
|
11
13
|
import { yaml } from "./extends/yaml";
|
|
12
14
|
type Options = ReplaceAntfuEslintRulesWithVpRulesDeeply<NonNullable<Parameters<typeof antfu>[0]>> & {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
extends?: {
|
|
16
|
+
javascript?: javascript.Options;
|
|
17
|
+
imports?: imports.Options;
|
|
18
|
+
typescript?: typescript.Options;
|
|
19
|
+
jsonc?: jsonc.Options;
|
|
20
|
+
sortPackageJson?: sortPackageJson.Options;
|
|
21
|
+
sortTsConfigJson?: sortTsconfigJson.Options;
|
|
22
|
+
sortJsonKeys?: sortJsonKeys.Options;
|
|
23
|
+
sortJsonArrayValues?: sortJsonArrayValues.Options;
|
|
24
|
+
yaml?: yaml.Options;
|
|
25
|
+
react?: react.Options;
|
|
26
|
+
};
|
|
27
|
+
packageJson?: boolean | packageJson.Options;
|
|
19
28
|
mdx?: boolean | mdx.Options;
|
|
20
29
|
storybook?: boolean | storybook.Options;
|
|
21
30
|
prettier?: boolean | prettier.Options;
|
package/dist/esm/vdustr.mjs
CHANGED
|
@@ -1,36 +1,71 @@
|
|
|
1
1
|
import antfu from "@antfu/eslint-config";
|
|
2
|
+
import { omit, pick } from "es-toolkit";
|
|
2
3
|
import { mdx } from "./configs/mdx.mjs";
|
|
4
|
+
import { packageJson } from "./configs/packageJson.mjs";
|
|
3
5
|
import { prettier } from "./configs/prettier.mjs";
|
|
4
6
|
import { storybook } from "./configs/storybook.mjs";
|
|
5
7
|
import { imports } from "./extends/imports.mjs";
|
|
6
8
|
import { javascript } from "./extends/javascript.mjs";
|
|
7
9
|
import { jsonc } from "./extends/jsonc.mjs";
|
|
8
10
|
import { react } from "./extends/react.mjs";
|
|
11
|
+
import {
|
|
12
|
+
sortJsonArrayValues,
|
|
13
|
+
sortJsonKeys,
|
|
14
|
+
sortPackageJson,
|
|
15
|
+
sortTsconfigJson
|
|
16
|
+
} from "./extends/sort.mjs";
|
|
9
17
|
import { typescript } from "./extends/typescript.mjs";
|
|
10
18
|
import { yaml } from "./extends/yaml.mjs";
|
|
19
|
+
const ownedConfigNames = [
|
|
20
|
+
"extends",
|
|
21
|
+
"packageJson",
|
|
22
|
+
"mdx",
|
|
23
|
+
"storybook",
|
|
24
|
+
"prettier"
|
|
25
|
+
];
|
|
11
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);
|
|
12
36
|
let config = antfu({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
37
|
+
...antfuOptions,
|
|
38
|
+
...!prettierEnabled ? null : {
|
|
39
|
+
// Forcibly disable style rules if prettier is enabled.
|
|
40
|
+
stylistic: false
|
|
41
|
+
}
|
|
16
42
|
});
|
|
17
|
-
javascript(config,
|
|
18
|
-
imports(config,
|
|
19
|
-
typescript(config,
|
|
20
|
-
jsonc(config,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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?.sortPackageJson);
|
|
49
|
+
sortTsconfigJson(config, vpOptions?.extends?.sortTsConfigJson);
|
|
50
|
+
sortJsonKeys(config, vpOptions?.extends?.sortJsonKeys);
|
|
51
|
+
sortJsonArrayValues(config, vpOptions?.extends?.sortJsonArrayValues);
|
|
52
|
+
yaml(config, vpOptions?.extends?.yaml);
|
|
53
|
+
react(config, vpOptions?.extends?.react);
|
|
54
|
+
if (packageJsonEnabled) {
|
|
55
|
+
const packageJsonOptions = typeof vpOptions?.packageJson !== "object" ? void 0 : vpOptions.packageJson;
|
|
56
|
+
config = config.append(
|
|
57
|
+
packageJson(...!packageJsonOptions ? [] : [packageJsonOptions])
|
|
58
|
+
);
|
|
59
|
+
}
|
|
24
60
|
if (storybookEnabled) {
|
|
25
|
-
const storybookOptions = typeof
|
|
61
|
+
const storybookOptions = typeof vpOptions?.storybook !== "object" ? void 0 : vpOptions.storybook;
|
|
26
62
|
config = config.append(
|
|
27
63
|
storybook(...!storybookOptions ? [] : [storybookOptions])
|
|
28
64
|
);
|
|
29
65
|
}
|
|
30
|
-
const mdxEnabled = Boolean(options?.mdx ?? false);
|
|
31
66
|
if (mdxEnabled) {
|
|
32
67
|
const mdxOptions = {
|
|
33
|
-
...typeof
|
|
68
|
+
...typeof vpOptions?.mdx !== "object" ? null : vpOptions.mdx
|
|
34
69
|
};
|
|
35
70
|
const mdxFlatCodeBlocksEnabled = Boolean(
|
|
36
71
|
mdxOptions?.codeBlocks ?? true
|
|
@@ -45,9 +80,8 @@ const vdustr = (options, ...userConfigs) => {
|
|
|
45
80
|
})
|
|
46
81
|
);
|
|
47
82
|
}
|
|
48
|
-
const prettierEnabled = Boolean(options?.prettier ?? true);
|
|
49
83
|
if (prettierEnabled) {
|
|
50
|
-
const prettierOptions = typeof
|
|
84
|
+
const prettierOptions = typeof vpOptions?.prettier !== "object" ? void 0 : vpOptions.prettier;
|
|
51
85
|
config = config.append(
|
|
52
86
|
prettier(...!prettierOptions ? [] : [prettierOptions])
|
|
53
87
|
);
|
package/dist/extends/imports.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
15
|
+
const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.javascript ?? {}, ["files", "ignores"]), {
|
|
17
16
|
name: "vdustr/javascript/rules",
|
|
18
17
|
rules: {
|
|
19
18
|
/**
|
package/dist/extends/jsonc.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import type { ConfigOverrides, VpComposer } from "../types";
|
|
|
2
2
|
declare namespace jsonc {
|
|
3
3
|
interface Options {
|
|
4
4
|
jsonc?: ConfigOverrides;
|
|
5
|
-
sortArrayValues?: ConfigOverrides;
|
|
6
|
-
packageJson?: ConfigOverrides;
|
|
7
5
|
}
|
|
8
6
|
}
|
|
9
7
|
declare const jsonc: (composer: VpComposer, options?: jsonc.Options) => Promise<void>;
|
package/dist/extends/jsonc.js
CHANGED
|
@@ -4,61 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.jsonc = void 0;
|
|
7
|
-
var _eslintConfig = require("@antfu/eslint-config");
|
|
8
|
-
var _defu = _interopRequireDefault(require("defu"));
|
|
9
7
|
var _esToolkit = require("es-toolkit");
|
|
10
8
|
var _globs = require("../globs");
|
|
11
9
|
var _extendsConfig = require("../utils/extendsConfig");
|
|
10
|
+
var _mergeConfig = require("../utils/mergeConfig");
|
|
12
11
|
var _utils = require("./_utils");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
12
|
const jsonc = async (composer, options) => {
|
|
15
|
-
await (0, _eslintConfig.ensurePackages)(["eslint-plugin-package-json"]);
|
|
16
|
-
const packageJson = await (0, _eslintConfig.interopDefault)(Promise.resolve().then(() => require("eslint-plugin-package-json/configs/recommended")));
|
|
17
13
|
(0, _extendsConfig.extendsConfig)(composer, "antfu/jsonc/rules", config => {
|
|
18
|
-
const modifiedConfig = (0,
|
|
19
|
-
files: [_globs.GLOB_CODE_WORKSPACE]
|
|
20
|
-
ignores: [_globs.GLOB_PACKAGE_JSON]
|
|
14
|
+
const modifiedConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.pick)(options?.jsonc ?? {}, ["files", "ignores"]), config, {
|
|
15
|
+
files: [_globs.GLOB_CODE_WORKSPACE]
|
|
21
16
|
});
|
|
22
17
|
const omittedConfig = (0, _esToolkit.omit)(modifiedConfig, _utils.ignoreKeys);
|
|
23
|
-
const rulesConfig = (0,
|
|
18
|
+
const rulesConfig = (0, _mergeConfig.mergeConfig)((0, _esToolkit.omit)(options?.jsonc ?? {}, ["files", "ignores"]), {
|
|
24
19
|
name: "vdustr/jsonc/rules",
|
|
25
20
|
rules: {
|
|
26
21
|
/**
|
|
27
|
-
*
|
|
22
|
+
* No overrides for now.
|
|
28
23
|
*/
|
|
29
|
-
"jsonc/sort-keys": ["error", {
|
|
30
|
-
pathPattern: ".*",
|
|
31
|
-
order: {
|
|
32
|
-
type: "asc",
|
|
33
|
-
caseSensitive: false,
|
|
34
|
-
natural: true
|
|
35
|
-
}
|
|
36
|
-
}]
|
|
37
24
|
}
|
|
38
25
|
}, omittedConfig);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
files: [_globs.GLOB_CSPELL_JSON],
|
|
42
|
-
rules: {
|
|
43
|
-
"jsonc/sort-array-values": ["error", {
|
|
44
|
-
pathPattern: ".*",
|
|
45
|
-
order: {
|
|
46
|
-
type: "asc",
|
|
47
|
-
caseSensitive: false,
|
|
48
|
-
natural: true
|
|
49
|
-
}
|
|
50
|
-
}]
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const packageJsonSetupConfig = {
|
|
54
|
-
plugins: packageJson.plugins,
|
|
55
|
-
name: "vdustr/package-json/setup"
|
|
56
|
-
};
|
|
57
|
-
const packageJsonRulesConfig = (0, _defu.default)(options?.packageJson, {
|
|
58
|
-
...(0, _esToolkit.omit)(packageJson, ["name", "plugins"]),
|
|
59
|
-
name: "vdustr/package-json/rules"
|
|
60
|
-
});
|
|
61
|
-
return [modifiedConfig, rulesConfig, sortArrayValuesConfig, packageJsonSetupConfig, packageJsonRulesConfig];
|
|
62
|
-
}, ["antfu/sort/package-json", "antfu/sort/tsconfig-json"]);
|
|
26
|
+
return [modifiedConfig, rulesConfig];
|
|
27
|
+
});
|
|
63
28
|
};
|
|
64
29
|
exports.jsonc = jsonc;
|
package/dist/extends/react.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
24
|
+
reactCompiler: (0, _mergeConfig.mergeConfig)(options?.reactCompiler, (0, _esToolkit.pick)(omittedConfig, ["files", "ignores"]))
|
|
26
25
|
});
|
|
27
26
|
return [modifiedConfig, rulesConfig, ...reactCompilerConfigs];
|
|
28
27
|
});
|