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