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