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