@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.cjs +384 -613
- package/dist/index.d.cts +2947 -38
- package/dist/index.d.ts +2947 -38
- package/dist/index.js +374 -585
- package/index.d.ts +54 -0
- package/package.json +15 -15
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
var antfu_exports = {};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/features.ts
|
|
173
143
|
function resolveTailwindPresets(option) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
277
|
-
|
|
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
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/utils.ts
|
|
361
243
|
function isObject(o) {
|
|
362
|
-
|
|
244
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
363
245
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
280
|
+
const NEWLINE_PATTERN = /\r?\n/u;
|
|
415
281
|
function mergeOptionWithDefaults(input, defaults, options = {}) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
341
|
+
return GENERAL_EDITORCONFIG_SECTIONS.has(section.trim());
|
|
483
342
|
}
|
|
484
343
|
function parseEditorConfig(filePath) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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
|
-
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/preset.ts
|
|
621
423
|
function getPresets(options, mode) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/factory.ts
|
|
639
431
|
function icebreaker(options = {}, ...userConfigs) {
|
|
640
|
-
|
|
432
|
+
return (0, antfu_exports.antfu)(...getPresets(options), ...userConfigs);
|
|
641
433
|
}
|
|
642
434
|
function icebreakerLegacy(options = {}, ...userConfigs) {
|
|
643
|
-
|
|
435
|
+
return (0, antfu_exports.antfu)(...getPresets(options, "legacy"), ...userConfigs);
|
|
644
436
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
icebreaker,
|
|
648
|
-
icebreakerLegacy
|
|
649
|
-
};
|
|
437
|
+
//#endregion
|
|
438
|
+
export { getPresets, icebreaker, icebreakerLegacy };
|