@icebreakers/eslint-config 1.6.29 → 1.6.30

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.js CHANGED
@@ -1,649 +1,438 @@
1
+ import { createRequire } from "node:module";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import process from "node:process";
5
+ //#region \0rolldown/runtime.js
1
6
  var __defProp = Object.defineProperty;
2
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
8
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __exportAll = (all, no_symbols) => {
11
+ let target = {};
12
+ for (var name in all) __defProp(target, name, {
13
+ get: all[name],
14
+ enumerable: true
15
+ });
16
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
17
+ return target;
18
+ };
5
19
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
20
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
21
+ key = keys[i];
22
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
23
+ get: ((k) => from[k]).bind(null, key),
24
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
25
+ });
26
+ }
27
+ return to;
12
28
  };
13
29
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
-
15
- // src/antfu.ts
16
- var antfu_exports = {};
17
- __reExport(antfu_exports, eslint_config_star);
18
- import * as eslint_config_star from "@antfu/eslint-config";
19
-
20
- // src/defaults.ts
21
- var INLINE_ELEMENTS = [
22
- "a",
23
- "abbr",
24
- "audio",
25
- "b",
26
- "bdi",
27
- "bdo",
28
- "canvas",
29
- "cite",
30
- "code",
31
- "data",
32
- "del",
33
- "dfn",
34
- "em",
35
- "i",
36
- "iframe",
37
- "ins",
38
- "kbd",
39
- "label",
40
- "map",
41
- "mark",
42
- "noscript",
43
- "object",
44
- "output",
45
- "picture",
46
- "q",
47
- "ruby",
48
- "s",
49
- "samp",
50
- "small",
51
- "span",
52
- "strong",
53
- "sub",
54
- "sup",
55
- "svg",
56
- "time",
57
- "u",
58
- "var",
59
- "video"
30
+ //#endregion
31
+ //#region src/antfu.ts
32
+ var antfu_exports = /* @__PURE__ */ __exportAll({});
33
+ import * as import__antfu_eslint_config from "@antfu/eslint-config";
34
+ __reExport(antfu_exports, import__antfu_eslint_config);
35
+ //#endregion
36
+ //#region src/defaults.ts
37
+ const INLINE_ELEMENTS = [
38
+ "a",
39
+ "abbr",
40
+ "audio",
41
+ "b",
42
+ "bdi",
43
+ "bdo",
44
+ "canvas",
45
+ "cite",
46
+ "code",
47
+ "data",
48
+ "del",
49
+ "dfn",
50
+ "em",
51
+ "i",
52
+ "iframe",
53
+ "ins",
54
+ "kbd",
55
+ "label",
56
+ "map",
57
+ "mark",
58
+ "noscript",
59
+ "object",
60
+ "output",
61
+ "picture",
62
+ "q",
63
+ "ruby",
64
+ "s",
65
+ "samp",
66
+ "small",
67
+ "span",
68
+ "strong",
69
+ "sub",
70
+ "sup",
71
+ "svg",
72
+ "time",
73
+ "u",
74
+ "var",
75
+ "video"
60
76
  ];
61
- var nestjsTypeScriptRules = {
62
- "ts/explicit-function-return-type": "off",
63
- "ts/explicit-module-boundary-types": "off",
64
- "ts/no-explicit-any": "off",
65
- "ts/no-parameter-properties": "off",
66
- "ts/no-empty-function": [
67
- "error",
68
- {
69
- allow: [
70
- "decoratedFunctions",
71
- "overrideMethods",
72
- "private-constructors",
73
- "protected-constructors"
74
- ]
75
- }
76
- ],
77
- "ts/no-empty-interface": "off",
78
- "ts/no-namespace": [
79
- "error",
80
- {
81
- allowDeclarations: true,
82
- allowDefinitionFiles: true
83
- }
84
- ],
85
- "ts/ban-types": [
86
- "error",
87
- {
88
- extendDefaults: true,
89
- types: {
90
- Function: false
91
- }
92
- }
93
- ]
77
+ const nestjsTypeScriptRules = {
78
+ "ts/explicit-function-return-type": "off",
79
+ "ts/explicit-module-boundary-types": "off",
80
+ "ts/no-explicit-any": "off",
81
+ "ts/no-parameter-properties": "off",
82
+ "ts/no-empty-function": ["error", { allow: [
83
+ "decoratedFunctions",
84
+ "overrideMethods",
85
+ "private-constructors",
86
+ "protected-constructors"
87
+ ] }],
88
+ "ts/no-empty-interface": "off",
89
+ "ts/no-namespace": ["error", {
90
+ allowDeclarations: true,
91
+ allowDefinitionFiles: true
92
+ }],
93
+ "ts/ban-types": ["error", {
94
+ extendDefaults: true,
95
+ types: { Function: false }
96
+ }]
94
97
  };
95
98
  function getDefaultVueOptions(opts) {
96
- const overrides = {
97
- "vue/attribute-hyphenation": "off",
98
- "vue/v-on-event-hyphenation": "off",
99
- "vue/custom-event-name-casing": "off",
100
- "vue/no-mutating-props": "warn",
101
- // https://eslint.vuejs.org/rules/no-useless-v-bind.html
102
- "vue/no-useless-v-bind": [
103
- "error",
104
- {
105
- // 不允许注释
106
- ignoreIncludesComment: false,
107
- // 允许在里面使用转义
108
- // 比如 v-bind:foo="'bar\nbaz'"
109
- ignoreStringEscape: true
110
- }
111
- ],
112
- // https://eslint.vuejs.org/rules/no-unused-refs.html
113
- "vue/no-unused-refs": "warn"
114
- };
115
- if (opts?.ionic) {
116
- overrides["vue/no-deprecated-slot-attribute"] = "off";
117
- }
118
- if (opts?.weapp) {
119
- overrides["vue/singleline-html-element-content-newline"] = [
120
- "warn",
121
- {
122
- ignoreWhenNoAttributes: true,
123
- ignoreWhenEmpty: true,
124
- ignores: [
125
- // 小程序标签
126
- "text",
127
- ...INLINE_ELEMENTS
128
- ],
129
- externalIgnores: []
130
- }
131
- ];
132
- }
133
- const vueOptions = {
134
- overrides
135
- };
136
- return vueOptions;
99
+ const overrides = {
100
+ "vue/attribute-hyphenation": "off",
101
+ "vue/v-on-event-hyphenation": "off",
102
+ "vue/custom-event-name-casing": "off",
103
+ "vue/no-mutating-props": "warn",
104
+ "vue/no-useless-v-bind": ["error", {
105
+ ignoreIncludesComment: false,
106
+ ignoreStringEscape: true
107
+ }],
108
+ "vue/no-unused-refs": "warn"
109
+ };
110
+ if (opts?.ionic) overrides["vue/no-deprecated-slot-attribute"] = "off";
111
+ if (opts?.weapp) overrides["vue/singleline-html-element-content-newline"] = ["warn", {
112
+ ignoreWhenNoAttributes: true,
113
+ ignoreWhenEmpty: true,
114
+ ignores: ["text", ...INLINE_ELEMENTS],
115
+ externalIgnores: []
116
+ }];
117
+ return { overrides };
137
118
  }
138
119
  function getDefaultTypescriptOptions(opts) {
139
- const overrides = {
140
- "ts/no-unused-vars": [
141
- "error",
142
- {
143
- args: "all",
144
- argsIgnorePattern: "^_",
145
- caughtErrors: "all",
146
- caughtErrorsIgnorePattern: "^_",
147
- destructuredArrayIgnorePattern: "^_",
148
- varsIgnorePattern: "^_",
149
- ignoreRestSiblings: true
150
- }
151
- ],
152
- "ts/prefer-ts-expect-error": "off",
153
- "ts/ban-ts-comment": "off",
154
- "ts/no-use-before-define": "warn",
155
- "ts/no-unused-expressions": [
156
- "error",
157
- {
158
- allowShortCircuit: true,
159
- allowTernary: true
160
- }
161
- ]
162
- };
163
- if (opts?.nestjs) {
164
- Object.assign(overrides, nestjsTypeScriptRules);
165
- }
166
- const typescriptOptions = {
167
- overrides
168
- };
169
- return typescriptOptions;
120
+ const overrides = {
121
+ "ts/no-unused-vars": ["error", {
122
+ args: "all",
123
+ argsIgnorePattern: "^_",
124
+ caughtErrors: "all",
125
+ caughtErrorsIgnorePattern: "^_",
126
+ destructuredArrayIgnorePattern: "^_",
127
+ varsIgnorePattern: "^_",
128
+ ignoreRestSiblings: true
129
+ }],
130
+ "ts/prefer-ts-expect-error": "off",
131
+ "ts/ban-ts-comment": "off",
132
+ "ts/no-use-before-define": "warn",
133
+ "ts/no-unused-expressions": ["error", {
134
+ allowShortCircuit: true,
135
+ allowTernary: true
136
+ }]
137
+ };
138
+ if (opts?.nestjs) Object.assign(overrides, nestjsTypeScriptRules);
139
+ return { overrides };
170
140
  }
171
-
172
- // src/features.ts
141
+ //#endregion
142
+ //#region src/features.ts
173
143
  function resolveTailwindPresets(option) {
174
- if (!option) {
175
- return [];
176
- }
177
- if (typeof option === "object") {
178
- return [
179
- (0, antfu_exports.interopDefault)(
180
- import("eslint-plugin-better-tailwindcss")
181
- ).then((eslintPluginBetterTailwindcss) => {
182
- const betterTailwindcssRules = {
183
- ...eslintPluginBetterTailwindcss.configs["recommended-warn"].rules,
184
- ...eslintPluginBetterTailwindcss.configs["recommended-error"].rules
185
- };
186
- return {
187
- name: "icebreaker/better-tailwindcss",
188
- plugins: {
189
- "better-tailwindcss": eslintPluginBetterTailwindcss
190
- },
191
- rules: betterTailwindcssRules,
192
- settings: {
193
- "better-tailwindcss": {
194
- entryPoint: option.entryPoint,
195
- tailwindConfig: option.tailwindConfig
196
- }
197
- }
198
- };
199
- })
200
- ];
201
- }
202
- return [
203
- // @ts-ignore optional dependency shape
204
- (0, antfu_exports.interopDefault)(
205
- import("eslint-plugin-tailwindcss")
206
- ).then((tailwind) => {
207
- return tailwind.configs["flat/recommended"];
208
- }),
209
- {
210
- rules: {
211
- "tailwindcss/no-custom-classname": "off"
212
- }
213
- }
214
- ];
144
+ if (!option) return [];
145
+ if (typeof option === "object") return [(0, antfu_exports.interopDefault)(import("eslint-plugin-better-tailwindcss")).then((eslintPluginBetterTailwindcss) => {
146
+ const betterTailwindcssRules = {
147
+ ...eslintPluginBetterTailwindcss.configs["recommended-warn"].rules,
148
+ ...eslintPluginBetterTailwindcss.configs["recommended-error"].rules
149
+ };
150
+ return {
151
+ name: "icebreaker/better-tailwindcss",
152
+ plugins: { "better-tailwindcss": eslintPluginBetterTailwindcss },
153
+ rules: betterTailwindcssRules,
154
+ settings: { "better-tailwindcss": {
155
+ entryPoint: option.entryPoint,
156
+ tailwindConfig: option.tailwindConfig
157
+ } }
158
+ };
159
+ })];
160
+ return [(0, antfu_exports.interopDefault)(import("eslint-plugin-tailwindcss")).then((tailwind) => {
161
+ return tailwind.configs["flat/recommended"];
162
+ }), { rules: { "tailwindcss/no-custom-classname": "off" } }];
215
163
  }
216
164
  function resolveMdxPresets(isEnabled) {
217
- if (!isEnabled) {
218
- return [];
219
- }
220
- return [
221
- (0, antfu_exports.interopDefault)(import("eslint-plugin-mdx")).then((mdx) => {
222
- return [
223
- {
224
- ...mdx.flat,
225
- processor: mdx.createRemarkProcessor({
226
- lintCodeBlocks: true,
227
- languageMapper: {}
228
- })
229
- },
230
- {
231
- ...mdx.flatCodeBlocks,
232
- rules: {
233
- ...mdx.flatCodeBlocks.rules
234
- }
235
- }
236
- ];
237
- })
238
- ];
165
+ if (!isEnabled) return [];
166
+ return [(0, antfu_exports.interopDefault)(import("eslint-plugin-mdx")).then((mdx) => {
167
+ return [{
168
+ ...mdx.flat,
169
+ processor: mdx.createRemarkProcessor({
170
+ lintCodeBlocks: true,
171
+ languageMapper: {}
172
+ })
173
+ }, {
174
+ ...mdx.flatCodeBlocks,
175
+ rules: { ...mdx.flatCodeBlocks.rules }
176
+ }];
177
+ })];
239
178
  }
240
179
  function resolveAccessibilityPresets(isEnabled, vueOption, reactOption) {
241
- if (!isEnabled) {
242
- return [];
243
- }
244
- const presets = [];
245
- if (vueOption) {
246
- presets.push(
247
- (0, antfu_exports.interopDefault)(
248
- import("eslint-plugin-vuejs-accessibility")
249
- ).then((pluginVueA11y) => {
250
- return pluginVueA11y.configs["flat/recommended"];
251
- })
252
- );
253
- }
254
- if (reactOption) {
255
- presets.push(
256
- (0, antfu_exports.interopDefault)(
257
- // @ts-ignore optional dependency shape
258
- import("eslint-plugin-jsx-a11y")
259
- ).then((jsxA11y) => {
260
- return jsxA11y.flatConfigs.recommended;
261
- })
262
- );
263
- }
264
- return presets;
180
+ if (!isEnabled) return [];
181
+ const presets = [];
182
+ if (vueOption) presets.push((0, antfu_exports.interopDefault)(import("eslint-plugin-vuejs-accessibility")).then((pluginVueA11y) => {
183
+ return pluginVueA11y.configs["flat/recommended"];
184
+ }));
185
+ if (reactOption) presets.push((0, antfu_exports.interopDefault)(import("eslint-plugin-jsx-a11y")).then((jsxA11y) => {
186
+ return jsxA11y.flatConfigs.recommended;
187
+ }));
188
+ return presets;
265
189
  }
266
190
  function resolveNestPresets(isEnabled) {
267
- if (!isEnabled) {
268
- return [];
269
- }
270
- return [{
271
- name: "icebreaker/nestjs/rules",
272
- rules: nestjsTypeScriptRules
273
- }];
191
+ if (!isEnabled) return [];
192
+ return [{
193
+ name: "icebreaker/nestjs/rules",
194
+ rules: nestjsTypeScriptRules
195
+ }];
274
196
  }
275
197
  function resolveQueryPresets(isEnabled) {
276
- if (!isEnabled) {
277
- return [];
278
- }
279
- return [
280
- (0, antfu_exports.interopDefault)(
281
- import("@tanstack/eslint-plugin-query")
282
- ).then((pluginQuery) => pluginQuery.configs["flat/recommended"])
283
- ];
198
+ if (!isEnabled) return [];
199
+ return [(0, antfu_exports.interopDefault)(import("@tanstack/eslint-plugin-query")).then((pluginQuery) => pluginQuery.configs["flat/recommended"])];
284
200
  }
285
-
286
- // src/options.ts
287
- import fs from "fs";
288
- import { createRequire } from "module";
289
- import path from "path";
290
- import process from "process";
291
-
292
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
201
+ //#endregion
202
+ //#region ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
293
203
  function isPlainObject(value) {
294
- if (value === null || typeof value !== "object") {
295
- return false;
296
- }
297
- const prototype = Object.getPrototypeOf(value);
298
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
299
- return false;
300
- }
301
- if (Symbol.iterator in value) {
302
- return false;
303
- }
304
- if (Symbol.toStringTag in value) {
305
- return Object.prototype.toString.call(value) === "[object Module]";
306
- }
307
- return true;
204
+ if (value === null || typeof value !== "object") return false;
205
+ const prototype = Object.getPrototypeOf(value);
206
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
207
+ if (Symbol.iterator in value) return false;
208
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
209
+ return true;
308
210
  }
309
211
  function _defu(baseObject, defaults, namespace = ".", merger) {
310
- if (!isPlainObject(defaults)) {
311
- return _defu(baseObject, {}, namespace, merger);
312
- }
313
- const object = Object.assign({}, defaults);
314
- for (const key in baseObject) {
315
- if (key === "__proto__" || key === "constructor") {
316
- continue;
317
- }
318
- const value = baseObject[key];
319
- if (value === null || value === void 0) {
320
- continue;
321
- }
322
- if (merger && merger(object, key, value, namespace)) {
323
- continue;
324
- }
325
- if (Array.isArray(value) && Array.isArray(object[key])) {
326
- object[key] = [...value, ...object[key]];
327
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
328
- object[key] = _defu(
329
- value,
330
- object[key],
331
- (namespace ? `${namespace}.` : "") + key.toString(),
332
- merger
333
- );
334
- } else {
335
- object[key] = value;
336
- }
337
- }
338
- return object;
212
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
213
+ const object = Object.assign({}, defaults);
214
+ for (const key in baseObject) {
215
+ if (key === "__proto__" || key === "constructor") continue;
216
+ const value = baseObject[key];
217
+ if (value === null || value === void 0) continue;
218
+ if (merger && merger(object, key, value, namespace)) continue;
219
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
220
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
221
+ else object[key] = value;
222
+ }
223
+ return object;
339
224
  }
340
225
  function createDefu(merger) {
341
- return (...arguments_) => (
342
- // eslint-disable-next-line unicorn/no-array-reduce
343
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
344
- );
226
+ return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
345
227
  }
346
- var defu = createDefu();
347
- var defuFn = createDefu((object, key, currentValue) => {
348
- if (object[key] !== void 0 && typeof currentValue === "function") {
349
- object[key] = currentValue(object[key]);
350
- return true;
351
- }
228
+ const defu = createDefu();
229
+ createDefu((object, key, currentValue) => {
230
+ if (object[key] !== void 0 && typeof currentValue === "function") {
231
+ object[key] = currentValue(object[key]);
232
+ return true;
233
+ }
352
234
  });
353
- var defuArrayFn = createDefu((object, key, currentValue) => {
354
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
355
- object[key] = currentValue(object[key]);
356
- return true;
357
- }
235
+ createDefu((object, key, currentValue) => {
236
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
237
+ object[key] = currentValue(object[key]);
238
+ return true;
239
+ }
358
240
  });
359
-
360
- // src/utils.ts
241
+ //#endregion
242
+ //#region src/utils.ts
361
243
  function isObject(o) {
362
- return Object.prototype.toString.call(o) === "[object Object]";
244
+ return Object.prototype.toString.call(o) === "[object Object]";
363
245
  }
364
-
365
- // src/options.ts
366
- var BASE_DEFAULTS = {
367
- formatters: true,
368
- pnpm: false,
369
- javascript: {
370
- overrides: {
371
- "curly": ["error", "all"],
372
- "no-console": ["warn"]
373
- }
374
- },
375
- test: {
376
- overrides: {
377
- "test/prefer-lowercase-title": ["off"]
378
- }
379
- }
246
+ //#endregion
247
+ //#region src/options.ts
248
+ const BASE_DEFAULTS = {
249
+ formatters: true,
250
+ pnpm: false,
251
+ javascript: { overrides: {
252
+ "curly": ["error", "all"],
253
+ "no-console": ["warn"]
254
+ } },
255
+ test: { overrides: { "test/prefer-lowercase-title": ["off"] } }
380
256
  };
381
- var BASE_RULES = {
382
- // `noPropertyAccessFromIndexSignature` requires bracket access (`obj['key']`)
383
- // for index-signature properties, which conflicts with ESLint core `dot-notation`.
384
- "dot-notation": "off",
385
- // Keep dependency bans visible without blocking CI on upstream preset defaults.
386
- "e18e/ban-dependencies": "warn",
387
- // Disable until upstream fixes false positives on non-array iterables (Set, Map).
388
- // See: [...new Set(arr)].sort() → new Set(arr).toSorted() is invalid.
389
- "e18e/prefer-array-to-sorted": "off",
390
- // Disable all pnpm rules by default
391
- // @antfu/eslint-config auto-enables pnpm plugin when pnpm-workspace.yaml exists
392
- // but we want it opt-in instead of auto-enabled
393
- "pnpm/json-enforce-catalog": "off",
394
- "pnpm/json-prefer-workspace-settings": "off",
395
- "pnpm/json-valid-catalog": "off",
396
- "pnpm/yaml-enforce-settings": "off",
397
- "pnpm/yaml-no-duplicate-catalog-item": "off",
398
- "pnpm/yaml-no-unused-catalog-item": "off",
399
- "unused-imports/no-unused-vars": "off",
400
- "unicorn/prefer-number-properties": "warn"
257
+ const BASE_RULES = {
258
+ "dot-notation": "off",
259
+ "e18e/ban-dependencies": "warn",
260
+ "e18e/prefer-array-to-sorted": "off",
261
+ "pnpm/json-enforce-catalog": "off",
262
+ "pnpm/json-prefer-workspace-settings": "off",
263
+ "pnpm/json-valid-catalog": "off",
264
+ "pnpm/yaml-enforce-settings": "off",
265
+ "pnpm/yaml-no-duplicate-catalog-item": "off",
266
+ "pnpm/yaml-no-unused-catalog-item": "off",
267
+ "unused-imports/no-unused-vars": "off",
268
+ "unicorn/prefer-number-properties": "warn"
401
269
  };
402
- var require2 = createRequire(import.meta.url);
403
- var ANTFU_PACKAGE_DIR = path.dirname(
404
- require2.resolve("@antfu/eslint-config/package.json")
405
- );
406
- var GENERAL_EDITORCONFIG_SECTIONS = /* @__PURE__ */ new Set([
407
- "*",
408
- "**",
409
- "**/*",
410
- "*.*",
411
- "**.*",
412
- "**/*.*"
270
+ const require = createRequire(import.meta.url);
271
+ const ANTFU_PACKAGE_DIR = path.dirname(require.resolve("@antfu/eslint-config/package.json"));
272
+ const GENERAL_EDITORCONFIG_SECTIONS = new Set([
273
+ "*",
274
+ "**",
275
+ "**/*",
276
+ "*.*",
277
+ "**.*",
278
+ "**/*.*"
413
279
  ]);
414
- var NEWLINE_PATTERN = /\r?\n/u;
280
+ const NEWLINE_PATTERN = /\r?\n/u;
415
281
  function mergeOptionWithDefaults(input, defaults, options = {}) {
416
- const { postProcess, useDefaultWhenUndefined = false } = options;
417
- const shouldUseDefaults = input === true || useDefaultWhenUndefined && input === void 0;
418
- if (shouldUseDefaults) {
419
- postProcess?.(defaults);
420
- return defaults;
421
- }
422
- if (isObject(input)) {
423
- const merged = defu(input, defaults);
424
- postProcess?.(merged);
425
- return merged;
426
- }
427
- return input;
282
+ const { postProcess, useDefaultWhenUndefined = false } = options;
283
+ if (input === true || useDefaultWhenUndefined && input === void 0) {
284
+ postProcess?.(defaults);
285
+ return defaults;
286
+ }
287
+ if (isObject(input)) {
288
+ const merged = defu(input, defaults);
289
+ postProcess?.(merged);
290
+ return merged;
291
+ }
292
+ return input;
428
293
  }
429
294
  function applyVueVersionSpecificRules(option) {
430
- if (!option || typeof option !== "object") {
431
- return;
432
- }
433
- const overrides = option.overrides;
434
- if (!overrides) {
435
- return;
436
- }
437
- if (option.vueVersion === 2) {
438
- Object.assign(overrides, {
439
- "vue/no-v-for-template-key-on-child": "off",
440
- "vue/no-v-for-template-key": "error",
441
- "vue/no-deprecated-v-bind-sync": "off"
442
- });
443
- return;
444
- }
445
- Object.assign(overrides, {
446
- "vue/no-v-for-template-key-on-child": "error",
447
- "vue/no-v-for-template-key": "off"
448
- });
295
+ if (!option || typeof option !== "object") return;
296
+ const overrides = option.overrides;
297
+ if (!overrides) return;
298
+ if (option.vueVersion === 2) {
299
+ Object.assign(overrides, {
300
+ "vue/no-v-for-template-key-on-child": "off",
301
+ "vue/no-v-for-template-key": "error",
302
+ "vue/no-deprecated-v-bind-sync": "off"
303
+ });
304
+ return;
305
+ }
306
+ Object.assign(overrides, {
307
+ "vue/no-v-for-template-key-on-child": "error",
308
+ "vue/no-v-for-template-key": "off"
309
+ });
449
310
  }
450
311
  function isPackageAvailable(name, paths) {
451
- try {
452
- require2.resolve(name, paths ? { paths } : void 0);
453
- return true;
454
- } catch {
455
- return false;
456
- }
312
+ try {
313
+ require.resolve(name, paths ? { paths } : void 0);
314
+ return true;
315
+ } catch {
316
+ return false;
317
+ }
457
318
  }
458
319
  function getDefaultFormatterOptions(cwd = process.cwd()) {
459
- const hasXmlPlugin = isPackageAvailable("@prettier/plugin-xml", [ANTFU_PACKAGE_DIR]);
460
- return {
461
- astro: isPackageAvailable("prettier-plugin-astro", [ANTFU_PACKAGE_DIR]),
462
- css: true,
463
- graphql: true,
464
- html: true,
465
- markdown: true,
466
- slidev: isPackageAvailable("@slidev/cli", [cwd]),
467
- svg: hasXmlPlugin,
468
- xml: hasXmlPlugin
469
- };
320
+ const hasXmlPlugin = isPackageAvailable("@prettier/plugin-xml", [ANTFU_PACKAGE_DIR]);
321
+ return {
322
+ astro: isPackageAvailable("prettier-plugin-astro", [ANTFU_PACKAGE_DIR]),
323
+ css: true,
324
+ graphql: true,
325
+ html: true,
326
+ markdown: true,
327
+ slidev: isPackageAvailable("@slidev/cli", [cwd]),
328
+ svg: hasXmlPlugin,
329
+ xml: hasXmlPlugin
330
+ };
470
331
  }
471
332
  function normalizeEditorConfigEndOfLine(value) {
472
- switch (value.trim().toLowerCase()) {
473
- case "cr":
474
- case "crlf":
475
- case "lf":
476
- return value.trim().toLowerCase();
477
- default:
478
- return void 0;
479
- }
333
+ switch (value.trim().toLowerCase()) {
334
+ case "cr":
335
+ case "crlf":
336
+ case "lf": return value.trim().toLowerCase();
337
+ default: return;
338
+ }
480
339
  }
481
340
  function isGeneralEditorConfigSection(section) {
482
- return GENERAL_EDITORCONFIG_SECTIONS.has(section.trim());
341
+ return GENERAL_EDITORCONFIG_SECTIONS.has(section.trim());
483
342
  }
484
343
  function parseEditorConfig(filePath) {
485
- const lines = fs.readFileSync(filePath, "utf8").split(NEWLINE_PATTERN);
486
- let currentSection;
487
- let endOfLine;
488
- let isRoot = false;
489
- for (const rawLine of lines) {
490
- const line = rawLine.trim();
491
- if (!line || line.startsWith("#") || line.startsWith(";")) {
492
- continue;
493
- }
494
- if (line.startsWith("[") && line.endsWith("]")) {
495
- currentSection = line.slice(1, -1).trim();
496
- continue;
497
- }
498
- const separatorIndex = line.indexOf("=");
499
- if (separatorIndex === -1) {
500
- continue;
501
- }
502
- const key = line.slice(0, separatorIndex).trim().toLowerCase();
503
- const value = line.slice(separatorIndex + 1).trim();
504
- if (!currentSection && key === "root") {
505
- isRoot = value.toLowerCase() === "true";
506
- continue;
507
- }
508
- if (key !== "end_of_line") {
509
- continue;
510
- }
511
- const normalized = normalizeEditorConfigEndOfLine(value);
512
- if (!normalized) {
513
- continue;
514
- }
515
- if (!currentSection || isGeneralEditorConfigSection(currentSection)) {
516
- endOfLine = normalized;
517
- }
518
- }
519
- return endOfLine ? {
520
- endOfLine,
521
- isRoot
522
- } : {
523
- isRoot
524
- };
344
+ const lines = fs.readFileSync(filePath, "utf8").split(NEWLINE_PATTERN);
345
+ let currentSection;
346
+ let endOfLine;
347
+ let isRoot = false;
348
+ for (const rawLine of lines) {
349
+ const line = rawLine.trim();
350
+ if (!line || line.startsWith("#") || line.startsWith(";")) continue;
351
+ if (line.startsWith("[") && line.endsWith("]")) {
352
+ currentSection = line.slice(1, -1).trim();
353
+ continue;
354
+ }
355
+ const separatorIndex = line.indexOf("=");
356
+ if (separatorIndex === -1) continue;
357
+ const key = line.slice(0, separatorIndex).trim().toLowerCase();
358
+ const value = line.slice(separatorIndex + 1).trim();
359
+ if (!currentSection && key === "root") {
360
+ isRoot = value.toLowerCase() === "true";
361
+ continue;
362
+ }
363
+ if (key !== "end_of_line") continue;
364
+ const normalized = normalizeEditorConfigEndOfLine(value);
365
+ if (!normalized) continue;
366
+ if (!currentSection || isGeneralEditorConfigSection(currentSection)) endOfLine = normalized;
367
+ }
368
+ return endOfLine ? {
369
+ endOfLine,
370
+ isRoot
371
+ } : { isRoot };
525
372
  }
526
373
  function inferPrettierEndOfLineFromEditorConfig(cwd = process.cwd()) {
527
- const configs = [];
528
- let currentDir = path.resolve(cwd);
529
- while (true) {
530
- const editorConfigPath = path.join(currentDir, ".editorconfig");
531
- if (fs.existsSync(editorConfigPath)) {
532
- configs.push(editorConfigPath);
533
- if (parseEditorConfig(editorConfigPath).isRoot) {
534
- break;
535
- }
536
- }
537
- const parentDir = path.dirname(currentDir);
538
- if (parentDir === currentDir) {
539
- break;
540
- }
541
- currentDir = parentDir;
542
- }
543
- let endOfLine;
544
- for (const filePath of configs.reverse()) {
545
- const parsed = parseEditorConfig(filePath);
546
- if (parsed.endOfLine) {
547
- endOfLine = parsed.endOfLine;
548
- }
549
- }
550
- return endOfLine;
374
+ const configs = [];
375
+ let currentDir = path.resolve(cwd);
376
+ while (true) {
377
+ const editorConfigPath = path.join(currentDir, ".editorconfig");
378
+ if (fs.existsSync(editorConfigPath)) {
379
+ configs.push(editorConfigPath);
380
+ if (parseEditorConfig(editorConfigPath).isRoot) break;
381
+ }
382
+ const parentDir = path.dirname(currentDir);
383
+ if (parentDir === currentDir) break;
384
+ currentDir = parentDir;
385
+ }
386
+ let endOfLine;
387
+ for (const filePath of configs.reverse()) {
388
+ const parsed = parseEditorConfig(filePath);
389
+ if (parsed.endOfLine) endOfLine = parsed.endOfLine;
390
+ }
391
+ return endOfLine;
551
392
  }
552
393
  function resolveFormattersOption(input, cwd = process.cwd()) {
553
- if (input === false) {
554
- return false;
555
- }
556
- const defaults = getDefaultFormatterOptions(cwd);
557
- const inferredEndOfLine = inferPrettierEndOfLineFromEditorConfig(cwd);
558
- const defaultsWithPrettier = inferredEndOfLine ? defu(
559
- {
560
- prettierOptions: {
561
- endOfLine: inferredEndOfLine
562
- }
563
- },
564
- defaults
565
- ) : defaults;
566
- if (input === void 0) {
567
- return inferredEndOfLine ? defaultsWithPrettier : true;
568
- }
569
- if (input === true) {
570
- return defaultsWithPrettier;
571
- }
572
- if (isObject(input)) {
573
- return defu(input, defaultsWithPrettier);
574
- }
575
- return defaultsWithPrettier;
394
+ if (input === false) return false;
395
+ const defaults = getDefaultFormatterOptions(cwd);
396
+ const inferredEndOfLine = inferPrettierEndOfLineFromEditorConfig(cwd);
397
+ const defaultsWithPrettier = inferredEndOfLine ? defu({ prettierOptions: { endOfLine: inferredEndOfLine } }, defaults) : defaults;
398
+ if (input === void 0) return inferredEndOfLine ? defaultsWithPrettier : true;
399
+ if (input === true) return defaultsWithPrettier;
400
+ if (isObject(input)) return defu(input, defaultsWithPrettier);
401
+ return defaultsWithPrettier;
576
402
  }
577
403
  function resolveUserOptions(options) {
578
- const resolved = defu(
579
- {},
580
- options ?? {},
581
- BASE_DEFAULTS
582
- );
583
- const resolvedVue = mergeOptionWithDefaults(
584
- resolved.vue,
585
- getDefaultVueOptions(options),
586
- {
587
- postProcess: applyVueVersionSpecificRules
588
- }
589
- );
590
- if (resolvedVue === void 0) {
591
- delete resolved.vue;
592
- } else {
593
- resolved.vue = resolvedVue;
594
- }
595
- const resolvedTypescript = mergeOptionWithDefaults(
596
- resolved.typescript,
597
- getDefaultTypescriptOptions(options),
598
- {
599
- useDefaultWhenUndefined: true
600
- }
601
- );
602
- if (resolvedTypescript === void 0) {
603
- delete resolved.typescript;
604
- } else {
605
- resolved.typescript = resolvedTypescript;
606
- }
607
- resolved.formatters = resolveFormattersOption(options?.formatters);
608
- return resolved;
404
+ const resolved = defu({}, options ?? {}, BASE_DEFAULTS);
405
+ const resolvedVue = mergeOptionWithDefaults(resolved.vue, getDefaultVueOptions(options), { postProcess: applyVueVersionSpecificRules });
406
+ if (resolvedVue === void 0) delete resolved.vue;
407
+ else resolved.vue = resolvedVue;
408
+ const resolvedTypescript = mergeOptionWithDefaults(resolved.typescript, getDefaultTypescriptOptions(options), { useDefaultWhenUndefined: true });
409
+ if (resolvedTypescript === void 0) delete resolved.typescript;
410
+ else resolved.typescript = resolvedTypescript;
411
+ resolved.formatters = resolveFormattersOption(options?.formatters);
412
+ return resolved;
609
413
  }
610
414
  function createBaseRuleSet(isLegacy) {
611
- if (!isLegacy) {
612
- return BASE_RULES;
613
- }
614
- return {
615
- ...BASE_RULES,
616
- "perfectionist/sort-imports": "off"
617
- };
415
+ if (!isLegacy) return BASE_RULES;
416
+ return {
417
+ ...BASE_RULES,
418
+ "perfectionist/sort-imports": "off"
419
+ };
618
420
  }
619
-
620
- // src/preset.ts
421
+ //#endregion
422
+ //#region src/preset.ts
621
423
  function getPresets(options, mode) {
622
- const resolved = resolveUserOptions(options);
623
- const presets = [
624
- {
625
- rules: createBaseRuleSet(mode === "legacy")
626
- }
627
- ];
628
- presets.push(
629
- ...resolveTailwindPresets(resolved.tailwindcss),
630
- ...resolveMdxPresets(resolved.mdx),
631
- ...resolveNestPresets(resolved.nestjs),
632
- ...resolveQueryPresets(resolved.query),
633
- ...resolveAccessibilityPresets(resolved.a11y, resolved.vue, resolved.react)
634
- );
635
- return [resolved, ...presets];
424
+ const resolved = resolveUserOptions(options);
425
+ const presets = [{ rules: createBaseRuleSet(mode === "legacy") }];
426
+ presets.push(...resolveTailwindPresets(resolved.tailwindcss), ...resolveMdxPresets(resolved.mdx), ...resolveNestPresets(resolved.nestjs), ...resolveQueryPresets(resolved.query), ...resolveAccessibilityPresets(resolved.a11y, resolved.vue, resolved.react));
427
+ return [resolved, ...presets];
636
428
  }
637
-
638
- // src/factory.ts
429
+ //#endregion
430
+ //#region src/factory.ts
639
431
  function icebreaker(options = {}, ...userConfigs) {
640
- return (0, antfu_exports.antfu)(...getPresets(options), ...userConfigs);
432
+ return (0, antfu_exports.antfu)(...getPresets(options), ...userConfigs);
641
433
  }
642
434
  function icebreakerLegacy(options = {}, ...userConfigs) {
643
- return (0, antfu_exports.antfu)(...getPresets(options, "legacy"), ...userConfigs);
435
+ return (0, antfu_exports.antfu)(...getPresets(options, "legacy"), ...userConfigs);
644
436
  }
645
- export {
646
- getPresets,
647
- icebreaker,
648
- icebreakerLegacy
649
- };
437
+ //#endregion
438
+ export { getPresets, icebreaker, icebreakerLegacy };