@coderwyd/eslint-config 2.2.2 → 2.3.1
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/cli.cjs +13 -12
- package/dist/cli.js +13 -12
- package/dist/index.cjs +99 -28
- package/dist/index.d.cts +155 -9
- package/dist/index.d.ts +155 -9
- package/dist/index.js +86 -27
- package/package.json +22 -22
package/dist/cli.cjs
CHANGED
|
@@ -46,32 +46,32 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
|
|
|
46
46
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
47
47
|
|
|
48
48
|
// package.json
|
|
49
|
-
var version = "2.
|
|
49
|
+
var version = "2.3.1";
|
|
50
50
|
var devDependencies = {
|
|
51
51
|
"@antfu/ni": "^0.21.12",
|
|
52
|
-
"@types/eslint": "^8.56.
|
|
52
|
+
"@types/eslint": "^8.56.6",
|
|
53
53
|
"@types/fs-extra": "^11.0.4",
|
|
54
|
-
"@types/node": "^20.11.
|
|
54
|
+
"@types/node": "^20.11.30",
|
|
55
55
|
"@types/prompts": "^2.4.9",
|
|
56
56
|
"@types/yargs": "^17.0.32",
|
|
57
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
57
|
+
"@unocss/eslint-plugin": "^0.58.7",
|
|
58
58
|
bumpp: "^9.4.0",
|
|
59
|
-
eslint: "
|
|
60
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
61
|
-
"eslint-plugin-react": "^7.34.
|
|
59
|
+
eslint: "9.0.0-rc.0",
|
|
60
|
+
"eslint-flat-config-viewer": "^0.1.14",
|
|
61
|
+
"eslint-plugin-react": "^7.34.1",
|
|
62
62
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
63
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
63
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
64
64
|
"eslint-plugin-svelte": "^2.35.1",
|
|
65
65
|
execa: "^8.0.1",
|
|
66
66
|
"fast-glob": "^3.3.2",
|
|
67
67
|
"fs-extra": "^11.2.0",
|
|
68
68
|
"lint-staged": "^15.2.2",
|
|
69
69
|
rimraf: "^5.0.5",
|
|
70
|
-
"simple-git-hooks": "^2.
|
|
70
|
+
"simple-git-hooks": "^2.11.1",
|
|
71
71
|
"svelte-eslint-parser": "^0.33.1",
|
|
72
72
|
tsup: "^8.0.2",
|
|
73
73
|
tsx: "^4.7.1",
|
|
74
|
-
typescript: "^5.
|
|
74
|
+
typescript: "^5.4.3"
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
// src/cli/constants.ts
|
|
@@ -97,7 +97,6 @@ var vscodeSettingsString = `
|
|
|
97
97
|
// Enable eslint for all supported languages
|
|
98
98
|
"eslint.validate": [
|
|
99
99
|
"svelte",
|
|
100
|
-
"astro",
|
|
101
100
|
"html",
|
|
102
101
|
"css",
|
|
103
102
|
"less",
|
|
@@ -107,7 +106,9 @@ var vscodeSettingsString = `
|
|
|
107
106
|
"yaml",
|
|
108
107
|
"yml",
|
|
109
108
|
"markdown",
|
|
110
|
-
"toml"
|
|
109
|
+
"toml",
|
|
110
|
+
"gql",
|
|
111
|
+
"graphql"
|
|
111
112
|
]
|
|
112
113
|
`;
|
|
113
114
|
|
package/dist/cli.js
CHANGED
|
@@ -17,32 +17,32 @@ import parse from "parse-gitignore";
|
|
|
17
17
|
import c from "picocolors";
|
|
18
18
|
|
|
19
19
|
// package.json
|
|
20
|
-
var version = "2.
|
|
20
|
+
var version = "2.3.1";
|
|
21
21
|
var devDependencies = {
|
|
22
22
|
"@antfu/ni": "^0.21.12",
|
|
23
|
-
"@types/eslint": "^8.56.
|
|
23
|
+
"@types/eslint": "^8.56.6",
|
|
24
24
|
"@types/fs-extra": "^11.0.4",
|
|
25
|
-
"@types/node": "^20.11.
|
|
25
|
+
"@types/node": "^20.11.30",
|
|
26
26
|
"@types/prompts": "^2.4.9",
|
|
27
27
|
"@types/yargs": "^17.0.32",
|
|
28
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
28
|
+
"@unocss/eslint-plugin": "^0.58.7",
|
|
29
29
|
bumpp: "^9.4.0",
|
|
30
|
-
eslint: "
|
|
31
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
32
|
-
"eslint-plugin-react": "^7.34.
|
|
30
|
+
eslint: "9.0.0-rc.0",
|
|
31
|
+
"eslint-flat-config-viewer": "^0.1.14",
|
|
32
|
+
"eslint-plugin-react": "^7.34.1",
|
|
33
33
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
34
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
34
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
35
35
|
"eslint-plugin-svelte": "^2.35.1",
|
|
36
36
|
execa: "^8.0.1",
|
|
37
37
|
"fast-glob": "^3.3.2",
|
|
38
38
|
"fs-extra": "^11.2.0",
|
|
39
39
|
"lint-staged": "^15.2.2",
|
|
40
40
|
rimraf: "^5.0.5",
|
|
41
|
-
"simple-git-hooks": "^2.
|
|
41
|
+
"simple-git-hooks": "^2.11.1",
|
|
42
42
|
"svelte-eslint-parser": "^0.33.1",
|
|
43
43
|
tsup: "^8.0.2",
|
|
44
44
|
tsx: "^4.7.1",
|
|
45
|
-
typescript: "^5.
|
|
45
|
+
typescript: "^5.4.3"
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// src/cli/constants.ts
|
|
@@ -68,7 +68,6 @@ var vscodeSettingsString = `
|
|
|
68
68
|
// Enable eslint for all supported languages
|
|
69
69
|
"eslint.validate": [
|
|
70
70
|
"svelte",
|
|
71
|
-
"astro",
|
|
72
71
|
"html",
|
|
73
72
|
"css",
|
|
74
73
|
"less",
|
|
@@ -78,7 +77,9 @@ var vscodeSettingsString = `
|
|
|
78
77
|
"yaml",
|
|
79
78
|
"yml",
|
|
80
79
|
"markdown",
|
|
81
|
-
"toml"
|
|
80
|
+
"toml",
|
|
81
|
+
"gql",
|
|
82
|
+
"graphql"
|
|
82
83
|
]
|
|
83
84
|
`;
|
|
84
85
|
|
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
33
|
+
combine: () => combine,
|
|
34
|
+
defaultPluginRenaming: () => defaultPluginRenaming,
|
|
35
|
+
defineConfig: () => defineConfig,
|
|
36
|
+
ensurePackages: () => ensurePackages,
|
|
37
|
+
getOverrides: () => getOverrides,
|
|
38
|
+
getVueVersion: () => getVueVersion,
|
|
39
|
+
interopDefault: () => interopDefault,
|
|
40
|
+
loadPrettierConfig: () => loadPrettierConfig,
|
|
41
|
+
parserPlain: () => parserPlain,
|
|
42
|
+
renamePluginInConfigs: () => renamePluginInConfigs,
|
|
43
|
+
renameRules: () => renameRules,
|
|
44
|
+
resolveSubOptions: () => resolveSubOptions,
|
|
45
|
+
toArray: () => toArray
|
|
34
46
|
});
|
|
35
47
|
module.exports = __toCommonJS(src_exports);
|
|
36
48
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
@@ -48,7 +60,7 @@ var DEFAULT_PRETTIER_RULES = {
|
|
|
48
60
|
// src/plugins/index.ts
|
|
49
61
|
var import_eslint_plugin_antfu = __toESM(require("eslint-plugin-antfu"), 1);
|
|
50
62
|
var import_eslint_plugin_eslint_comments = __toESM(require("eslint-plugin-eslint-comments"), 1);
|
|
51
|
-
var pluginImport = __toESM(require("eslint-plugin-
|
|
63
|
+
var pluginImport = __toESM(require("eslint-plugin-import-x"), 1);
|
|
52
64
|
var import_eslint_plugin_n = __toESM(require("eslint-plugin-n"), 1);
|
|
53
65
|
var import_eslint_plugin_unicorn = __toESM(require("eslint-plugin-unicorn"), 1);
|
|
54
66
|
var import_eslint_plugin_unused_imports = __toESM(require("eslint-plugin-unused-imports"), 1);
|
|
@@ -91,7 +103,7 @@ var GLOB_JSONC = "**/*.jsonc";
|
|
|
91
103
|
var GLOB_MARKDOWN = "**/*.md";
|
|
92
104
|
var GLOB_YAML = "**/*.y?(a)ml";
|
|
93
105
|
var GLOB_TOML = "**/*.toml";
|
|
94
|
-
var GLOB_GRAPHQL = "**/*.
|
|
106
|
+
var GLOB_GRAPHQL = "**/*.{g,graph}ql";
|
|
95
107
|
var GLOB_PRETTIER_LINT = [GLOB_SRC, GLOB_VUE];
|
|
96
108
|
var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
97
109
|
var GLOB_TESTS = [
|
|
@@ -180,10 +192,7 @@ async function imports() {
|
|
|
180
192
|
],
|
|
181
193
|
...{
|
|
182
194
|
// format
|
|
183
|
-
"import/newline-after-import": [
|
|
184
|
-
"error",
|
|
185
|
-
{ considerComments: true, count: 1 }
|
|
186
|
-
]
|
|
195
|
+
"import/newline-after-import": ["error", { count: 1 }]
|
|
187
196
|
}
|
|
188
197
|
}
|
|
189
198
|
},
|
|
@@ -488,15 +497,34 @@ async function combine(...configs) {
|
|
|
488
497
|
const resolved = await Promise.all(configs);
|
|
489
498
|
return resolved.flat();
|
|
490
499
|
}
|
|
491
|
-
function renameRules(rules,
|
|
500
|
+
function renameRules(rules, map) {
|
|
492
501
|
return Object.fromEntries(
|
|
493
502
|
Object.entries(rules).map(([key, value]) => {
|
|
494
|
-
|
|
495
|
-
|
|
503
|
+
for (const [from, to] of Object.entries(map)) {
|
|
504
|
+
if (key.startsWith(`${from}/`))
|
|
505
|
+
return [to + key.slice(from.length), value];
|
|
506
|
+
}
|
|
496
507
|
return [key, value];
|
|
497
508
|
})
|
|
498
509
|
);
|
|
499
510
|
}
|
|
511
|
+
function renamePluginInConfigs(configs, map) {
|
|
512
|
+
return configs.map((i) => {
|
|
513
|
+
const clone = { ...i };
|
|
514
|
+
if (clone.rules)
|
|
515
|
+
clone.rules = renameRules(clone.rules, map);
|
|
516
|
+
if (clone.plugins) {
|
|
517
|
+
clone.plugins = Object.fromEntries(
|
|
518
|
+
Object.entries(clone.plugins).map(([key, value]) => {
|
|
519
|
+
if (key in map)
|
|
520
|
+
return [map[key], value];
|
|
521
|
+
return [key, value];
|
|
522
|
+
})
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
return clone;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
500
528
|
function getVueVersion() {
|
|
501
529
|
const pkg = (0, import_local_pkg.getPackageInfoSync)("vue", { paths: [import_node_process.default.cwd()] });
|
|
502
530
|
if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
|
|
@@ -754,6 +782,22 @@ async function sortPackageJson() {
|
|
|
754
782
|
{
|
|
755
783
|
order: ["types", "import", "require", "default"],
|
|
756
784
|
pathPattern: "^exports.*$"
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
order: [
|
|
788
|
+
// client hooks only
|
|
789
|
+
"pre-commit",
|
|
790
|
+
"prepare-commit-msg",
|
|
791
|
+
"commit-msg",
|
|
792
|
+
"post-commit",
|
|
793
|
+
"pre-rebase",
|
|
794
|
+
"post-rewrite",
|
|
795
|
+
"post-checkout",
|
|
796
|
+
"post-merge",
|
|
797
|
+
"pre-push",
|
|
798
|
+
"pre-auto-gc"
|
|
799
|
+
],
|
|
800
|
+
pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
|
|
757
801
|
}
|
|
758
802
|
]
|
|
759
803
|
}
|
|
@@ -991,14 +1035,11 @@ async function typescript(options = {}) {
|
|
|
991
1035
|
rules: {
|
|
992
1036
|
...renameRules(
|
|
993
1037
|
pluginTs.configs["eslint-recommended"].overrides[0].rules,
|
|
994
|
-
"@typescript-eslint
|
|
995
|
-
"ts/"
|
|
996
|
-
),
|
|
997
|
-
...renameRules(
|
|
998
|
-
pluginTs.configs.strict.rules,
|
|
999
|
-
"@typescript-eslint/",
|
|
1000
|
-
"ts/"
|
|
1038
|
+
{ "@typescript-eslint": "ts" }
|
|
1001
1039
|
),
|
|
1040
|
+
...renameRules(pluginTs.configs.strict.rules, {
|
|
1041
|
+
"@typescript-eslint": "ts"
|
|
1042
|
+
}),
|
|
1002
1043
|
"no-dupe-class-members": "off",
|
|
1003
1044
|
"no-loss-of-precision": "off",
|
|
1004
1045
|
"no-redeclare": "off",
|
|
@@ -1506,12 +1547,19 @@ async function unocss(options = {}) {
|
|
|
1506
1547
|
async function formatter(options = {}, prettierRules2 = {}) {
|
|
1507
1548
|
const {
|
|
1508
1549
|
css = true,
|
|
1509
|
-
graphql,
|
|
1550
|
+
graphql = false,
|
|
1510
1551
|
html = true,
|
|
1511
|
-
markdown,
|
|
1512
|
-
toml,
|
|
1513
|
-
yaml
|
|
1514
|
-
} = options
|
|
1552
|
+
markdown = false,
|
|
1553
|
+
toml = false,
|
|
1554
|
+
yaml = false
|
|
1555
|
+
} = typeof options === "object" ? options : {
|
|
1556
|
+
css: true,
|
|
1557
|
+
graphql: true,
|
|
1558
|
+
html: true,
|
|
1559
|
+
markdown: true,
|
|
1560
|
+
toml: true,
|
|
1561
|
+
yaml: true
|
|
1562
|
+
};
|
|
1515
1563
|
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
1516
1564
|
function createPrettierFormatter(files, parser, plugins) {
|
|
1517
1565
|
const rules = {
|
|
@@ -1698,6 +1746,7 @@ async function tailwindcss(options = {}) {
|
|
|
1698
1746
|
"tailwindcss/no-arbitrary-value": "off",
|
|
1699
1747
|
"tailwindcss/no-contradicting-classname": "error",
|
|
1700
1748
|
"tailwindcss/no-custom-classname": "off",
|
|
1749
|
+
"tailwindcss/no-unnecessary-arbitrary-value": "warn",
|
|
1701
1750
|
...overrides
|
|
1702
1751
|
}
|
|
1703
1752
|
}
|
|
@@ -1725,8 +1774,16 @@ var flatConfigProps = [
|
|
|
1725
1774
|
"rules",
|
|
1726
1775
|
"settings"
|
|
1727
1776
|
];
|
|
1777
|
+
var defaultPluginRenaming = {
|
|
1778
|
+
"@typescript-eslint": "ts",
|
|
1779
|
+
"import-x": "import",
|
|
1780
|
+
n: "node",
|
|
1781
|
+
vitest: "test",
|
|
1782
|
+
yml: "yaml"
|
|
1783
|
+
};
|
|
1728
1784
|
async function defineConfig(options = {}, ...userConfigs) {
|
|
1729
1785
|
const {
|
|
1786
|
+
autoRenamePlugins = true,
|
|
1730
1787
|
componentExts = [],
|
|
1731
1788
|
gitignore: enableGitignore = true,
|
|
1732
1789
|
isInEditor: isInEditor2 = isInEditor,
|
|
@@ -1850,10 +1907,10 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1850
1907
|
);
|
|
1851
1908
|
Object.assign(prettierRules2, prettierConfig);
|
|
1852
1909
|
}
|
|
1853
|
-
configs.push(
|
|
1854
|
-
|
|
1855
|
-
formatter(options.formatter, prettierRules2)
|
|
1856
|
-
|
|
1910
|
+
configs.push(prettier(options.formatter ? prettierRules2 : {}));
|
|
1911
|
+
if (options.formatter) {
|
|
1912
|
+
configs.push(formatter(options.formatter, prettierRules2));
|
|
1913
|
+
}
|
|
1857
1914
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
1858
1915
|
if (key in options)
|
|
1859
1916
|
acc[key] = options[key];
|
|
@@ -1861,10 +1918,24 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1861
1918
|
}, {});
|
|
1862
1919
|
if (Object.keys(fusedConfig).length > 0)
|
|
1863
1920
|
configs.push([fusedConfig]);
|
|
1864
|
-
const merged = combine(...configs, ...userConfigs);
|
|
1921
|
+
const merged = await combine(...configs, ...userConfigs);
|
|
1922
|
+
if (autoRenamePlugins)
|
|
1923
|
+
return renamePluginInConfigs(merged, defaultPluginRenaming);
|
|
1865
1924
|
return merged;
|
|
1866
1925
|
}
|
|
1867
1926
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1868
1927
|
0 && (module.exports = {
|
|
1869
|
-
|
|
1928
|
+
combine,
|
|
1929
|
+
defaultPluginRenaming,
|
|
1930
|
+
defineConfig,
|
|
1931
|
+
ensurePackages,
|
|
1932
|
+
getOverrides,
|
|
1933
|
+
getVueVersion,
|
|
1934
|
+
interopDefault,
|
|
1935
|
+
loadPrettierConfig,
|
|
1936
|
+
parserPlain,
|
|
1937
|
+
renamePluginInConfigs,
|
|
1938
|
+
renameRules,
|
|
1939
|
+
resolveSubOptions,
|
|
1940
|
+
toArray
|
|
1870
1941
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
2
2
|
import { ParserOptions } from '@typescript-eslint/parser';
|
|
3
|
-
import { RuleConfig,
|
|
4
|
-
import { RequiredOptions, LiteralUnion
|
|
3
|
+
import { RuleConfig, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules, FlatESLintConfigItem } from '@antfu/eslint-define-config';
|
|
4
|
+
import { BuiltInParserName, RequiredOptions, LiteralUnion } from 'prettier';
|
|
5
5
|
import { Linter } from 'eslint';
|
|
6
6
|
import { Rules } from 'eslint-plugin-antfu';
|
|
7
7
|
|
|
@@ -284,6 +284,44 @@ interface NoCustomClassnameRule {
|
|
|
284
284
|
'tailwindcss/no-custom-classname': NoCustomClassnameRuleConfig
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Option.
|
|
289
|
+
*/
|
|
290
|
+
interface NoUnnecessaryArbitraryValueOption {
|
|
291
|
+
callees?: string[]
|
|
292
|
+
ignoredKeys?: string[]
|
|
293
|
+
config?: string | Record<string, any>
|
|
294
|
+
tags?: string[]
|
|
295
|
+
|
|
296
|
+
[k: string]: any
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Options.
|
|
301
|
+
*/
|
|
302
|
+
type NoUnnecessaryArbitraryValueOptions = [
|
|
303
|
+
NoUnnecessaryArbitraryValueOption?,
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Avoid unjustified arbitrary classnames.
|
|
308
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
309
|
+
*/
|
|
310
|
+
type NoUnnecessaryArbitraryValueRuleConfig =
|
|
311
|
+
RuleConfig<NoUnnecessaryArbitraryValueOptions>
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Avoid unjustified arbitrary classnames.
|
|
315
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
316
|
+
*/
|
|
317
|
+
interface NoUnnecessaryArbitraryValueRule {
|
|
318
|
+
/**
|
|
319
|
+
* Avoid unjustified arbitrary classnames.
|
|
320
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
321
|
+
*/
|
|
322
|
+
'tailwindcss/no-unnecessary-arbitrary-value': NoUnnecessaryArbitraryValueRuleConfig
|
|
323
|
+
}
|
|
324
|
+
|
|
287
325
|
/**
|
|
288
326
|
* All TailwindCss rules.
|
|
289
327
|
*/
|
|
@@ -293,7 +331,8 @@ type TailwindCssRules = ClassnamesOrderRule &
|
|
|
293
331
|
MigrationFromTailwind_2Rule &
|
|
294
332
|
NoArbitraryValueRule &
|
|
295
333
|
NoContradictingClassnameRule &
|
|
296
|
-
NoCustomClassnameRule
|
|
334
|
+
NoCustomClassnameRule &
|
|
335
|
+
NoUnnecessaryArbitraryValueRule
|
|
297
336
|
|
|
298
337
|
type WrapRuleConfig<T extends {
|
|
299
338
|
[key: string]: any;
|
|
@@ -318,6 +357,12 @@ type FlatConfigItem = Omit<FlatESLintConfigItem<EslintFlatRules, false>, 'plugin
|
|
|
318
357
|
type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
|
|
319
358
|
|
|
320
359
|
type Awaitable<T> = T | Promise<T>;
|
|
360
|
+
interface OptionsFiles {
|
|
361
|
+
/**
|
|
362
|
+
* Override the `files` option to provide custom globs.
|
|
363
|
+
*/
|
|
364
|
+
files?: string[];
|
|
365
|
+
}
|
|
321
366
|
type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
|
|
322
367
|
interface OptionsFormatters {
|
|
323
368
|
/**
|
|
@@ -372,6 +417,12 @@ interface OptionsTypeScriptWithTypes {
|
|
|
372
417
|
*/
|
|
373
418
|
tsconfigPath?: string | string[];
|
|
374
419
|
}
|
|
420
|
+
interface OptionsHasTypeScript {
|
|
421
|
+
typescript?: boolean;
|
|
422
|
+
}
|
|
423
|
+
interface OptionsIsInEditor {
|
|
424
|
+
isInEditor?: boolean;
|
|
425
|
+
}
|
|
375
426
|
interface OptionsOverrides {
|
|
376
427
|
overrides?: FlatConfigItem['rules'];
|
|
377
428
|
}
|
|
@@ -487,9 +538,6 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
487
538
|
/**
|
|
488
539
|
* Use external formatters to format files.
|
|
489
540
|
*
|
|
490
|
-
* Requires installing:
|
|
491
|
-
* - `eslint-plugin-prettier`
|
|
492
|
-
*
|
|
493
541
|
* @default
|
|
494
542
|
* {
|
|
495
543
|
* "html": true,
|
|
@@ -499,8 +547,10 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
499
547
|
* "yaml": false
|
|
500
548
|
* "toml": false
|
|
501
549
|
* }
|
|
550
|
+
*
|
|
551
|
+
* When set to `true`, it will enable all formatters.
|
|
502
552
|
*/
|
|
503
|
-
formatter?: OptionsFormatters;
|
|
553
|
+
formatter?: boolean | OptionsFormatters;
|
|
504
554
|
/**
|
|
505
555
|
* Default prettier rules
|
|
506
556
|
*
|
|
@@ -521,11 +571,107 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
521
571
|
* @default auto-detect based on the process.env
|
|
522
572
|
*/
|
|
523
573
|
isInEditor?: boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Automatically rename plugins in the config.
|
|
576
|
+
*
|
|
577
|
+
* @default true
|
|
578
|
+
*/
|
|
579
|
+
autoRenamePlugins?: boolean;
|
|
524
580
|
}
|
|
525
|
-
|
|
581
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
582
|
+
|
|
583
|
+
declare const parserPlain: {
|
|
584
|
+
meta: {
|
|
585
|
+
name: string;
|
|
586
|
+
};
|
|
587
|
+
parseForESLint: (code: string) => {
|
|
588
|
+
ast: {
|
|
589
|
+
body: never[];
|
|
590
|
+
comments: never[];
|
|
591
|
+
loc: {
|
|
592
|
+
end: number;
|
|
593
|
+
start: number;
|
|
594
|
+
};
|
|
595
|
+
range: number[];
|
|
596
|
+
tokens: never[];
|
|
597
|
+
type: string;
|
|
598
|
+
};
|
|
599
|
+
scopeManager: null;
|
|
600
|
+
services: {
|
|
601
|
+
isPlain: boolean;
|
|
602
|
+
};
|
|
603
|
+
visitorKeys: {
|
|
604
|
+
Program: never[];
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Combine array and non-array configs into a single array.
|
|
610
|
+
*/
|
|
611
|
+
declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
|
|
612
|
+
/**
|
|
613
|
+
* Rename plugin prefixes in a rule object.
|
|
614
|
+
* Accepts a map of prefixes to rename.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* import { renameRules } from '@coderwyd/eslint-config'
|
|
619
|
+
*
|
|
620
|
+
* export default [{
|
|
621
|
+
* rules: renameRules(
|
|
622
|
+
* {
|
|
623
|
+
* '@typescript-eslint/indent': 'error'
|
|
624
|
+
* },
|
|
625
|
+
* { '@typescript-eslint': 'ts' }
|
|
626
|
+
* )
|
|
627
|
+
* }]
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
|
|
631
|
+
[k: string]: any;
|
|
632
|
+
};
|
|
633
|
+
/**
|
|
634
|
+
* Rename plugin names a flat configs array
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```ts
|
|
638
|
+
* import { renamePluginInConfigs } from '@antfu/eslint-config'
|
|
639
|
+
* import someConfigs from './some-configs'
|
|
640
|
+
*
|
|
641
|
+
* export default renamePluginInConfigs(someConfigs, {
|
|
642
|
+
* '@typescript-eslint': 'ts',
|
|
643
|
+
* 'import-x': 'import',
|
|
644
|
+
* })
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
|
|
648
|
+
declare function getVueVersion(): number;
|
|
649
|
+
declare function toArray<T>(value: T | T[]): T[];
|
|
650
|
+
declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
|
|
651
|
+
default: infer U;
|
|
652
|
+
} ? U : T>;
|
|
653
|
+
declare function ensurePackages(packages: string[]): Promise<void>;
|
|
654
|
+
declare function loadPrettierConfig(cwd: string): Promise<Partial<PrettierOptions>>;
|
|
655
|
+
declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
|
|
656
|
+
declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): {};
|
|
657
|
+
|
|
658
|
+
declare const defaultPluginRenaming: {
|
|
659
|
+
'@typescript-eslint': string;
|
|
660
|
+
'import-x': string;
|
|
661
|
+
n: string;
|
|
662
|
+
vitest: string;
|
|
663
|
+
yml: string;
|
|
664
|
+
};
|
|
526
665
|
/**
|
|
527
666
|
* Construct an array of ESLint flat config items.
|
|
667
|
+
*
|
|
668
|
+
* @param {OptionsConfig & FlatConfigItem} options
|
|
669
|
+
* The options for generating the ESLint configurations.
|
|
670
|
+
* @param {Awaitable<UserConfigItem | UserConfigItem[]>[]} userConfigs
|
|
671
|
+
* The user configurations to be merged with the generated configurations.
|
|
672
|
+
* @returns {Promise<UserConfigItem[]>}
|
|
673
|
+
* The merged ESLint configurations.
|
|
528
674
|
*/
|
|
529
675
|
declare function defineConfig(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
|
|
530
676
|
|
|
531
|
-
export { defineConfig };
|
|
677
|
+
export { type Awaitable, type EslintFlatRules, type FlatConfigItem, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type PartialPrettierExtendedOptions, type PrettierParser, type ResolvedOptions, type UserConfigItem, type WrapRuleConfig, combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, getVueVersion, interopDefault, loadPrettierConfig, parserPlain, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
|
|
2
2
|
import { ParserOptions } from '@typescript-eslint/parser';
|
|
3
|
-
import { RuleConfig,
|
|
4
|
-
import { RequiredOptions, LiteralUnion
|
|
3
|
+
import { RuleConfig, MergeIntersection, RenamePrefix, TypeScriptRules, VitestRules, NRules, Prefix, ReactHooksRules, ReactRules, JSDocRules, ImportRules, EslintRules, JsoncRules, VueRules, UnicornRules, EslintCommentsRules, FlatESLintConfigItem } from '@antfu/eslint-define-config';
|
|
4
|
+
import { BuiltInParserName, RequiredOptions, LiteralUnion } from 'prettier';
|
|
5
5
|
import { Linter } from 'eslint';
|
|
6
6
|
import { Rules } from 'eslint-plugin-antfu';
|
|
7
7
|
|
|
@@ -284,6 +284,44 @@ interface NoCustomClassnameRule {
|
|
|
284
284
|
'tailwindcss/no-custom-classname': NoCustomClassnameRuleConfig
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Option.
|
|
289
|
+
*/
|
|
290
|
+
interface NoUnnecessaryArbitraryValueOption {
|
|
291
|
+
callees?: string[]
|
|
292
|
+
ignoredKeys?: string[]
|
|
293
|
+
config?: string | Record<string, any>
|
|
294
|
+
tags?: string[]
|
|
295
|
+
|
|
296
|
+
[k: string]: any
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Options.
|
|
301
|
+
*/
|
|
302
|
+
type NoUnnecessaryArbitraryValueOptions = [
|
|
303
|
+
NoUnnecessaryArbitraryValueOption?,
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Avoid unjustified arbitrary classnames.
|
|
308
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
309
|
+
*/
|
|
310
|
+
type NoUnnecessaryArbitraryValueRuleConfig =
|
|
311
|
+
RuleConfig<NoUnnecessaryArbitraryValueOptions>
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Avoid unjustified arbitrary classnames.
|
|
315
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
316
|
+
*/
|
|
317
|
+
interface NoUnnecessaryArbitraryValueRule {
|
|
318
|
+
/**
|
|
319
|
+
* Avoid unjustified arbitrary classnames.
|
|
320
|
+
* @see [no-unnecessary-arbitrary-value](https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md)
|
|
321
|
+
*/
|
|
322
|
+
'tailwindcss/no-unnecessary-arbitrary-value': NoUnnecessaryArbitraryValueRuleConfig
|
|
323
|
+
}
|
|
324
|
+
|
|
287
325
|
/**
|
|
288
326
|
* All TailwindCss rules.
|
|
289
327
|
*/
|
|
@@ -293,7 +331,8 @@ type TailwindCssRules = ClassnamesOrderRule &
|
|
|
293
331
|
MigrationFromTailwind_2Rule &
|
|
294
332
|
NoArbitraryValueRule &
|
|
295
333
|
NoContradictingClassnameRule &
|
|
296
|
-
NoCustomClassnameRule
|
|
334
|
+
NoCustomClassnameRule &
|
|
335
|
+
NoUnnecessaryArbitraryValueRule
|
|
297
336
|
|
|
298
337
|
type WrapRuleConfig<T extends {
|
|
299
338
|
[key: string]: any;
|
|
@@ -318,6 +357,12 @@ type FlatConfigItem = Omit<FlatESLintConfigItem<EslintFlatRules, false>, 'plugin
|
|
|
318
357
|
type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
|
|
319
358
|
|
|
320
359
|
type Awaitable<T> = T | Promise<T>;
|
|
360
|
+
interface OptionsFiles {
|
|
361
|
+
/**
|
|
362
|
+
* Override the `files` option to provide custom globs.
|
|
363
|
+
*/
|
|
364
|
+
files?: string[];
|
|
365
|
+
}
|
|
321
366
|
type OptionsTypescript = (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides);
|
|
322
367
|
interface OptionsFormatters {
|
|
323
368
|
/**
|
|
@@ -372,6 +417,12 @@ interface OptionsTypeScriptWithTypes {
|
|
|
372
417
|
*/
|
|
373
418
|
tsconfigPath?: string | string[];
|
|
374
419
|
}
|
|
420
|
+
interface OptionsHasTypeScript {
|
|
421
|
+
typescript?: boolean;
|
|
422
|
+
}
|
|
423
|
+
interface OptionsIsInEditor {
|
|
424
|
+
isInEditor?: boolean;
|
|
425
|
+
}
|
|
375
426
|
interface OptionsOverrides {
|
|
376
427
|
overrides?: FlatConfigItem['rules'];
|
|
377
428
|
}
|
|
@@ -487,9 +538,6 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
487
538
|
/**
|
|
488
539
|
* Use external formatters to format files.
|
|
489
540
|
*
|
|
490
|
-
* Requires installing:
|
|
491
|
-
* - `eslint-plugin-prettier`
|
|
492
|
-
*
|
|
493
541
|
* @default
|
|
494
542
|
* {
|
|
495
543
|
* "html": true,
|
|
@@ -499,8 +547,10 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
499
547
|
* "yaml": false
|
|
500
548
|
* "toml": false
|
|
501
549
|
* }
|
|
550
|
+
*
|
|
551
|
+
* When set to `true`, it will enable all formatters.
|
|
502
552
|
*/
|
|
503
|
-
formatter?: OptionsFormatters;
|
|
553
|
+
formatter?: boolean | OptionsFormatters;
|
|
504
554
|
/**
|
|
505
555
|
* Default prettier rules
|
|
506
556
|
*
|
|
@@ -521,11 +571,107 @@ interface OptionsConfig extends OptionsComponentExts {
|
|
|
521
571
|
* @default auto-detect based on the process.env
|
|
522
572
|
*/
|
|
523
573
|
isInEditor?: boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Automatically rename plugins in the config.
|
|
576
|
+
*
|
|
577
|
+
* @default true
|
|
578
|
+
*/
|
|
579
|
+
autoRenamePlugins?: boolean;
|
|
524
580
|
}
|
|
525
|
-
|
|
581
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
582
|
+
|
|
583
|
+
declare const parserPlain: {
|
|
584
|
+
meta: {
|
|
585
|
+
name: string;
|
|
586
|
+
};
|
|
587
|
+
parseForESLint: (code: string) => {
|
|
588
|
+
ast: {
|
|
589
|
+
body: never[];
|
|
590
|
+
comments: never[];
|
|
591
|
+
loc: {
|
|
592
|
+
end: number;
|
|
593
|
+
start: number;
|
|
594
|
+
};
|
|
595
|
+
range: number[];
|
|
596
|
+
tokens: never[];
|
|
597
|
+
type: string;
|
|
598
|
+
};
|
|
599
|
+
scopeManager: null;
|
|
600
|
+
services: {
|
|
601
|
+
isPlain: boolean;
|
|
602
|
+
};
|
|
603
|
+
visitorKeys: {
|
|
604
|
+
Program: never[];
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Combine array and non-array configs into a single array.
|
|
610
|
+
*/
|
|
611
|
+
declare function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
|
|
612
|
+
/**
|
|
613
|
+
* Rename plugin prefixes in a rule object.
|
|
614
|
+
* Accepts a map of prefixes to rename.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* import { renameRules } from '@coderwyd/eslint-config'
|
|
619
|
+
*
|
|
620
|
+
* export default [{
|
|
621
|
+
* rules: renameRules(
|
|
622
|
+
* {
|
|
623
|
+
* '@typescript-eslint/indent': 'error'
|
|
624
|
+
* },
|
|
625
|
+
* { '@typescript-eslint': 'ts' }
|
|
626
|
+
* )
|
|
627
|
+
* }]
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
declare function renameRules(rules: Record<string, any>, map: Record<string, string>): {
|
|
631
|
+
[k: string]: any;
|
|
632
|
+
};
|
|
633
|
+
/**
|
|
634
|
+
* Rename plugin names a flat configs array
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```ts
|
|
638
|
+
* import { renamePluginInConfigs } from '@antfu/eslint-config'
|
|
639
|
+
* import someConfigs from './some-configs'
|
|
640
|
+
*
|
|
641
|
+
* export default renamePluginInConfigs(someConfigs, {
|
|
642
|
+
* '@typescript-eslint': 'ts',
|
|
643
|
+
* 'import-x': 'import',
|
|
644
|
+
* })
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function renamePluginInConfigs(configs: UserConfigItem[], map: Record<string, string>): UserConfigItem[];
|
|
648
|
+
declare function getVueVersion(): number;
|
|
649
|
+
declare function toArray<T>(value: T | T[]): T[];
|
|
650
|
+
declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
|
|
651
|
+
default: infer U;
|
|
652
|
+
} ? U : T>;
|
|
653
|
+
declare function ensurePackages(packages: string[]): Promise<void>;
|
|
654
|
+
declare function loadPrettierConfig(cwd: string): Promise<Partial<PrettierOptions>>;
|
|
655
|
+
declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
|
|
656
|
+
declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): {};
|
|
657
|
+
|
|
658
|
+
declare const defaultPluginRenaming: {
|
|
659
|
+
'@typescript-eslint': string;
|
|
660
|
+
'import-x': string;
|
|
661
|
+
n: string;
|
|
662
|
+
vitest: string;
|
|
663
|
+
yml: string;
|
|
664
|
+
};
|
|
526
665
|
/**
|
|
527
666
|
* Construct an array of ESLint flat config items.
|
|
667
|
+
*
|
|
668
|
+
* @param {OptionsConfig & FlatConfigItem} options
|
|
669
|
+
* The options for generating the ESLint configurations.
|
|
670
|
+
* @param {Awaitable<UserConfigItem | UserConfigItem[]>[]} userConfigs
|
|
671
|
+
* The user configurations to be merged with the generated configurations.
|
|
672
|
+
* @returns {Promise<UserConfigItem[]>}
|
|
673
|
+
* The merged ESLint configurations.
|
|
528
674
|
*/
|
|
529
675
|
declare function defineConfig(options?: OptionsConfig & FlatConfigItem, ...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]>;
|
|
530
676
|
|
|
531
|
-
export { defineConfig };
|
|
677
|
+
export { type Awaitable, type EslintFlatRules, type FlatConfigItem, type OptionsComponentExts, type OptionsConfig, type OptionsFiles, type OptionsFormatters, type OptionsHasTypeScript, type OptionsIsInEditor, type OptionsOverrides, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type OptionsTypescript, type OptionsUnoCSS, type OptionsVue, type PartialPrettierExtendedOptions, type PrettierParser, type ResolvedOptions, type UserConfigItem, type WrapRuleConfig, combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, getVueVersion, interopDefault, loadPrettierConfig, parserPlain, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var DEFAULT_PRETTIER_RULES = {
|
|
|
14
14
|
// src/plugins/index.ts
|
|
15
15
|
import { default as default2 } from "eslint-plugin-antfu";
|
|
16
16
|
import { default as default3 } from "eslint-plugin-eslint-comments";
|
|
17
|
-
import * as pluginImport from "eslint-plugin-
|
|
17
|
+
import * as pluginImport from "eslint-plugin-import-x";
|
|
18
18
|
import { default as default4 } from "eslint-plugin-n";
|
|
19
19
|
import { default as default5 } from "eslint-plugin-unicorn";
|
|
20
20
|
import { default as default6 } from "eslint-plugin-unused-imports";
|
|
@@ -57,7 +57,7 @@ var GLOB_JSONC = "**/*.jsonc";
|
|
|
57
57
|
var GLOB_MARKDOWN = "**/*.md";
|
|
58
58
|
var GLOB_YAML = "**/*.y?(a)ml";
|
|
59
59
|
var GLOB_TOML = "**/*.toml";
|
|
60
|
-
var GLOB_GRAPHQL = "**/*.
|
|
60
|
+
var GLOB_GRAPHQL = "**/*.{g,graph}ql";
|
|
61
61
|
var GLOB_PRETTIER_LINT = [GLOB_SRC, GLOB_VUE];
|
|
62
62
|
var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
63
63
|
var GLOB_TESTS = [
|
|
@@ -146,10 +146,7 @@ async function imports() {
|
|
|
146
146
|
],
|
|
147
147
|
...{
|
|
148
148
|
// format
|
|
149
|
-
"import/newline-after-import": [
|
|
150
|
-
"error",
|
|
151
|
-
{ considerComments: true, count: 1 }
|
|
152
|
-
]
|
|
149
|
+
"import/newline-after-import": ["error", { count: 1 }]
|
|
153
150
|
}
|
|
154
151
|
}
|
|
155
152
|
},
|
|
@@ -454,15 +451,34 @@ async function combine(...configs) {
|
|
|
454
451
|
const resolved = await Promise.all(configs);
|
|
455
452
|
return resolved.flat();
|
|
456
453
|
}
|
|
457
|
-
function renameRules(rules,
|
|
454
|
+
function renameRules(rules, map) {
|
|
458
455
|
return Object.fromEntries(
|
|
459
456
|
Object.entries(rules).map(([key, value]) => {
|
|
460
|
-
|
|
461
|
-
|
|
457
|
+
for (const [from, to] of Object.entries(map)) {
|
|
458
|
+
if (key.startsWith(`${from}/`))
|
|
459
|
+
return [to + key.slice(from.length), value];
|
|
460
|
+
}
|
|
462
461
|
return [key, value];
|
|
463
462
|
})
|
|
464
463
|
);
|
|
465
464
|
}
|
|
465
|
+
function renamePluginInConfigs(configs, map) {
|
|
466
|
+
return configs.map((i) => {
|
|
467
|
+
const clone = { ...i };
|
|
468
|
+
if (clone.rules)
|
|
469
|
+
clone.rules = renameRules(clone.rules, map);
|
|
470
|
+
if (clone.plugins) {
|
|
471
|
+
clone.plugins = Object.fromEntries(
|
|
472
|
+
Object.entries(clone.plugins).map(([key, value]) => {
|
|
473
|
+
if (key in map)
|
|
474
|
+
return [map[key], value];
|
|
475
|
+
return [key, value];
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
return clone;
|
|
480
|
+
});
|
|
481
|
+
}
|
|
466
482
|
function getVueVersion() {
|
|
467
483
|
const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
|
|
468
484
|
if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
|
|
@@ -720,6 +736,22 @@ async function sortPackageJson() {
|
|
|
720
736
|
{
|
|
721
737
|
order: ["types", "import", "require", "default"],
|
|
722
738
|
pathPattern: "^exports.*$"
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
order: [
|
|
742
|
+
// client hooks only
|
|
743
|
+
"pre-commit",
|
|
744
|
+
"prepare-commit-msg",
|
|
745
|
+
"commit-msg",
|
|
746
|
+
"post-commit",
|
|
747
|
+
"pre-rebase",
|
|
748
|
+
"post-rewrite",
|
|
749
|
+
"post-checkout",
|
|
750
|
+
"post-merge",
|
|
751
|
+
"pre-push",
|
|
752
|
+
"pre-auto-gc"
|
|
753
|
+
],
|
|
754
|
+
pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
|
|
723
755
|
}
|
|
724
756
|
]
|
|
725
757
|
}
|
|
@@ -957,14 +989,11 @@ async function typescript(options = {}) {
|
|
|
957
989
|
rules: {
|
|
958
990
|
...renameRules(
|
|
959
991
|
pluginTs.configs["eslint-recommended"].overrides[0].rules,
|
|
960
|
-
"@typescript-eslint
|
|
961
|
-
"ts/"
|
|
962
|
-
),
|
|
963
|
-
...renameRules(
|
|
964
|
-
pluginTs.configs.strict.rules,
|
|
965
|
-
"@typescript-eslint/",
|
|
966
|
-
"ts/"
|
|
992
|
+
{ "@typescript-eslint": "ts" }
|
|
967
993
|
),
|
|
994
|
+
...renameRules(pluginTs.configs.strict.rules, {
|
|
995
|
+
"@typescript-eslint": "ts"
|
|
996
|
+
}),
|
|
968
997
|
"no-dupe-class-members": "off",
|
|
969
998
|
"no-loss-of-precision": "off",
|
|
970
999
|
"no-redeclare": "off",
|
|
@@ -1472,12 +1501,19 @@ async function unocss(options = {}) {
|
|
|
1472
1501
|
async function formatter(options = {}, prettierRules2 = {}) {
|
|
1473
1502
|
const {
|
|
1474
1503
|
css = true,
|
|
1475
|
-
graphql,
|
|
1504
|
+
graphql = false,
|
|
1476
1505
|
html = true,
|
|
1477
|
-
markdown,
|
|
1478
|
-
toml,
|
|
1479
|
-
yaml
|
|
1480
|
-
} = options
|
|
1506
|
+
markdown = false,
|
|
1507
|
+
toml = false,
|
|
1508
|
+
yaml = false
|
|
1509
|
+
} = typeof options === "object" ? options : {
|
|
1510
|
+
css: true,
|
|
1511
|
+
graphql: true,
|
|
1512
|
+
html: true,
|
|
1513
|
+
markdown: true,
|
|
1514
|
+
toml: true,
|
|
1515
|
+
yaml: true
|
|
1516
|
+
};
|
|
1481
1517
|
const pluginPrettier = await interopDefault(import("eslint-plugin-prettier"));
|
|
1482
1518
|
function createPrettierFormatter(files, parser, plugins) {
|
|
1483
1519
|
const rules = {
|
|
@@ -1664,6 +1700,7 @@ async function tailwindcss(options = {}) {
|
|
|
1664
1700
|
"tailwindcss/no-arbitrary-value": "off",
|
|
1665
1701
|
"tailwindcss/no-contradicting-classname": "error",
|
|
1666
1702
|
"tailwindcss/no-custom-classname": "off",
|
|
1703
|
+
"tailwindcss/no-unnecessary-arbitrary-value": "warn",
|
|
1667
1704
|
...overrides
|
|
1668
1705
|
}
|
|
1669
1706
|
}
|
|
@@ -1691,8 +1728,16 @@ var flatConfigProps = [
|
|
|
1691
1728
|
"rules",
|
|
1692
1729
|
"settings"
|
|
1693
1730
|
];
|
|
1731
|
+
var defaultPluginRenaming = {
|
|
1732
|
+
"@typescript-eslint": "ts",
|
|
1733
|
+
"import-x": "import",
|
|
1734
|
+
n: "node",
|
|
1735
|
+
vitest: "test",
|
|
1736
|
+
yml: "yaml"
|
|
1737
|
+
};
|
|
1694
1738
|
async function defineConfig(options = {}, ...userConfigs) {
|
|
1695
1739
|
const {
|
|
1740
|
+
autoRenamePlugins = true,
|
|
1696
1741
|
componentExts = [],
|
|
1697
1742
|
gitignore: enableGitignore = true,
|
|
1698
1743
|
isInEditor: isInEditor2 = isInEditor,
|
|
@@ -1816,10 +1861,10 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1816
1861
|
);
|
|
1817
1862
|
Object.assign(prettierRules2, prettierConfig);
|
|
1818
1863
|
}
|
|
1819
|
-
configs.push(
|
|
1820
|
-
|
|
1821
|
-
formatter(options.formatter, prettierRules2)
|
|
1822
|
-
|
|
1864
|
+
configs.push(prettier(options.formatter ? prettierRules2 : {}));
|
|
1865
|
+
if (options.formatter) {
|
|
1866
|
+
configs.push(formatter(options.formatter, prettierRules2));
|
|
1867
|
+
}
|
|
1823
1868
|
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
1824
1869
|
if (key in options)
|
|
1825
1870
|
acc[key] = options[key];
|
|
@@ -1827,9 +1872,23 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
1827
1872
|
}, {});
|
|
1828
1873
|
if (Object.keys(fusedConfig).length > 0)
|
|
1829
1874
|
configs.push([fusedConfig]);
|
|
1830
|
-
const merged = combine(...configs, ...userConfigs);
|
|
1875
|
+
const merged = await combine(...configs, ...userConfigs);
|
|
1876
|
+
if (autoRenamePlugins)
|
|
1877
|
+
return renamePluginInConfigs(merged, defaultPluginRenaming);
|
|
1831
1878
|
return merged;
|
|
1832
1879
|
}
|
|
1833
1880
|
export {
|
|
1834
|
-
|
|
1881
|
+
combine,
|
|
1882
|
+
defaultPluginRenaming,
|
|
1883
|
+
defineConfig,
|
|
1884
|
+
ensurePackages,
|
|
1885
|
+
getOverrides,
|
|
1886
|
+
getVueVersion,
|
|
1887
|
+
interopDefault,
|
|
1888
|
+
loadPrettierConfig,
|
|
1889
|
+
parserPlain,
|
|
1890
|
+
renamePluginInConfigs,
|
|
1891
|
+
renameRules,
|
|
1892
|
+
resolveSubOptions,
|
|
1893
|
+
toArray
|
|
1835
1894
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderwyd/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
5
|
-
"packageManager": "pnpm@8.15.
|
|
4
|
+
"version": "2.3.1",
|
|
5
|
+
"packageManager": "pnpm@8.15.5",
|
|
6
6
|
"description": "Donny's ESLint config",
|
|
7
7
|
"author": "Donny Wang <donny526@outlook.com> (https://github.com/coderwyd/)",
|
|
8
8
|
"license": "MIT",
|
|
@@ -68,29 +68,29 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@antfu/eslint-define-config": "1.23.0-2",
|
|
70
70
|
"@antfu/install-pkg": "^0.3.1",
|
|
71
|
-
"@eslint-types/jsdoc": "48.2.
|
|
72
|
-
"@eslint-types/typescript-eslint": "^7.0
|
|
71
|
+
"@eslint-types/jsdoc": "48.2.1",
|
|
72
|
+
"@eslint-types/typescript-eslint": "^7.2.0",
|
|
73
73
|
"@eslint-types/unicorn": "^51.0.1",
|
|
74
74
|
"@toml-tools/parser": "^1.0.0",
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
76
|
-
"@typescript-eslint/parser": "^7.
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
76
|
+
"@typescript-eslint/parser": "^7.4.0",
|
|
77
77
|
"eslint-config-flat-gitignore": "^0.1.3",
|
|
78
78
|
"eslint-config-prettier": "^9.1.0",
|
|
79
79
|
"eslint-plugin-antfu": "^2.1.2",
|
|
80
80
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
81
|
-
"eslint-plugin-
|
|
81
|
+
"eslint-plugin-import-x": "^0.4.4",
|
|
82
82
|
"eslint-plugin-jsdoc": "^48.2.1",
|
|
83
|
-
"eslint-plugin-jsonc": "^2.
|
|
83
|
+
"eslint-plugin-jsonc": "^2.14.1",
|
|
84
84
|
"eslint-plugin-n": "^16.6.2",
|
|
85
85
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
|
86
|
-
"eslint-plugin-perfectionist": "^2.
|
|
86
|
+
"eslint-plugin-perfectionist": "^2.7.0",
|
|
87
87
|
"eslint-plugin-prettier": "^5.1.3",
|
|
88
|
-
"eslint-plugin-tailwindcss": "^3.
|
|
88
|
+
"eslint-plugin-tailwindcss": "^3.15.1",
|
|
89
89
|
"eslint-plugin-unicorn": "^51.0.1",
|
|
90
90
|
"eslint-plugin-unused-imports": "^3.1.0",
|
|
91
|
-
"eslint-plugin-vitest": "^0.
|
|
92
|
-
"eslint-plugin-vue": "^9.
|
|
93
|
-
"globals": "^
|
|
91
|
+
"eslint-plugin-vitest": "^0.4.0",
|
|
92
|
+
"eslint-plugin-vue": "^9.24.0",
|
|
93
|
+
"globals": "^15.0.0",
|
|
94
94
|
"jsonc-eslint-parser": "^2.4.0",
|
|
95
95
|
"local-pkg": "^0.5.0",
|
|
96
96
|
"parse-gitignore": "^2.0.0",
|
|
@@ -103,29 +103,29 @@
|
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@antfu/ni": "^0.21.12",
|
|
106
|
-
"@types/eslint": "^8.56.
|
|
106
|
+
"@types/eslint": "^8.56.6",
|
|
107
107
|
"@types/fs-extra": "^11.0.4",
|
|
108
|
-
"@types/node": "^20.11.
|
|
108
|
+
"@types/node": "^20.11.30",
|
|
109
109
|
"@types/prompts": "^2.4.9",
|
|
110
110
|
"@types/yargs": "^17.0.32",
|
|
111
|
-
"@unocss/eslint-plugin": "^0.58.
|
|
111
|
+
"@unocss/eslint-plugin": "^0.58.7",
|
|
112
112
|
"bumpp": "^9.4.0",
|
|
113
|
-
"eslint": "
|
|
114
|
-
"eslint-flat-config-viewer": "^0.1.
|
|
115
|
-
"eslint-plugin-react": "^7.34.
|
|
113
|
+
"eslint": "9.0.0-rc.0",
|
|
114
|
+
"eslint-flat-config-viewer": "^0.1.14",
|
|
115
|
+
"eslint-plugin-react": "^7.34.1",
|
|
116
116
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
117
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
117
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
118
118
|
"eslint-plugin-svelte": "^2.35.1",
|
|
119
119
|
"execa": "^8.0.1",
|
|
120
120
|
"fast-glob": "^3.3.2",
|
|
121
121
|
"fs-extra": "^11.2.0",
|
|
122
122
|
"lint-staged": "^15.2.2",
|
|
123
123
|
"rimraf": "^5.0.5",
|
|
124
|
-
"simple-git-hooks": "^2.
|
|
124
|
+
"simple-git-hooks": "^2.11.1",
|
|
125
125
|
"svelte-eslint-parser": "^0.33.1",
|
|
126
126
|
"tsup": "^8.0.2",
|
|
127
127
|
"tsx": "^4.7.1",
|
|
128
|
-
"typescript": "^5.
|
|
128
|
+
"typescript": "^5.4.3"
|
|
129
129
|
},
|
|
130
130
|
"simple-git-hooks": {
|
|
131
131
|
"pre-commit": "pnpx nano-staged"
|