@tofrankie/eslint 0.0.19 → 0.0.21
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 +19 -2
- package/README.md +107 -30
- package/dist/index.cjs +439 -256
- package/dist/index.d.cts +12 -13
- package/dist/index.d.mts +12 -13
- package/dist/index.mjs +432 -257
- package/package.json +20 -4
package/dist/index.mjs
CHANGED
|
@@ -1,157 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import merge from "lodash.merge";
|
|
1
|
+
import antfu from "@antfu/eslint-config";
|
|
3
2
|
import { jsdoc } from "eslint-plugin-jsdoc";
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { createDefu } from "defu";
|
|
4
|
+
import { findUpSync } from "find-up-simple";
|
|
5
|
+
import { isPackageExists } from "local-pkg";
|
|
6
|
+
export * from "@antfu/eslint-config";
|
|
7
|
+
//#region src/presets/e18e.ts
|
|
8
|
+
const e18eRules = {
|
|
9
|
+
"e18e/ban-dependencies": "off",
|
|
10
|
+
"e18e/prefer-array-to-sorted": "off",
|
|
11
|
+
"e18e/prefer-static-regex": "off"
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/presets/eslint-comments.ts
|
|
15
|
+
const eslintCommentsRules = { "eslint-comments/no-unlimited-disable": "off" };
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/presets/javascript.ts
|
|
18
|
+
const javascriptRules = {
|
|
19
|
+
"no-console": "off",
|
|
20
|
+
"no-debugger": "warn",
|
|
21
|
+
"no-unused-vars": "off"
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/presets/jsdoc.ts
|
|
25
|
+
const jsdocJavaScriptRules = {
|
|
6
26
|
"jsdoc/check-syntax": "error",
|
|
27
|
+
"jsdoc/newline-after-description": "off",
|
|
7
28
|
"jsdoc/no-defaults": "off",
|
|
29
|
+
"jsdoc/reject-any-type": "off",
|
|
8
30
|
"jsdoc/require-jsdoc": "off",
|
|
9
31
|
"jsdoc/require-param-description": "off",
|
|
32
|
+
"jsdoc/require-param-type": "warn",
|
|
10
33
|
"jsdoc/require-property-description": "off",
|
|
11
34
|
"jsdoc/require-returns": "off",
|
|
12
|
-
"jsdoc/require-returns-type": "off",
|
|
13
35
|
"jsdoc/require-returns-description": "off",
|
|
14
|
-
"jsdoc/
|
|
15
|
-
"jsdoc/reject-any-type": "off"
|
|
16
|
-
};
|
|
17
|
-
const SHARED_SETTINGS = { tagNamePreference: {
|
|
18
|
-
description: "desc",
|
|
19
|
-
property: "prop",
|
|
20
|
-
returns: "return"
|
|
21
|
-
} };
|
|
22
|
-
const JSDOC_PRESET_CONFIG = [jsdoc({
|
|
23
|
-
config: "flat/recommended-typescript-flavor-error",
|
|
24
|
-
files: [
|
|
25
|
-
"**/*.js",
|
|
26
|
-
"**/*.jsx",
|
|
27
|
-
"**/*.cjs",
|
|
28
|
-
"**/*.mjs"
|
|
29
|
-
],
|
|
30
|
-
rules: {
|
|
31
|
-
...SHARED_RULES,
|
|
32
|
-
"jsdoc/require-param-type": "warn"
|
|
33
|
-
},
|
|
34
|
-
settings: SHARED_SETTINGS
|
|
35
|
-
}), jsdoc({
|
|
36
|
-
config: "flat/recommended-typescript-error",
|
|
37
|
-
files: [
|
|
38
|
-
"**/*.ts",
|
|
39
|
-
"**/*.tsx",
|
|
40
|
-
"**/*.cts",
|
|
41
|
-
"**/*.mts"
|
|
42
|
-
],
|
|
43
|
-
rules: {
|
|
44
|
-
...SHARED_RULES,
|
|
45
|
-
"jsdoc/require-param-type": "off"
|
|
46
|
-
},
|
|
47
|
-
settings: SHARED_SETTINGS
|
|
48
|
-
})];
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/preset-configs/typescript.ts
|
|
51
|
-
const TYPESCRIPT_PRESET_CONFIG = {
|
|
52
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
53
|
-
rules: {
|
|
54
|
-
"no-unused-vars": "off",
|
|
55
|
-
"ts/no-unused-vars": ["error", {
|
|
56
|
-
args: "all",
|
|
57
|
-
argsIgnorePattern: "^_",
|
|
58
|
-
caughtErrors: "all",
|
|
59
|
-
caughtErrorsIgnorePattern: "^_",
|
|
60
|
-
destructuredArrayIgnorePattern: "^_",
|
|
61
|
-
varsIgnorePattern: "^_",
|
|
62
|
-
ignoreRestSiblings: true
|
|
63
|
-
}]
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/preset-rules/antfu.ts
|
|
68
|
-
/**
|
|
69
|
-
* - rule: `antfu/*`
|
|
70
|
-
* - plugin: `eslint-plugin-antfu`
|
|
71
|
-
* @see https://github.com/antfu/eslint-config#top-level-function-style-etc
|
|
72
|
-
* @see https://github.com/antfu/eslint-plugin-antfu
|
|
73
|
-
*/
|
|
74
|
-
const ANTFU_PRESET_RULES = {
|
|
75
|
-
"antfu/if-newline": "off",
|
|
76
|
-
"antfu/consistent-list-newline": "off"
|
|
77
|
-
};
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/preset-rules/base.ts
|
|
80
|
-
/**
|
|
81
|
-
* - rule: `*`
|
|
82
|
-
* - plugin: `none`
|
|
83
|
-
* @see https://eslint.org/docs/latest/rules/
|
|
84
|
-
*/
|
|
85
|
-
const BASE_PRESET_RULES = {
|
|
86
|
-
"no-console": "off",
|
|
87
|
-
"no-debugger": "warn",
|
|
88
|
-
"no-unused-vars": ["error", {
|
|
89
|
-
vars: "all",
|
|
90
|
-
args: "all",
|
|
91
|
-
argsIgnorePattern: "^_",
|
|
92
|
-
destructuredArrayIgnorePattern: "^_",
|
|
93
|
-
varsIgnorePattern: "^_",
|
|
94
|
-
ignoreRestSiblings: true
|
|
95
|
-
}]
|
|
36
|
+
"jsdoc/require-returns-type": "off"
|
|
96
37
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
38
|
+
const jsdocTypeScriptRules = {
|
|
39
|
+
"jsdoc/check-syntax": "error",
|
|
40
|
+
"jsdoc/newline-after-description": "off",
|
|
41
|
+
"jsdoc/no-defaults": "off",
|
|
42
|
+
"jsdoc/reject-any-type": "off",
|
|
43
|
+
"jsdoc/require-jsdoc": "off",
|
|
44
|
+
"jsdoc/require-param-description": "off",
|
|
45
|
+
"jsdoc/require-param-type": "off",
|
|
46
|
+
"jsdoc/require-property-description": "off",
|
|
47
|
+
"jsdoc/require-returns": "off",
|
|
48
|
+
"jsdoc/require-returns-description": "off",
|
|
49
|
+
"jsdoc/require-returns-type": "off"
|
|
108
50
|
};
|
|
109
51
|
//#endregion
|
|
110
|
-
//#region src/
|
|
111
|
-
|
|
112
|
-
* - rule: `eslint-comments/*`
|
|
113
|
-
* - plugin: `eslint-plugin-eslint-comments`
|
|
114
|
-
* @see https://github.com/antfu/eslint-config
|
|
115
|
-
* @see https://github.com/eslint-community/eslint-plugin-eslint-comments
|
|
116
|
-
*/
|
|
117
|
-
const ESLINT_COMMENTS_PRESET_RULES = { "eslint-comments/no-unlimited-disable": "off" };
|
|
52
|
+
//#region src/presets/node.ts
|
|
53
|
+
const nodeRules = { "node/prefer-global/process": "off" };
|
|
118
54
|
//#endregion
|
|
119
|
-
//#region src/
|
|
120
|
-
|
|
121
|
-
* - rule: `node/*`
|
|
122
|
-
* - original rule: `n/*`
|
|
123
|
-
* - plugin: `eslint-plugin-n`
|
|
124
|
-
* @see https://github.com/antfu/eslint-config#node
|
|
125
|
-
* @see https://github.com/eslint-community/eslint-plugin-n
|
|
126
|
-
*/
|
|
127
|
-
const NODE_PRESET_RULES = { "node/prefer-global/process": "off" };
|
|
55
|
+
//#region src/presets/pnpm.ts
|
|
56
|
+
const pnpmRules = { "pnpm/yaml-enforce-settings": "off" };
|
|
128
57
|
//#endregion
|
|
129
|
-
//#region src/
|
|
130
|
-
|
|
131
|
-
* - rule: `pnpm/*`
|
|
132
|
-
* - plugin: `eslint-plugin-pnpm`
|
|
133
|
-
* @see https://github.com/antfu/eslint-config
|
|
134
|
-
* @see https://github.com/antfu/pnpm-workspace-utils/tree/main/packages/eslint-plugin-pnpm
|
|
135
|
-
*/
|
|
136
|
-
const PNPM_PRESET_RULES = { "pnpm/yaml-enforce-settings": "off" };
|
|
58
|
+
//#region src/presets/react.ts
|
|
59
|
+
const reactRules = { "react-hooks-extra/no-direct-set-state-in-use-effect": "off" };
|
|
137
60
|
//#endregion
|
|
138
|
-
//#region src/
|
|
139
|
-
|
|
140
|
-
* - rule: `react/*`、`react-hooks-extra/*`
|
|
141
|
-
* - plugin: `eslint-plugin-react-hooks-extra`
|
|
142
|
-
* @see https://www.npmjs.com/package/eslint-plugin-react-hooks-extra
|
|
143
|
-
*/
|
|
144
|
-
const REACT_PRESET_RULES = { "react-hooks-extra/no-direct-set-state-in-use-effect": "off" };
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/preset-rules/style.ts
|
|
147
|
-
/**
|
|
148
|
-
* - rule: `style/*`
|
|
149
|
-
* - original rule: `@stylistic/*`
|
|
150
|
-
* - plugin: `@stylistic/eslint-plugin`
|
|
151
|
-
* @see https://github.com/antfu/eslint-config#stylistic
|
|
152
|
-
* @see https://eslint.style/rules
|
|
153
|
-
*/
|
|
154
|
-
const STYLE_PRESET_RULES = {
|
|
61
|
+
//#region src/presets/stylistic.ts
|
|
62
|
+
const stylisticRules = {
|
|
155
63
|
"style/quotes": [
|
|
156
64
|
"error",
|
|
157
65
|
"single",
|
|
@@ -169,20 +77,10 @@ const STYLE_PRESET_RULES = {
|
|
|
169
77
|
],
|
|
170
78
|
"style/operator-linebreak": [
|
|
171
79
|
"error",
|
|
172
|
-
"
|
|
80
|
+
"after",
|
|
173
81
|
{ overrides: {
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
"??": "after",
|
|
177
|
-
"=": "after",
|
|
178
|
-
"+": "after",
|
|
179
|
-
"-": "after",
|
|
180
|
-
"*": "after",
|
|
181
|
-
"&": "after",
|
|
182
|
-
"<": "after",
|
|
183
|
-
"<=": "after",
|
|
184
|
-
">": "after",
|
|
185
|
-
">=": "after"
|
|
82
|
+
"?": "before",
|
|
83
|
+
":": "before"
|
|
186
84
|
} }
|
|
187
85
|
],
|
|
188
86
|
"style/member-delimiter-style": ["error", {
|
|
@@ -203,137 +101,414 @@ const STYLE_PRESET_RULES = {
|
|
|
203
101
|
"style/comma-dangle": "off",
|
|
204
102
|
"style/indent": "off",
|
|
205
103
|
"style/indent-binary-ops": "off",
|
|
206
|
-
"style/multiline-ternary": "off",
|
|
207
|
-
"style/jsx-wrap-multilines": "off",
|
|
208
104
|
"style/jsx-curly-newline": "off",
|
|
209
|
-
"style/jsx-one-expression-per-line": "off"
|
|
105
|
+
"style/jsx-one-expression-per-line": "off",
|
|
106
|
+
"style/jsx-wrap-multilines": "off",
|
|
107
|
+
"style/multiline-ternary": "off"
|
|
108
|
+
};
|
|
109
|
+
const stylisticLessOpinionatedRules = {
|
|
110
|
+
"antfu/consistent-list-newline": "off",
|
|
111
|
+
"antfu/if-newline": "off"
|
|
210
112
|
};
|
|
211
113
|
//#endregion
|
|
212
|
-
//#region src/
|
|
213
|
-
|
|
214
|
-
* - rule: `test/*`
|
|
215
|
-
* - original rule: `vitest/*`, `no-only-tests/*`
|
|
216
|
-
* - plugin: `@vitest/eslint-plugin`, `eslint-plugin-no-only-tests`
|
|
217
|
-
* @see https://github.com/antfu/eslint-config#test
|
|
218
|
-
* @see https://github.com/vitest-dev/eslint-plugin-vitest
|
|
219
|
-
* @see https://github.com/levibuzolic/eslint-plugin-no-only-tests
|
|
220
|
-
*/
|
|
221
|
-
const TEST_PRESET_RULES = { "test/prefer-lowercase-title": "off" };
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/preset-rules/unicorn.ts
|
|
224
|
-
/**
|
|
225
|
-
* - rule: `unicorn/*`
|
|
226
|
-
* - plugin: `eslint-plugin-unicorn`
|
|
227
|
-
* @see https://github.com/sindresorhus/eslint-plugin-unicorn
|
|
228
|
-
*/
|
|
229
|
-
const UNICORN_PRESET_RULES = { "unicorn/number-literal-case": ["error", { hexadecimalValue: "lowercase" }] };
|
|
114
|
+
//#region src/presets/test.ts
|
|
115
|
+
const testRules = { "test/prefer-lowercase-title": "off" };
|
|
230
116
|
//#endregion
|
|
231
|
-
//#region src/
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
void: "always",
|
|
244
|
-
normal: "always",
|
|
245
|
-
component: "always"
|
|
246
|
-
},
|
|
247
|
-
svg: "always",
|
|
248
|
-
math: "always"
|
|
117
|
+
//#region src/presets/typescript.ts
|
|
118
|
+
const typescriptRules = {
|
|
119
|
+
"no-unused-vars": "off",
|
|
120
|
+
"unused-imports/no-unused-vars": "off",
|
|
121
|
+
"ts/no-unused-vars": ["error", {
|
|
122
|
+
args: "all",
|
|
123
|
+
argsIgnorePattern: "^_",
|
|
124
|
+
caughtErrors: "all",
|
|
125
|
+
caughtErrorsIgnorePattern: "^_",
|
|
126
|
+
destructuredArrayIgnorePattern: "^_",
|
|
127
|
+
varsIgnorePattern: "^_",
|
|
128
|
+
ignoreRestSiblings: true
|
|
249
129
|
}]
|
|
250
130
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/presets/index.ts
|
|
133
|
+
const integrationRulePresets = [
|
|
134
|
+
{
|
|
135
|
+
key: "javascript",
|
|
136
|
+
rules: javascriptRules
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: "e18e",
|
|
140
|
+
option: "e18e",
|
|
141
|
+
rules: e18eRules
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
key: "unicorn",
|
|
145
|
+
option: "unicorn",
|
|
146
|
+
rules: { "unicorn/number-literal-case": ["error", { hexadecimalValue: "lowercase" }] }
|
|
147
|
+
},
|
|
267
148
|
{
|
|
268
|
-
|
|
269
|
-
|
|
149
|
+
key: "react",
|
|
150
|
+
option: "react",
|
|
151
|
+
rules: reactRules
|
|
270
152
|
},
|
|
271
153
|
{
|
|
272
|
-
|
|
273
|
-
|
|
154
|
+
key: "stylistic",
|
|
155
|
+
option: "stylistic",
|
|
156
|
+
rules: stylisticRules
|
|
274
157
|
},
|
|
275
158
|
{
|
|
276
|
-
|
|
277
|
-
|
|
159
|
+
key: "stylistic",
|
|
160
|
+
rules: stylisticLessOpinionatedRules
|
|
278
161
|
},
|
|
279
162
|
{
|
|
280
|
-
|
|
281
|
-
|
|
163
|
+
key: "test",
|
|
164
|
+
option: "test",
|
|
165
|
+
rules: testRules
|
|
282
166
|
},
|
|
283
167
|
{
|
|
284
|
-
|
|
285
|
-
|
|
168
|
+
key: "typescript",
|
|
169
|
+
option: "typescript",
|
|
170
|
+
rules: typescriptRules
|
|
286
171
|
},
|
|
287
172
|
{
|
|
288
|
-
|
|
289
|
-
|
|
173
|
+
key: "vue",
|
|
174
|
+
option: "vue",
|
|
175
|
+
rules: {
|
|
176
|
+
"vue/singleline-html-element-content-newline": "off",
|
|
177
|
+
"vue/html-closing-bracket-newline": "off",
|
|
178
|
+
"vue/html-indent": "off",
|
|
179
|
+
"vue/html-self-closing": ["warn", {
|
|
180
|
+
html: {
|
|
181
|
+
void: "always",
|
|
182
|
+
normal: "always",
|
|
183
|
+
component: "always"
|
|
184
|
+
},
|
|
185
|
+
svg: "always",
|
|
186
|
+
math: "always"
|
|
187
|
+
}]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
const configItemRulePresets = [
|
|
192
|
+
{
|
|
193
|
+
name: "eslint-comments",
|
|
194
|
+
rules: eslintCommentsRules
|
|
290
195
|
},
|
|
291
196
|
{
|
|
292
|
-
|
|
293
|
-
|
|
197
|
+
name: "node",
|
|
198
|
+
option: "node",
|
|
199
|
+
rules: nodeRules
|
|
294
200
|
},
|
|
295
|
-
{
|
|
296
|
-
|
|
201
|
+
{
|
|
202
|
+
name: "pnpm",
|
|
203
|
+
option: "pnpm",
|
|
204
|
+
rules: pnpmRules
|
|
205
|
+
}
|
|
297
206
|
];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (!predicate || predicate(resolvedOptions)) Object.assign(acc, rules);
|
|
301
|
-
return acc;
|
|
302
|
-
}, {});
|
|
303
|
-
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/patches/config-item-rules.ts
|
|
304
209
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* @return A predicate function that checks if the option is not false.
|
|
210
|
+
* These rule families do not have an equivalent antfu integration-overrides
|
|
211
|
+
* path that we can merge into before calling `antfu()`. They must stay as
|
|
212
|
+
* post-antfu config-item patches and be applied onto a specific named item.
|
|
309
213
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
214
|
+
const CONFIG_ITEM_RULE_TARGETS = {
|
|
215
|
+
"eslint-comments/": "antfu/eslint-comments/rules",
|
|
216
|
+
"jsdoc/": "antfu/jsdoc/rules",
|
|
217
|
+
"node/": "antfu/node/rules",
|
|
218
|
+
"pnpm/": "antfu/pnpm/pnpm-workspace-yaml"
|
|
219
|
+
};
|
|
220
|
+
const applyConfigItemRulePatches = (composer, options) => {
|
|
221
|
+
for (const preset of configItemRulePresets) {
|
|
222
|
+
if (preset.option != null && !options[preset.option]) continue;
|
|
223
|
+
const targetName = resolveConfigItemTarget(preset);
|
|
224
|
+
if (!targetName) continue;
|
|
225
|
+
composer.override(targetName, { rules: preset.rules });
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
function resolveConfigItemTarget(preset) {
|
|
229
|
+
const ruleIds = Object.keys(preset.rules);
|
|
230
|
+
if (ruleIds.length === 0) {
|
|
231
|
+
warnIgnoredPreset(preset.name, "it does not define any rules");
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
if (ruleIds.some((ruleId) => !ruleId.includes("/"))) {
|
|
235
|
+
warnIgnoredPreset(preset.name, "package presets should not contain built-in rules; only plugin-prefixed rules can be auto-routed");
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const targetNames = /* @__PURE__ */ new Set();
|
|
239
|
+
for (const ruleId of ruleIds) {
|
|
240
|
+
const targetName = findConfigItemTarget(ruleId);
|
|
241
|
+
if (!targetName) {
|
|
242
|
+
warnIgnoredPreset(preset.name, `no config-item target is registered for rule "${ruleId}"`);
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
targetNames.add(targetName);
|
|
246
|
+
}
|
|
247
|
+
if (targetNames.size !== 1) {
|
|
248
|
+
warnIgnoredPreset(preset.name, `its rules map to multiple config items (${Array.from(targetNames).join(", ")})`);
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
return Array.from(targetNames)[0];
|
|
252
|
+
}
|
|
253
|
+
function findConfigItemTarget(ruleId) {
|
|
254
|
+
for (const [rulePrefix, targetName] of Object.entries(CONFIG_ITEM_RULE_TARGETS)) if (ruleId.startsWith(rulePrefix)) return targetName;
|
|
255
|
+
}
|
|
256
|
+
function warnIgnoredPreset(name, reason) {
|
|
257
|
+
const processLike = Reflect.get(globalThis, "process");
|
|
258
|
+
if (isObjectLike$2(processLike) && "emitWarning" in processLike && typeof processLike.emitWarning === "function") processLike.emitWarning(`[@tofrankie/eslint] Ignore config-item preset "${name}": ${reason}.`);
|
|
259
|
+
}
|
|
260
|
+
function isObjectLike$2(value) {
|
|
261
|
+
return typeof value === "object" && value !== null;
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/patches/jsdoc.ts
|
|
265
|
+
const SHARED_SETTINGS = { tagNamePreference: {
|
|
266
|
+
description: "desc",
|
|
267
|
+
property: "prop",
|
|
268
|
+
returns: "return"
|
|
269
|
+
} };
|
|
270
|
+
const applyJsdocPatch = (composer, options) => {
|
|
271
|
+
if (!options.jsdoc) return;
|
|
272
|
+
if (options.jsdocMode === "managed") {
|
|
273
|
+
composer.insertBefore("antfu/disables", ...buildManagedJsdocItems());
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
composer.insertAfter("antfu/jsdoc/rules", ...buildAntfuJsdocItems());
|
|
277
|
+
};
|
|
278
|
+
function buildManagedJsdocItems() {
|
|
279
|
+
return [...toConfigItems(jsdoc({
|
|
280
|
+
config: "flat/recommended-typescript-flavor-error",
|
|
281
|
+
files: [
|
|
282
|
+
"**/*.js",
|
|
283
|
+
"**/*.jsx",
|
|
284
|
+
"**/*.cjs",
|
|
285
|
+
"**/*.mjs"
|
|
286
|
+
],
|
|
287
|
+
rules: jsdocJavaScriptRules,
|
|
288
|
+
settings: SHARED_SETTINGS
|
|
289
|
+
})), ...toConfigItems(jsdoc({
|
|
290
|
+
config: "flat/recommended-typescript-error",
|
|
291
|
+
files: [
|
|
292
|
+
"**/*.ts",
|
|
293
|
+
"**/*.tsx",
|
|
294
|
+
"**/*.cts",
|
|
295
|
+
"**/*.mts"
|
|
296
|
+
],
|
|
297
|
+
rules: jsdocTypeScriptRules,
|
|
298
|
+
settings: SHARED_SETTINGS
|
|
299
|
+
}))];
|
|
312
300
|
}
|
|
301
|
+
function buildAntfuJsdocItems() {
|
|
302
|
+
return [{
|
|
303
|
+
name: "tofrankie/jsdoc/javascript",
|
|
304
|
+
files: [
|
|
305
|
+
"**/*.js",
|
|
306
|
+
"**/*.jsx",
|
|
307
|
+
"**/*.cjs",
|
|
308
|
+
"**/*.mjs"
|
|
309
|
+
],
|
|
310
|
+
rules: jsdocJavaScriptRules,
|
|
311
|
+
settings: SHARED_SETTINGS
|
|
312
|
+
}, {
|
|
313
|
+
name: "tofrankie/jsdoc/typescript",
|
|
314
|
+
files: [
|
|
315
|
+
"**/*.ts",
|
|
316
|
+
"**/*.tsx",
|
|
317
|
+
"**/*.cts",
|
|
318
|
+
"**/*.mts"
|
|
319
|
+
],
|
|
320
|
+
rules: jsdocTypeScriptRules,
|
|
321
|
+
settings: SHARED_SETTINGS
|
|
322
|
+
}];
|
|
323
|
+
}
|
|
324
|
+
function toConfigItems(config) {
|
|
325
|
+
return Array.isArray(config) ? config : [config];
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/patches/index.ts
|
|
329
|
+
const configItemPatches = [applyConfigItemRulePatches, applyJsdocPatch];
|
|
313
330
|
//#endregion
|
|
314
|
-
//#region src/
|
|
331
|
+
//#region src/core/apply-post-antfu-patches.ts
|
|
315
332
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
333
|
+
* Post-antfu patches only live here.
|
|
334
|
+
* Most package defaults should be merged into AntfuOptions before `antfu()`
|
|
335
|
+
* so user overrides keep the same semantics as plain @antfu/eslint-config.
|
|
318
336
|
*/
|
|
337
|
+
function applyPostAntfuPatches(composer, options) {
|
|
338
|
+
for (const applyPatch of configItemPatches) applyPatch(composer, options);
|
|
339
|
+
}
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/core/compose-preset.ts
|
|
342
|
+
function composePreset(options) {
|
|
343
|
+
const preset = {};
|
|
344
|
+
for (const integrationRulePreset of integrationRulePresets) {
|
|
345
|
+
if (!isPresetEnabled(integrationRulePreset.option, options)) continue;
|
|
346
|
+
mergeRulesIntoIntegrationOptions(preset, integrationRulePreset.key, integrationRulePreset.rules);
|
|
347
|
+
}
|
|
348
|
+
return preset;
|
|
349
|
+
}
|
|
350
|
+
function mergeRulesIntoIntegrationOptions(preset, key, rules) {
|
|
351
|
+
const currentValue = preset[key];
|
|
352
|
+
const currentOptions = isObjectLike$1(currentValue) ? currentValue : {};
|
|
353
|
+
const currentOverrides = isObjectLike$1(currentOptions) && "overrides" in currentOptions && isObjectLike$1(currentOptions.overrides) ? currentOptions.overrides : {};
|
|
354
|
+
preset[key] = {
|
|
355
|
+
...currentOptions,
|
|
356
|
+
overrides: {
|
|
357
|
+
...currentOverrides,
|
|
358
|
+
...rules
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function isObjectLike$1(value) {
|
|
363
|
+
return typeof value === "object" && value !== null;
|
|
364
|
+
}
|
|
365
|
+
function isPresetEnabled(option, options) {
|
|
366
|
+
return option == null ? true : options[option] === true;
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/core/merge-options.ts
|
|
370
|
+
const mergeOptions = createDefu((obj, key, value) => {
|
|
371
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
372
|
+
obj[key] = value;
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
});
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/core/merge-preset.ts
|
|
379
|
+
function mergePreset(userOptions, preset) {
|
|
380
|
+
const mergedOptions = mergeOptions(userOptions, preset);
|
|
381
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "e18e");
|
|
382
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "react");
|
|
383
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "stylistic");
|
|
384
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "test");
|
|
385
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "typescript");
|
|
386
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "unicorn");
|
|
387
|
+
restoreBooleanObjectPreset(mergedOptions, userOptions, preset, "vue");
|
|
388
|
+
return mergedOptions;
|
|
389
|
+
}
|
|
390
|
+
function restoreBooleanObjectPreset(mergedOptions, userOptions, preset, key) {
|
|
391
|
+
if (userOptions[key] !== true) return;
|
|
392
|
+
const presetValue = preset[key];
|
|
393
|
+
if (!isObjectLike(presetValue)) return;
|
|
394
|
+
mergedOptions[key] = mergeOptions({}, presetValue);
|
|
395
|
+
}
|
|
396
|
+
function isObjectLike(value) {
|
|
397
|
+
return typeof value === "object" && value !== null;
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/core/default-options.ts
|
|
401
|
+
const DEFAULT_OPTIONS = { formatters: {
|
|
402
|
+
astro: false,
|
|
403
|
+
css: false,
|
|
404
|
+
graphql: false,
|
|
405
|
+
html: false,
|
|
406
|
+
markdown: false,
|
|
407
|
+
slidev: false,
|
|
408
|
+
svg: false,
|
|
409
|
+
xml: false,
|
|
410
|
+
prettierOptions: {
|
|
411
|
+
printWidth: 120,
|
|
412
|
+
semi: false,
|
|
413
|
+
singleQuote: true,
|
|
414
|
+
arrowParens: "avoid",
|
|
415
|
+
trailingComma: "es5",
|
|
416
|
+
htmlWhitespaceSensitivity: "css"
|
|
417
|
+
}
|
|
418
|
+
} };
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/core/resolve-antfu-options.ts
|
|
421
|
+
function resolveAntfuOptions(userOptions) {
|
|
422
|
+
return {
|
|
423
|
+
...mergeOptions(userOptions, DEFAULT_OPTIONS),
|
|
424
|
+
formatters: resolveFormattersOption(userOptions.formatters)
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function resolveFormattersOption(value) {
|
|
428
|
+
if (value === false) return false;
|
|
429
|
+
if (value === true) return mergeOptions({
|
|
430
|
+
css: true,
|
|
431
|
+
graphql: true,
|
|
432
|
+
html: true,
|
|
433
|
+
markdown: true
|
|
434
|
+
}, DEFAULT_OPTIONS.formatters ?? {});
|
|
435
|
+
return mergeOptions(value ?? {}, DEFAULT_OPTIONS.formatters ?? {});
|
|
436
|
+
}
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/core/detect-packages.ts
|
|
439
|
+
function detectPackage(name) {
|
|
440
|
+
return isPackageExists(name);
|
|
441
|
+
}
|
|
442
|
+
function detectPnpmWorkspaceYaml(cwd) {
|
|
443
|
+
return findUpSync("pnpm-workspace.yaml", cwd === void 0 ? void 0 : { cwd }) !== void 0;
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/core/jsdoc-mode.ts
|
|
447
|
+
const INTERNAL_JSDOC_MODE = "antfu";
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/core/resolve-config-options.ts
|
|
450
|
+
function resolveConfigOptions(options) {
|
|
451
|
+
const typescript = isAutoDetectedEnabled(options.typescript, "typescript");
|
|
452
|
+
const typescriptTypeAware = typescript && isOptionObject(options.typescript) && "tsconfigPath" in options.typescript && Boolean(options.typescript.tsconfigPath);
|
|
453
|
+
return {
|
|
454
|
+
e18e: isEnabledByDefault(options.e18e),
|
|
455
|
+
jsdoc: isEnabledByDefault(options.jsdoc),
|
|
456
|
+
jsdocMode: INTERNAL_JSDOC_MODE,
|
|
457
|
+
lessOpinionated: options.lessOpinionated === true,
|
|
458
|
+
node: isEnabledByDefault(options.node),
|
|
459
|
+
pnpm: isPnpmEnabled(options.pnpm),
|
|
460
|
+
react: isExplicitlyEnabled(options.react),
|
|
461
|
+
stylistic: isEnabledByDefault(options.stylistic),
|
|
462
|
+
test: isEnabledByDefault(options.test),
|
|
463
|
+
typescript,
|
|
464
|
+
typescriptTypeAware,
|
|
465
|
+
unicorn: isEnabledByDefault(options.unicorn),
|
|
466
|
+
vue: isAutoDetectedEnabled(options.vue, "vue")
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function isEnabledByDefault(value) {
|
|
470
|
+
return value !== false;
|
|
471
|
+
}
|
|
472
|
+
function isExplicitlyEnabled(value) {
|
|
473
|
+
return value === true || isOptionObject(value);
|
|
474
|
+
}
|
|
475
|
+
function isPnpmEnabled(pnpmOption) {
|
|
476
|
+
if (pnpmOption === false) return false;
|
|
477
|
+
if (isExplicitlyEnabled(pnpmOption)) return true;
|
|
478
|
+
return detectPnpmWorkspaceYaml();
|
|
479
|
+
}
|
|
480
|
+
function isAutoDetectedEnabled(value, packageName) {
|
|
481
|
+
if (value === false) return false;
|
|
482
|
+
return isExplicitlyEnabled(value) || detectPackage(packageName);
|
|
483
|
+
}
|
|
484
|
+
function isOptionObject(value) {
|
|
485
|
+
return typeof value === "object" && value !== null;
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/define-config.ts
|
|
319
489
|
function defineConfig(antfuOptions, ...userFlatConfigs) {
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
} },
|
|
330
|
-
typescript: true
|
|
331
|
-
}, userOptionsWithoutRules);
|
|
332
|
-
const resolvedOptions = merge({}, mergedOptions, { rules: merge({}, buildPresetRules(mergedOptions), userRules ?? {}) });
|
|
333
|
-
const presetConfigs = [];
|
|
334
|
-
if (mergedOptions.typescript) presetConfigs.push(TYPESCRIPT_PRESET_CONFIG);
|
|
335
|
-
if (mergedOptions.jsdoc !== false) presetConfigs.push(...JSDOC_PRESET_CONFIG);
|
|
336
|
-
return antfu(resolvedOptions, ...presetConfigs, ...userFlatConfigs);
|
|
490
|
+
const userOptions = antfuOptions ?? {};
|
|
491
|
+
const resolvedConfigOptions = resolveConfigOptions(userOptions);
|
|
492
|
+
const composer = antfu(resolveComposerOptions(resolveAntfuOptions(mergePreset(userOptions, composePreset(resolvedConfigOptions))), resolvedConfigOptions.jsdocMode, resolvedConfigOptions.jsdoc), ...userFlatConfigs);
|
|
493
|
+
applyPostAntfuPatches(composer, resolvedConfigOptions);
|
|
494
|
+
return composer;
|
|
495
|
+
}
|
|
496
|
+
function resolveComposerOptions(options, jsdocMode, jsdocEnabled) {
|
|
497
|
+
if (!jsdocEnabled || jsdocMode !== "managed") return options;
|
|
498
|
+
return mergeOptions({ jsdoc: false }, options);
|
|
337
499
|
}
|
|
338
500
|
//#endregion
|
|
339
|
-
|
|
501
|
+
//#region src/language-options/miniprogram.ts
|
|
502
|
+
const MINIPROGRAM_LANGUAGE_OPTIONS = { globals: {
|
|
503
|
+
wx: true,
|
|
504
|
+
App: true,
|
|
505
|
+
getApp: true,
|
|
506
|
+
getCurrentPages: true,
|
|
507
|
+
Page: true,
|
|
508
|
+
Component: true,
|
|
509
|
+
Behavior: true,
|
|
510
|
+
requireMiniProgram: true,
|
|
511
|
+
requirePlugin: true
|
|
512
|
+
} };
|
|
513
|
+
//#endregion
|
|
514
|
+
export { MINIPROGRAM_LANGUAGE_OPTIONS, defineConfig };
|