@tofrankie/eslint 0.0.2 → 0.0.4
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/CHANGELOG.md +28 -1
- package/README.md +1 -1
- package/dist/index.cjs +199 -37
- package/dist/index.d.cts +14 -3
- package/dist/index.d.mts +14 -3
- package/dist/index.mjs +199 -37
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## eslint@0.0.4 (2026-02-13)
|
|
4
|
+
|
|
5
|
+
### BREAKING CHANGE
|
|
6
|
+
|
|
7
|
+
- **defineConfig(antfuOptions?, ...userFlatConfigs)** - New API signature
|
|
8
|
+
- First param: antfu options (formatters, typescript, rules, etc.), merge with user options
|
|
9
|
+
- Rest params: ESLint flat configs, appended after preset configs
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
- TypeScript support enabled by default
|
|
14
|
+
|
|
15
|
+
## eslint@0.0.3 (2026-02-11)
|
|
16
|
+
|
|
17
|
+
- Add `antfu/if-newline` rule
|
|
18
|
+
- Add `antfu/consistent-list-newline` rule
|
|
19
|
+
|
|
20
|
+
## eslint@0.0.2 (2026-02-11)
|
|
21
|
+
|
|
22
|
+
- Add `no-unused-vars` rule
|
|
23
|
+
- Add `style/quotes` rule
|
|
24
|
+
- Add `style/arrow-parens` rule
|
|
25
|
+
- Add `style/brace-style` rule
|
|
26
|
+
- Add `style/operator-linebreak` rule
|
|
27
|
+
- Add `style/comma-dangle` rule
|
|
28
|
+
- Add `eslint-comments/no-unlimited-disable` rule
|
|
29
|
+
|
|
30
|
+
## eslint@0.0.1 (2026-02-10)
|
|
4
31
|
|
|
5
32
|
- Initial alpha release
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tofrankie/eslint
|
|
2
2
|
|
|
3
|
-
Based on [
|
|
3
|
+
Based on [@antfu/eslint-config](https://github.com/antfu/eslint-config), with a few preset rules tailored to personal preferences.
|
|
4
4
|
|
|
5
5
|
> [!IMPORTANT]
|
|
6
6
|
> Rule presets are not yet stable and may change.
|
package/dist/index.cjs
CHANGED
|
@@ -30,44 +30,206 @@ let _antfu_eslint_config = require("@antfu/eslint-config");
|
|
|
30
30
|
let lodash_merge = require("lodash.merge");
|
|
31
31
|
lodash_merge = __toESM(lodash_merge);
|
|
32
32
|
|
|
33
|
+
//#region src/preset-configs/typescript.ts
|
|
34
|
+
const TYPESCRIPT_PRESET_CONFIG = {
|
|
35
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
36
|
+
rules: {
|
|
37
|
+
"no-unused-vars": "off",
|
|
38
|
+
"ts/no-unused-vars": ["error", {
|
|
39
|
+
args: "all",
|
|
40
|
+
argsIgnorePattern: "^_",
|
|
41
|
+
caughtErrors: "all",
|
|
42
|
+
caughtErrorsIgnorePattern: "^_",
|
|
43
|
+
destructuredArrayIgnorePattern: "^_",
|
|
44
|
+
varsIgnorePattern: "^_",
|
|
45
|
+
ignoreRestSiblings: true
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/preset-rules/antfu.ts
|
|
52
|
+
/**
|
|
53
|
+
* - rule: `antfu/*`
|
|
54
|
+
* - plugin: `eslint-plugin-antfu`
|
|
55
|
+
* @see https://github.com/antfu/eslint-config#top-level-function-style-etc
|
|
56
|
+
* @see https://github.com/antfu/eslint-plugin-antfu
|
|
57
|
+
*/
|
|
58
|
+
const ANTFU_PRESET_RULES = {
|
|
59
|
+
"antfu/if-newline": "off",
|
|
60
|
+
"antfu/consistent-list-newline": "off"
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/preset-rules/base.ts
|
|
65
|
+
/**
|
|
66
|
+
* - rule: `*`
|
|
67
|
+
* - plugin: `none`
|
|
68
|
+
* @see https://eslint.org/docs/latest/rules/
|
|
69
|
+
*/
|
|
70
|
+
const BASE_PRESET_RULES = {
|
|
71
|
+
"no-console": "off",
|
|
72
|
+
"no-debugger": "warn",
|
|
73
|
+
"no-unused-vars": ["error", {
|
|
74
|
+
vars: "all",
|
|
75
|
+
args: "all",
|
|
76
|
+
argsIgnorePattern: "^_",
|
|
77
|
+
destructuredArrayIgnorePattern: "^_",
|
|
78
|
+
varsIgnorePattern: "^_",
|
|
79
|
+
ignoreRestSiblings: true
|
|
80
|
+
}]
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/preset-rules/eslint-comments.ts
|
|
85
|
+
/**
|
|
86
|
+
* - rule: `eslint-comments/*`
|
|
87
|
+
* - plugin: `eslint-plugin-eslint-comments`
|
|
88
|
+
* @see https://github.com/antfu/eslint-config
|
|
89
|
+
* @see https://github.com/eslint-community/eslint-plugin-eslint-comments
|
|
90
|
+
*/
|
|
91
|
+
const ESLINT_COMMENTS_PRESET_RULES = { "eslint-comments/no-unlimited-disable": "off" };
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/preset-rules/node.ts
|
|
95
|
+
/**
|
|
96
|
+
* - rule: `node/*`
|
|
97
|
+
* - original rule: `n/*`
|
|
98
|
+
* - plugin: `eslint-plugin-n`
|
|
99
|
+
* @see https://github.com/antfu/eslint-config#node
|
|
100
|
+
* @see https://github.com/eslint-community/eslint-plugin-n
|
|
101
|
+
*/
|
|
102
|
+
const NODE_PRESET_RULES = { "node/prefer-global/process": "off" };
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/preset-rules/pnpm.ts
|
|
106
|
+
/**
|
|
107
|
+
* - rule: `pnpm/*`
|
|
108
|
+
* - plugin: `eslint-plugin-pnpm`
|
|
109
|
+
* @see https://github.com/antfu/eslint-config
|
|
110
|
+
* @see https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm
|
|
111
|
+
*/
|
|
112
|
+
const PNPM_PRESET_RULES = { "pnpm/yaml-enforce-settings": "off" };
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/preset-rules/style.ts
|
|
116
|
+
/**
|
|
117
|
+
* - rule: `style/*`
|
|
118
|
+
* - original rule: `@stylistic/*`
|
|
119
|
+
* - plugin: `@stylistic/eslint-plugin`
|
|
120
|
+
* @see https://github.com/antfu/eslint-config#stylistic
|
|
121
|
+
* @see https://eslint.style/rules
|
|
122
|
+
*/
|
|
123
|
+
const STYLE_PRESET_RULES = {
|
|
124
|
+
"style/quotes": [
|
|
125
|
+
"error",
|
|
126
|
+
"single",
|
|
127
|
+
{ avoidEscape: false }
|
|
128
|
+
],
|
|
129
|
+
"style/arrow-parens": ["error", "as-needed"],
|
|
130
|
+
"style/brace-style": [
|
|
131
|
+
"error",
|
|
132
|
+
"1tbs",
|
|
133
|
+
{ allowSingleLine: false }
|
|
134
|
+
],
|
|
135
|
+
"style/operator-linebreak": [
|
|
136
|
+
"error",
|
|
137
|
+
"before",
|
|
138
|
+
{ overrides: { "&&": "after" } }
|
|
139
|
+
],
|
|
140
|
+
"style/comma-dangle": "off"
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/preset-rules/test.ts
|
|
145
|
+
/**
|
|
146
|
+
* - rule: `test/*`
|
|
147
|
+
* - original rule: `vitest/*`, `no-only-tests/*`
|
|
148
|
+
* - plugin: `@vitest/eslint-plugin`, `eslint-plugin-no-only-tests`
|
|
149
|
+
* @see https://github.com/antfu/eslint-config#test
|
|
150
|
+
* @see https://github.com/vitest-dev/eslint-plugin-vitest
|
|
151
|
+
* @see https://github.com/levibuzolic/eslint-plugin-no-only-tests
|
|
152
|
+
*/
|
|
153
|
+
const TEST_PRESET_RULES = { "test/prefer-lowercase-title": "off" };
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/preset-rules/index.ts
|
|
157
|
+
const ALL_PRESET_RULES = {
|
|
158
|
+
...ANTFU_PRESET_RULES,
|
|
159
|
+
...BASE_PRESET_RULES,
|
|
160
|
+
...ESLINT_COMMENTS_PRESET_RULES,
|
|
161
|
+
...NODE_PRESET_RULES,
|
|
162
|
+
...PNPM_PRESET_RULES,
|
|
163
|
+
...STYLE_PRESET_RULES,
|
|
164
|
+
...TEST_PRESET_RULES
|
|
165
|
+
};
|
|
166
|
+
const PRESET_PREDICATES = [
|
|
167
|
+
{ rules: BASE_PRESET_RULES },
|
|
168
|
+
{ rules: ESLINT_COMMENTS_PRESET_RULES },
|
|
169
|
+
{
|
|
170
|
+
rules: STYLE_PRESET_RULES,
|
|
171
|
+
predicate: notFalse("stylistic")
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
rules: ANTFU_PRESET_RULES,
|
|
175
|
+
predicate: (options) => options.lessOpinionated !== true
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
rules: NODE_PRESET_RULES,
|
|
179
|
+
predicate: notFalse("node")
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
rules: TEST_PRESET_RULES,
|
|
183
|
+
predicate: notFalse("test")
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
rules: PNPM_PRESET_RULES,
|
|
187
|
+
predicate: notFalse("pnpm")
|
|
188
|
+
}
|
|
189
|
+
];
|
|
190
|
+
function buildPresetRules(resolvedOptions) {
|
|
191
|
+
return PRESET_PREDICATES.reduce((acc, { rules, predicate }) => {
|
|
192
|
+
if (!predicate || predicate(resolvedOptions)) Object.assign(acc, rules);
|
|
193
|
+
return acc;
|
|
194
|
+
}, {});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 自动检测/默认开启的配置,若不为 false 则加载相关预设 rules
|
|
198
|
+
* 如果默认关闭的配置,若为 true 才加载相关预设 rules
|
|
199
|
+
* @param key - The key of the option to check.
|
|
200
|
+
* @returns A predicate function that checks if the option is not false.
|
|
201
|
+
*/
|
|
202
|
+
function notFalse(key) {
|
|
203
|
+
return (options) => options[key] !== false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
33
207
|
//#region src/config.ts
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"1tbs",
|
|
60
|
-
{ allowSingleLine: false }
|
|
61
|
-
],
|
|
62
|
-
"style/operator-linebreak": [
|
|
63
|
-
"error",
|
|
64
|
-
"before",
|
|
65
|
-
{ overrides: { "&&": "after" } }
|
|
66
|
-
],
|
|
67
|
-
"style/comma-dangle": "off",
|
|
68
|
-
"eslint-comments/no-unlimited-disable": "off"
|
|
69
|
-
}
|
|
70
|
-
}, options), userConfigs);
|
|
208
|
+
/**
|
|
209
|
+
* @param antfuOptions Configures for antfu's config.
|
|
210
|
+
* @param userFlatConfigs From the second arguments they are ESLint Flat Configs, you can have multiple configs.
|
|
211
|
+
*
|
|
212
|
+
* 前提:用户预设优于内置预设,若有相同的 key,则进行覆盖。
|
|
213
|
+
* 1. 排除 rules 的前提下,合并 baseOptions 与 userOptions,得到 mergedOptions
|
|
214
|
+
* 2. 根据 mergedOptions 取预设规则 presetRules,不对用户 rules 作错误兼容
|
|
215
|
+
* 3. 将 presetRules 与 userRules 合并,得到 mergedRules
|
|
216
|
+
* 4. 将 mergedOptions 与 { rules: mergedRules } 合并,得到 resolvedOptions
|
|
217
|
+
* 5. 将 resolvedOptions 作为 antfu 第一个参数
|
|
218
|
+
*/
|
|
219
|
+
function defineConfig(antfuOptions, ...userFlatConfigs) {
|
|
220
|
+
const { rules: userRules, ...userOptionsWithoutRules } = antfuOptions ?? {};
|
|
221
|
+
const mergedOptions = (0, lodash_merge.default)({}, {
|
|
222
|
+
formatters: { prettierOptions: {
|
|
223
|
+
printWidth: 100,
|
|
224
|
+
semi: false,
|
|
225
|
+
singleQuote: true,
|
|
226
|
+
arrowParens: "avoid",
|
|
227
|
+
trailingComma: "es5",
|
|
228
|
+
htmlWhitespaceSensitivity: "css"
|
|
229
|
+
} },
|
|
230
|
+
typescript: true
|
|
231
|
+
}, userOptionsWithoutRules);
|
|
232
|
+
return (0, _antfu_eslint_config.antfu)((0, lodash_merge.default)({}, mergedOptions, { rules: (0, lodash_merge.default)({}, buildPresetRules(mergedOptions), userRules ?? {}) }), ...mergedOptions.typescript ? [TYPESCRIPT_PRESET_CONFIG] : [], ...userFlatConfigs);
|
|
71
233
|
}
|
|
72
234
|
|
|
73
235
|
//#endregion
|
package/dist/index.d.cts
CHANGED
|
@@ -4,9 +4,20 @@ import { OptionsConfig as OptionsConfig$1, TypedFlatConfigItem, antfu } from "@a
|
|
|
4
4
|
interface OptionsConfig extends OptionsConfig$1 {}
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/config.d.ts
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
type AntfuOptions = OptionsConfig & Omit<TypedFlatConfigItem, 'files'>;
|
|
8
|
+
type UserFlatConfig = Parameters<typeof antfu>[1];
|
|
9
9
|
type Config = ReturnType<typeof antfu>;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param antfuOptions Configures for antfu's config.
|
|
12
|
+
* @param userFlatConfigs From the second arguments they are ESLint Flat Configs, you can have multiple configs.
|
|
13
|
+
*
|
|
14
|
+
* 前提:用户预设优于内置预设,若有相同的 key,则进行覆盖。
|
|
15
|
+
* 1. 排除 rules 的前提下,合并 baseOptions 与 userOptions,得到 mergedOptions
|
|
16
|
+
* 2. 根据 mergedOptions 取预设规则 presetRules,不对用户 rules 作错误兼容
|
|
17
|
+
* 3. 将 presetRules 与 userRules 合并,得到 mergedRules
|
|
18
|
+
* 4. 将 mergedOptions 与 { rules: mergedRules } 合并,得到 resolvedOptions
|
|
19
|
+
* 5. 将 resolvedOptions 作为 antfu 第一个参数
|
|
20
|
+
*/
|
|
21
|
+
declare function defineConfig(antfuOptions?: AntfuOptions, ...userFlatConfigs: UserFlatConfig[]): Config;
|
|
11
22
|
//#endregion
|
|
12
23
|
export { OptionsConfig, defineConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,9 +4,20 @@ import { OptionsConfig as OptionsConfig$1, TypedFlatConfigItem, antfu } from "@a
|
|
|
4
4
|
interface OptionsConfig extends OptionsConfig$1 {}
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/config.d.ts
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
type AntfuOptions = OptionsConfig & Omit<TypedFlatConfigItem, 'files'>;
|
|
8
|
+
type UserFlatConfig = Parameters<typeof antfu>[1];
|
|
9
9
|
type Config = ReturnType<typeof antfu>;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param antfuOptions Configures for antfu's config.
|
|
12
|
+
* @param userFlatConfigs From the second arguments they are ESLint Flat Configs, you can have multiple configs.
|
|
13
|
+
*
|
|
14
|
+
* 前提:用户预设优于内置预设,若有相同的 key,则进行覆盖。
|
|
15
|
+
* 1. 排除 rules 的前提下,合并 baseOptions 与 userOptions,得到 mergedOptions
|
|
16
|
+
* 2. 根据 mergedOptions 取预设规则 presetRules,不对用户 rules 作错误兼容
|
|
17
|
+
* 3. 将 presetRules 与 userRules 合并,得到 mergedRules
|
|
18
|
+
* 4. 将 mergedOptions 与 { rules: mergedRules } 合并,得到 resolvedOptions
|
|
19
|
+
* 5. 将 resolvedOptions 作为 antfu 第一个参数
|
|
20
|
+
*/
|
|
21
|
+
declare function defineConfig(antfuOptions?: AntfuOptions, ...userFlatConfigs: UserFlatConfig[]): Config;
|
|
11
22
|
//#endregion
|
|
12
23
|
export { OptionsConfig, defineConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,44 +1,206 @@
|
|
|
1
1
|
import { antfu } from "@antfu/eslint-config";
|
|
2
2
|
import merge from "lodash.merge";
|
|
3
3
|
|
|
4
|
+
//#region src/preset-configs/typescript.ts
|
|
5
|
+
const TYPESCRIPT_PRESET_CONFIG = {
|
|
6
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
7
|
+
rules: {
|
|
8
|
+
"no-unused-vars": "off",
|
|
9
|
+
"ts/no-unused-vars": ["error", {
|
|
10
|
+
args: "all",
|
|
11
|
+
argsIgnorePattern: "^_",
|
|
12
|
+
caughtErrors: "all",
|
|
13
|
+
caughtErrorsIgnorePattern: "^_",
|
|
14
|
+
destructuredArrayIgnorePattern: "^_",
|
|
15
|
+
varsIgnorePattern: "^_",
|
|
16
|
+
ignoreRestSiblings: true
|
|
17
|
+
}]
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/preset-rules/antfu.ts
|
|
23
|
+
/**
|
|
24
|
+
* - rule: `antfu/*`
|
|
25
|
+
* - plugin: `eslint-plugin-antfu`
|
|
26
|
+
* @see https://github.com/antfu/eslint-config#top-level-function-style-etc
|
|
27
|
+
* @see https://github.com/antfu/eslint-plugin-antfu
|
|
28
|
+
*/
|
|
29
|
+
const ANTFU_PRESET_RULES = {
|
|
30
|
+
"antfu/if-newline": "off",
|
|
31
|
+
"antfu/consistent-list-newline": "off"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/preset-rules/base.ts
|
|
36
|
+
/**
|
|
37
|
+
* - rule: `*`
|
|
38
|
+
* - plugin: `none`
|
|
39
|
+
* @see https://eslint.org/docs/latest/rules/
|
|
40
|
+
*/
|
|
41
|
+
const BASE_PRESET_RULES = {
|
|
42
|
+
"no-console": "off",
|
|
43
|
+
"no-debugger": "warn",
|
|
44
|
+
"no-unused-vars": ["error", {
|
|
45
|
+
vars: "all",
|
|
46
|
+
args: "all",
|
|
47
|
+
argsIgnorePattern: "^_",
|
|
48
|
+
destructuredArrayIgnorePattern: "^_",
|
|
49
|
+
varsIgnorePattern: "^_",
|
|
50
|
+
ignoreRestSiblings: true
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/preset-rules/eslint-comments.ts
|
|
56
|
+
/**
|
|
57
|
+
* - rule: `eslint-comments/*`
|
|
58
|
+
* - plugin: `eslint-plugin-eslint-comments`
|
|
59
|
+
* @see https://github.com/antfu/eslint-config
|
|
60
|
+
* @see https://github.com/eslint-community/eslint-plugin-eslint-comments
|
|
61
|
+
*/
|
|
62
|
+
const ESLINT_COMMENTS_PRESET_RULES = { "eslint-comments/no-unlimited-disable": "off" };
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/preset-rules/node.ts
|
|
66
|
+
/**
|
|
67
|
+
* - rule: `node/*`
|
|
68
|
+
* - original rule: `n/*`
|
|
69
|
+
* - plugin: `eslint-plugin-n`
|
|
70
|
+
* @see https://github.com/antfu/eslint-config#node
|
|
71
|
+
* @see https://github.com/eslint-community/eslint-plugin-n
|
|
72
|
+
*/
|
|
73
|
+
const NODE_PRESET_RULES = { "node/prefer-global/process": "off" };
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/preset-rules/pnpm.ts
|
|
77
|
+
/**
|
|
78
|
+
* - rule: `pnpm/*`
|
|
79
|
+
* - plugin: `eslint-plugin-pnpm`
|
|
80
|
+
* @see https://github.com/antfu/eslint-config
|
|
81
|
+
* @see https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm
|
|
82
|
+
*/
|
|
83
|
+
const PNPM_PRESET_RULES = { "pnpm/yaml-enforce-settings": "off" };
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/preset-rules/style.ts
|
|
87
|
+
/**
|
|
88
|
+
* - rule: `style/*`
|
|
89
|
+
* - original rule: `@stylistic/*`
|
|
90
|
+
* - plugin: `@stylistic/eslint-plugin`
|
|
91
|
+
* @see https://github.com/antfu/eslint-config#stylistic
|
|
92
|
+
* @see https://eslint.style/rules
|
|
93
|
+
*/
|
|
94
|
+
const STYLE_PRESET_RULES = {
|
|
95
|
+
"style/quotes": [
|
|
96
|
+
"error",
|
|
97
|
+
"single",
|
|
98
|
+
{ avoidEscape: false }
|
|
99
|
+
],
|
|
100
|
+
"style/arrow-parens": ["error", "as-needed"],
|
|
101
|
+
"style/brace-style": [
|
|
102
|
+
"error",
|
|
103
|
+
"1tbs",
|
|
104
|
+
{ allowSingleLine: false }
|
|
105
|
+
],
|
|
106
|
+
"style/operator-linebreak": [
|
|
107
|
+
"error",
|
|
108
|
+
"before",
|
|
109
|
+
{ overrides: { "&&": "after" } }
|
|
110
|
+
],
|
|
111
|
+
"style/comma-dangle": "off"
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/preset-rules/test.ts
|
|
116
|
+
/**
|
|
117
|
+
* - rule: `test/*`
|
|
118
|
+
* - original rule: `vitest/*`, `no-only-tests/*`
|
|
119
|
+
* - plugin: `@vitest/eslint-plugin`, `eslint-plugin-no-only-tests`
|
|
120
|
+
* @see https://github.com/antfu/eslint-config#test
|
|
121
|
+
* @see https://github.com/vitest-dev/eslint-plugin-vitest
|
|
122
|
+
* @see https://github.com/levibuzolic/eslint-plugin-no-only-tests
|
|
123
|
+
*/
|
|
124
|
+
const TEST_PRESET_RULES = { "test/prefer-lowercase-title": "off" };
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/preset-rules/index.ts
|
|
128
|
+
const ALL_PRESET_RULES = {
|
|
129
|
+
...ANTFU_PRESET_RULES,
|
|
130
|
+
...BASE_PRESET_RULES,
|
|
131
|
+
...ESLINT_COMMENTS_PRESET_RULES,
|
|
132
|
+
...NODE_PRESET_RULES,
|
|
133
|
+
...PNPM_PRESET_RULES,
|
|
134
|
+
...STYLE_PRESET_RULES,
|
|
135
|
+
...TEST_PRESET_RULES
|
|
136
|
+
};
|
|
137
|
+
const PRESET_PREDICATES = [
|
|
138
|
+
{ rules: BASE_PRESET_RULES },
|
|
139
|
+
{ rules: ESLINT_COMMENTS_PRESET_RULES },
|
|
140
|
+
{
|
|
141
|
+
rules: STYLE_PRESET_RULES,
|
|
142
|
+
predicate: notFalse("stylistic")
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
rules: ANTFU_PRESET_RULES,
|
|
146
|
+
predicate: (options) => options.lessOpinionated !== true
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
rules: NODE_PRESET_RULES,
|
|
150
|
+
predicate: notFalse("node")
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
rules: TEST_PRESET_RULES,
|
|
154
|
+
predicate: notFalse("test")
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
rules: PNPM_PRESET_RULES,
|
|
158
|
+
predicate: notFalse("pnpm")
|
|
159
|
+
}
|
|
160
|
+
];
|
|
161
|
+
function buildPresetRules(resolvedOptions) {
|
|
162
|
+
return PRESET_PREDICATES.reduce((acc, { rules, predicate }) => {
|
|
163
|
+
if (!predicate || predicate(resolvedOptions)) Object.assign(acc, rules);
|
|
164
|
+
return acc;
|
|
165
|
+
}, {});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 自动检测/默认开启的配置,若不为 false 则加载相关预设 rules
|
|
169
|
+
* 如果默认关闭的配置,若为 true 才加载相关预设 rules
|
|
170
|
+
* @param key - The key of the option to check.
|
|
171
|
+
* @returns A predicate function that checks if the option is not false.
|
|
172
|
+
*/
|
|
173
|
+
function notFalse(key) {
|
|
174
|
+
return (options) => options[key] !== false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
4
178
|
//#region src/config.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"1tbs",
|
|
31
|
-
{ allowSingleLine: false }
|
|
32
|
-
],
|
|
33
|
-
"style/operator-linebreak": [
|
|
34
|
-
"error",
|
|
35
|
-
"before",
|
|
36
|
-
{ overrides: { "&&": "after" } }
|
|
37
|
-
],
|
|
38
|
-
"style/comma-dangle": "off",
|
|
39
|
-
"eslint-comments/no-unlimited-disable": "off"
|
|
40
|
-
}
|
|
41
|
-
}, options), userConfigs);
|
|
179
|
+
/**
|
|
180
|
+
* @param antfuOptions Configures for antfu's config.
|
|
181
|
+
* @param userFlatConfigs From the second arguments they are ESLint Flat Configs, you can have multiple configs.
|
|
182
|
+
*
|
|
183
|
+
* 前提:用户预设优于内置预设,若有相同的 key,则进行覆盖。
|
|
184
|
+
* 1. 排除 rules 的前提下,合并 baseOptions 与 userOptions,得到 mergedOptions
|
|
185
|
+
* 2. 根据 mergedOptions 取预设规则 presetRules,不对用户 rules 作错误兼容
|
|
186
|
+
* 3. 将 presetRules 与 userRules 合并,得到 mergedRules
|
|
187
|
+
* 4. 将 mergedOptions 与 { rules: mergedRules } 合并,得到 resolvedOptions
|
|
188
|
+
* 5. 将 resolvedOptions 作为 antfu 第一个参数
|
|
189
|
+
*/
|
|
190
|
+
function defineConfig(antfuOptions, ...userFlatConfigs) {
|
|
191
|
+
const { rules: userRules, ...userOptionsWithoutRules } = antfuOptions ?? {};
|
|
192
|
+
const mergedOptions = merge({}, {
|
|
193
|
+
formatters: { prettierOptions: {
|
|
194
|
+
printWidth: 100,
|
|
195
|
+
semi: false,
|
|
196
|
+
singleQuote: true,
|
|
197
|
+
arrowParens: "avoid",
|
|
198
|
+
trailingComma: "es5",
|
|
199
|
+
htmlWhitespaceSensitivity: "css"
|
|
200
|
+
} },
|
|
201
|
+
typescript: true
|
|
202
|
+
}, userOptionsWithoutRules);
|
|
203
|
+
return antfu(merge({}, mergedOptions, { rules: merge({}, buildPresetRules(mergedOptions), userRules ?? {}) }), ...mergedOptions.typescript ? [TYPESCRIPT_PRESET_CONFIG] : [], ...userFlatConfigs);
|
|
42
204
|
}
|
|
43
205
|
|
|
44
206
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tofrankie/eslint",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "Shared ESLint configuration for @tofrankie projects",
|
|
6
6
|
"author": "Frankie <1426203851@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
"eslint": ">=9.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@eslint-react/eslint-plugin": "^2.12.4",
|
|
41
42
|
"eslint-plugin-format": "^1.4.0",
|
|
43
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
44
|
+
"eslint-plugin-react-refresh": "^0.5.0",
|
|
42
45
|
"lodash.merge": "^4.6.2"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|