@siberiacancode/eslint 2.15.2 → 2.16.0
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/cjs/index.cjs +577 -194
- package/dist/cjs/index.d.cts +13 -0
- package/dist/esm/index.d.mts +13 -0
- package/dist/esm/index.mjs +540 -191
- package/package.json +20 -17
- package/dist/types/index.d.ts +0 -10
package/dist/esm/index.mjs
CHANGED
|
@@ -1,195 +1,544 @@
|
|
|
1
1
|
import antfu from "@antfu/eslint-config";
|
|
2
|
-
import
|
|
2
|
+
import pluginCss from "@eslint/css";
|
|
3
3
|
import pluginJsxA11y from "eslint-plugin-jsx-a11y";
|
|
4
|
-
import
|
|
4
|
+
import pluginPlaywright from "eslint-plugin-playwright";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region src/plugin/rules/function-component-definition.ts
|
|
9
|
+
const NAMED_TEMPLATES = {
|
|
10
|
+
"function-declaration": "function {name}{typeParams}({params}){returnType} {body}",
|
|
11
|
+
"arrow-function": "{varType} {name}{typeAnnotation} = {typeParams}({params}){returnType} => {body}",
|
|
12
|
+
"function-expression": "{varType} {name}{typeAnnotation} = function{typeParams}({params}){returnType} {body}"
|
|
13
|
+
};
|
|
14
|
+
const buildFunction = (template, parts) => Object.keys(parts).reduce((acc, key) => acc.replace(new RegExp(`\\{${key}\\}`, "g"), () => parts[key] ?? ""), template);
|
|
15
|
+
const hasName = (node) => {
|
|
16
|
+
if (node.type === "FunctionDeclaration") return true;
|
|
17
|
+
return node.parent?.type === "VariableDeclarator";
|
|
18
|
+
};
|
|
19
|
+
const getName = (node) => {
|
|
20
|
+
if (node.type === "FunctionDeclaration" && node.id?.type === "Identifier") return node.id.name;
|
|
21
|
+
const parent = node.parent;
|
|
22
|
+
if ((node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") && parent?.type === "VariableDeclarator" && parent.id?.type === "Identifier") return parent.id.name;
|
|
23
|
+
};
|
|
24
|
+
const getTypeParams = (node) => {
|
|
25
|
+
return node.typeParameters;
|
|
26
|
+
};
|
|
27
|
+
const getNodeText = (sourceCode, node) => {
|
|
28
|
+
if (!node || !("range" in node) || !node.range) return void 0;
|
|
29
|
+
return sourceCode.getText(node);
|
|
30
|
+
};
|
|
31
|
+
const getParams = (sourceCode, node) => {
|
|
32
|
+
if (node.params.length === 0) return void 0;
|
|
33
|
+
const first = node.params[0];
|
|
34
|
+
const last = node.params[node.params.length - 1];
|
|
35
|
+
if (first == null || last == null || !("range" in first) || !("range" in last)) return void 0;
|
|
36
|
+
return sourceCode.getText({ range: [first.range[0], last.range[1]] });
|
|
37
|
+
};
|
|
38
|
+
const getBody = (sourceCode, node) => {
|
|
39
|
+
const body = node.body;
|
|
40
|
+
if (!("range" in body) || !body.range) return "{}";
|
|
41
|
+
const text = sourceCode.getText(body);
|
|
42
|
+
if (body.type === "BlockStatement") return text;
|
|
43
|
+
return `{\n return ${text}\n}`;
|
|
44
|
+
};
|
|
45
|
+
const getTypeAnnotation = (sourceCode, node) => {
|
|
46
|
+
if (!hasName(node) || node.type === "FunctionDeclaration") return void 0;
|
|
47
|
+
const parent = node.parent;
|
|
48
|
+
if (parent?.type !== "VariableDeclarator" || parent.id?.type !== "Identifier") return void 0;
|
|
49
|
+
const id = parent.id;
|
|
50
|
+
if (!("typeAnnotation" in id) || id.typeAnnotation === void 0 || id.typeAnnotation === null) return void 0;
|
|
51
|
+
return getNodeText(sourceCode, id.typeAnnotation);
|
|
52
|
+
};
|
|
53
|
+
const isUnfixableExport = (node) => node.type === "FunctionDeclaration" && node.parent?.type === "ExportDefaultDeclaration";
|
|
54
|
+
const isFunctionExpressionWithName = (node) => node.type === "FunctionExpression" && "id" in node && node.id !== null && node.id !== void 0;
|
|
55
|
+
const JSX_TYPES = ["JSXElement", "JSXFragment"];
|
|
56
|
+
/** Walk AST and return true if any descendant is JSX */
|
|
57
|
+
const containsJSX = (node) => {
|
|
58
|
+
if (JSX_TYPES.includes(node.type)) return true;
|
|
59
|
+
for (const key of Object.keys(node)) {
|
|
60
|
+
if (key === "parent") continue;
|
|
61
|
+
const value = node[key];
|
|
62
|
+
if (value !== null && value !== void 0 && typeof value === "object") {
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
if (value.some((child) => child !== null && child !== void 0 && typeof child === "object" && "type" in child && containsJSX(child))) return true;
|
|
65
|
+
} else if (value !== null && value !== void 0 && typeof value === "object" && "type" in value && containsJSX(value)) return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
const walk = (node, visit) => {
|
|
71
|
+
visit(node);
|
|
72
|
+
for (const key of Object.keys(node)) {
|
|
73
|
+
if (key === "parent") continue;
|
|
74
|
+
const value = node[key];
|
|
75
|
+
if (value !== null && value !== void 0 && typeof value === "object") {
|
|
76
|
+
if (Array.isArray(value)) value.forEach((child) => {
|
|
77
|
+
if (child !== null && child !== void 0 && typeof child === "object" && "type" in child) walk(child, visit);
|
|
78
|
+
});
|
|
79
|
+
else if (value !== null && value !== void 0 && typeof value === "object" && "type" in value) walk(value, visit);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/** Collect component nodes: functions that contain JSX (and for expr/arrow, are in VariableDeclarator) */
|
|
84
|
+
const getComponentNodes = (program) => {
|
|
85
|
+
const components = /* @__PURE__ */ new Set();
|
|
86
|
+
let fileHasJSX = false;
|
|
87
|
+
walk(program, (n) => {
|
|
88
|
+
const type = n.type;
|
|
89
|
+
if (type === "JSXElement" || type === "JSXFragment") fileHasJSX = true;
|
|
90
|
+
});
|
|
91
|
+
if (!fileHasJSX) return components;
|
|
92
|
+
walk(program, (n) => {
|
|
93
|
+
if (n.type === "FunctionDeclaration" && containsJSX(n)) components.add(n);
|
|
94
|
+
const withParent = n;
|
|
95
|
+
if ((n.type === "ArrowFunctionExpression" || n.type === "FunctionExpression") && withParent.parent?.type === "VariableDeclarator" && containsJSX(n)) components.add(n);
|
|
96
|
+
});
|
|
97
|
+
return components;
|
|
98
|
+
};
|
|
99
|
+
const functionComponentDefinition = {
|
|
100
|
+
meta: {
|
|
101
|
+
type: "layout",
|
|
102
|
+
docs: { description: "Enforce a specific function type for function components" },
|
|
103
|
+
fixable: "code",
|
|
104
|
+
schema: [{
|
|
105
|
+
type: "object",
|
|
106
|
+
properties: { namedComponents: { anyOf: [{ enum: [
|
|
107
|
+
"function-declaration",
|
|
108
|
+
"arrow-function",
|
|
109
|
+
"function-expression"
|
|
110
|
+
] }, {
|
|
111
|
+
type: "array",
|
|
112
|
+
items: {
|
|
113
|
+
type: "string",
|
|
114
|
+
enum: [
|
|
115
|
+
"function-declaration",
|
|
116
|
+
"arrow-function",
|
|
117
|
+
"function-expression"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}] } },
|
|
121
|
+
additionalProperties: false
|
|
122
|
+
}],
|
|
123
|
+
messages: {
|
|
124
|
+
"function-declaration": "Function component is not a function declaration",
|
|
125
|
+
"function-expression": "Function component is not a function expression",
|
|
126
|
+
"arrow-function": "Function component is not an arrow function"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
create(context) {
|
|
130
|
+
const sourceCode = context.sourceCode;
|
|
131
|
+
const options = context.options[0] ?? {};
|
|
132
|
+
const namedConfig = [].concat(options.namedComponents ?? "function-declaration");
|
|
133
|
+
let fileVarType = "var";
|
|
134
|
+
const validatePairs = [];
|
|
135
|
+
let componentNodes = /* @__PURE__ */ new Set();
|
|
136
|
+
const getFixer = (node, fixOptions) => {
|
|
137
|
+
const typeAnnotation = getTypeAnnotation(sourceCode, node);
|
|
138
|
+
if (fixOptions.type === "function-declaration" && typeAnnotation) return void 0;
|
|
139
|
+
if (isUnfixableExport(node)) return void 0;
|
|
140
|
+
if (isFunctionExpressionWithName(node)) return void 0;
|
|
141
|
+
let varType = fileVarType;
|
|
142
|
+
const parent = node.parent;
|
|
143
|
+
if ((node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && parent?.type === "VariableDeclarator" && parent.parent?.type === "VariableDeclaration") varType = parent.parent.kind;
|
|
144
|
+
const typeParams = getNodeText(sourceCode, getTypeParams(node));
|
|
145
|
+
const params = getParams(sourceCode, node);
|
|
146
|
+
const returnType = getNodeText(sourceCode, "returnType" in node ? node.returnType : void 0);
|
|
147
|
+
const body = getBody(sourceCode, node);
|
|
148
|
+
const name = getName(node);
|
|
149
|
+
const text = buildFunction(fixOptions.template, {
|
|
150
|
+
typeAnnotation,
|
|
151
|
+
typeParams,
|
|
152
|
+
params,
|
|
153
|
+
returnType,
|
|
154
|
+
body,
|
|
155
|
+
name: name !== void 0 && name !== null && name !== "" ? name : "",
|
|
156
|
+
varType
|
|
157
|
+
});
|
|
158
|
+
return (fixer) => fixer.replaceTextRange(fixOptions.range, text);
|
|
159
|
+
};
|
|
160
|
+
const report = (node, fixOptions) => {
|
|
161
|
+
const fix = getFixer(node, fixOptions);
|
|
162
|
+
context.report({
|
|
163
|
+
node,
|
|
164
|
+
messageId: fixOptions.messageId,
|
|
165
|
+
fix
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const validate = (node, functionType) => {
|
|
169
|
+
if (!componentNodes.has(node)) return;
|
|
170
|
+
if (node.parent?.type === "Property") return;
|
|
171
|
+
if (hasName(node) && !namedConfig.includes(functionType)) {
|
|
172
|
+
const parent = node.parent;
|
|
173
|
+
report(node, {
|
|
174
|
+
messageId: namedConfig[0],
|
|
175
|
+
type: namedConfig[0],
|
|
176
|
+
template: NAMED_TEMPLATES[namedConfig[0]],
|
|
177
|
+
range: node.type === "FunctionDeclaration" ? node.range : parent?.parent?.range ?? node.range
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
Program(programNode) {
|
|
183
|
+
componentNodes = getComponentNodes(programNode);
|
|
184
|
+
},
|
|
185
|
+
FunctionDeclaration(node) {
|
|
186
|
+
validatePairs.push([node, "function-declaration"]);
|
|
187
|
+
},
|
|
188
|
+
ArrowFunctionExpression(node) {
|
|
189
|
+
validatePairs.push([node, "arrow-function"]);
|
|
190
|
+
},
|
|
191
|
+
FunctionExpression(node) {
|
|
192
|
+
validatePairs.push([node, "function-expression"]);
|
|
193
|
+
},
|
|
194
|
+
VariableDeclaration(node) {
|
|
195
|
+
if (node.kind === "const" || node.kind === "let") fileVarType = "const";
|
|
196
|
+
},
|
|
197
|
+
"Program:exit": function() {
|
|
198
|
+
if (fileVarType === "var") {
|
|
199
|
+
if (validatePairs.some(([n]) => n.parent?.type === "VariableDeclarator") || componentNodes.size > 0 && validatePairs.length > 0) fileVarType = "const";
|
|
200
|
+
}
|
|
201
|
+
validatePairs.forEach(([node, type]) => validate(node, type));
|
|
202
|
+
},
|
|
203
|
+
ImportDeclaration: () => {
|
|
204
|
+
fileVarType = "const";
|
|
205
|
+
},
|
|
206
|
+
ExportNamedDeclaration: () => {
|
|
207
|
+
fileVarType = "const";
|
|
208
|
+
},
|
|
209
|
+
ExportDefaultDeclaration: () => {
|
|
210
|
+
fileVarType = "const";
|
|
211
|
+
},
|
|
212
|
+
JSXElement: () => {
|
|
213
|
+
fileVarType = "const";
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/plugin/rules/no-unused-class.ts
|
|
221
|
+
const STYLE_IMPORT_REGEXP = /\.(?:css|scss|less)$/u;
|
|
222
|
+
const toCamelCase = (value) => value.replace(/-([a-z])/gu, (_substring, letter) => letter.toUpperCase());
|
|
223
|
+
const extractClassNames = (source) => {
|
|
224
|
+
const classNames = /* @__PURE__ */ new Set();
|
|
225
|
+
const classNameRegExp = /\.([_a-zA-Z][\w-]*)/gu;
|
|
226
|
+
let match = classNameRegExp.exec(source);
|
|
227
|
+
while (match !== null) {
|
|
228
|
+
const className = match[1];
|
|
229
|
+
if (className !== void 0 && className !== "") classNames.add(className);
|
|
230
|
+
match = classNameRegExp.exec(source);
|
|
231
|
+
}
|
|
232
|
+
return [...classNames];
|
|
233
|
+
};
|
|
234
|
+
const buildClassesMap = (classNames, camelCaseOption) => {
|
|
235
|
+
const onlyCamelCase = camelCaseOption === "only" || camelCaseOption === "dashes-only";
|
|
236
|
+
const withCamelCase = camelCaseOption === true || camelCaseOption === "dashes" || onlyCamelCase;
|
|
237
|
+
const classesMap = {};
|
|
238
|
+
classNames.forEach((className) => {
|
|
239
|
+
if (!onlyCamelCase) classesMap[className] = className;
|
|
240
|
+
if (withCamelCase) classesMap[toCamelCase(className)] = className;
|
|
241
|
+
});
|
|
242
|
+
return classesMap;
|
|
243
|
+
};
|
|
244
|
+
const getStyleImportData = (node) => {
|
|
245
|
+
if (node.source.type !== "Literal" || typeof node.source.value !== "string") return void 0;
|
|
246
|
+
const source = node.source.value;
|
|
247
|
+
if (!STYLE_IMPORT_REGEXP.test(source)) return void 0;
|
|
248
|
+
const importSpecifier = node.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportNamespaceSpecifier");
|
|
249
|
+
if (importSpecifier === void 0) return void 0;
|
|
250
|
+
return {
|
|
251
|
+
importName: importSpecifier.local.name,
|
|
252
|
+
importNode: importSpecifier,
|
|
253
|
+
styleFilePath: source
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
const getPropertyName = (node, camelCaseOption) => {
|
|
257
|
+
if (node.computed === false && node.property.type === "Identifier") return node.property.name;
|
|
258
|
+
if (node.computed === true && node.property.type === "Literal") {
|
|
259
|
+
if (typeof node.property.value !== "string" || node.property.value === "") return void 0;
|
|
260
|
+
return camelCaseOption === "only" ? toCamelCase(node.property.value) : node.property.value;
|
|
261
|
+
}
|
|
262
|
+
if (node.computed === true && node.property.type === "TemplateLiteral" && node.property.expressions.length === 0) {
|
|
263
|
+
const value = node.property.quasis[0]?.value.cooked;
|
|
264
|
+
if (typeof value !== "string" || value === "") return void 0;
|
|
265
|
+
return camelCaseOption === "only" ? toCamelCase(value) : value;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const getAbsoluteStylePath = (context, styleFilePath) => {
|
|
269
|
+
const filename = context.filename;
|
|
270
|
+
if (filename === "<input>") return void 0;
|
|
271
|
+
return path.resolve(path.dirname(filename), styleFilePath);
|
|
272
|
+
};
|
|
273
|
+
const noUnusedClass = {
|
|
274
|
+
meta: {
|
|
275
|
+
type: "problem",
|
|
276
|
+
docs: { description: "Checks that all CSS/SCSS/LESS classes imported as modules are used" },
|
|
277
|
+
schema: [{
|
|
278
|
+
type: "object",
|
|
279
|
+
properties: {
|
|
280
|
+
camelCase: { enum: [
|
|
281
|
+
true,
|
|
282
|
+
"dashes",
|
|
283
|
+
"only",
|
|
284
|
+
"dashes-only"
|
|
285
|
+
] },
|
|
286
|
+
markAsUsed: {
|
|
287
|
+
type: "array",
|
|
288
|
+
items: { type: "string" }
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
additionalProperties: false
|
|
292
|
+
}]
|
|
293
|
+
},
|
|
294
|
+
create(context) {
|
|
295
|
+
const options = context.options[0] ?? {};
|
|
296
|
+
const camelCaseOption = options.camelCase;
|
|
297
|
+
const markAsUsed = options.markAsUsed ?? [];
|
|
298
|
+
const importMap = {};
|
|
299
|
+
return {
|
|
300
|
+
ImportDeclaration(node) {
|
|
301
|
+
const styleImportData = getStyleImportData(node);
|
|
302
|
+
if (styleImportData === void 0) return;
|
|
303
|
+
const absoluteStylePath = getAbsoluteStylePath(context, styleImportData.styleFilePath);
|
|
304
|
+
if (absoluteStylePath === void 0 || !fs.existsSync(absoluteStylePath)) return;
|
|
305
|
+
const classNames = extractClassNames(fs.readFileSync(absoluteStylePath, "utf8"));
|
|
306
|
+
const classes = {};
|
|
307
|
+
classNames.forEach((className) => {
|
|
308
|
+
classes[className] = false;
|
|
309
|
+
});
|
|
310
|
+
importMap[styleImportData.importName] = {
|
|
311
|
+
classes,
|
|
312
|
+
classesMap: buildClassesMap(classNames, camelCaseOption),
|
|
313
|
+
filePath: styleImportData.styleFilePath,
|
|
314
|
+
node: styleImportData.importNode
|
|
315
|
+
};
|
|
316
|
+
},
|
|
317
|
+
MemberExpression(node) {
|
|
318
|
+
const typedNode = node;
|
|
319
|
+
if (typedNode.object.type !== "Identifier") return;
|
|
320
|
+
const entry = importMap[typedNode.object.name];
|
|
321
|
+
if (entry === void 0) return;
|
|
322
|
+
const propertyName = getPropertyName(typedNode, camelCaseOption);
|
|
323
|
+
if (propertyName === void 0 || propertyName === "") return;
|
|
324
|
+
const className = entry.classesMap[propertyName];
|
|
325
|
+
if (className === void 0 || className === "") return;
|
|
326
|
+
entry.classes[className] = true;
|
|
327
|
+
},
|
|
328
|
+
"Program:exit": () => {
|
|
329
|
+
Object.values(importMap).forEach((entry) => {
|
|
330
|
+
markAsUsed.forEach((usedClass) => {
|
|
331
|
+
if (usedClass !== "") entry.classes[usedClass] = true;
|
|
332
|
+
});
|
|
333
|
+
const unusedClasses = Object.entries(entry.classes).filter(([, used]) => used === false).map(([className]) => className);
|
|
334
|
+
if (unusedClasses.length > 0) context.report({
|
|
335
|
+
node: entry.node,
|
|
336
|
+
message: `Unused classes found in ${path.basename(entry.filePath)}: ${unusedClasses.join(", ")}`
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/plugin/index.ts
|
|
346
|
+
const version = "1.0.0";
|
|
347
|
+
const siberiacancodePlugin = {
|
|
348
|
+
meta: {
|
|
349
|
+
name: "@siberiacancode/eslint-plugin",
|
|
350
|
+
version
|
|
351
|
+
},
|
|
352
|
+
rules: {
|
|
353
|
+
"function-component-definition": functionComponentDefinition,
|
|
354
|
+
"no-unused-class": noUnusedClass
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/index.ts
|
|
360
|
+
const getDefaultTypescriptConfig = (option) => {
|
|
361
|
+
if (typeof option === "object") return option;
|
|
362
|
+
if (option === true && fs.existsSync("./tsconfig.json")) return { tsconfigPath: "./tsconfig.json" };
|
|
363
|
+
return option;
|
|
364
|
+
};
|
|
5
365
|
const eslint = (inputOptions = {}, ...configs) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"nullish"
|
|
182
|
-
],
|
|
183
|
-
order: "asc",
|
|
184
|
-
specialCharacters: "keep",
|
|
185
|
-
type: "alphabetical"
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
...configs
|
|
191
|
-
);
|
|
192
|
-
};
|
|
193
|
-
export {
|
|
194
|
-
eslint
|
|
366
|
+
const { jsxA11y = false, playwright = false, ...options } = inputOptions;
|
|
367
|
+
const typescript = getDefaultTypescriptConfig(options?.typescript ?? false);
|
|
368
|
+
const stylistic = options?.stylistic ?? false;
|
|
369
|
+
if (jsxA11y) {
|
|
370
|
+
const jsxA11yRules = pluginJsxA11y.flatConfigs.recommended.rules;
|
|
371
|
+
configs.unshift({
|
|
372
|
+
name: "siberiacancode/jsx-a11y",
|
|
373
|
+
plugins: { "siberiacancode-jsx-a11y": pluginJsxA11y },
|
|
374
|
+
rules: { ...Object.entries(jsxA11yRules).reduce((acc, [key, value]) => {
|
|
375
|
+
acc[key.replace("jsx-a11y", "siberiacancode-jsx-a11y")] = value;
|
|
376
|
+
return acc;
|
|
377
|
+
}, {}) }
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (playwright) {
|
|
381
|
+
const playwrightRules = pluginPlaywright.configs["flat/recommended"].rules;
|
|
382
|
+
configs.unshift({
|
|
383
|
+
name: "siberiacancode/playwright",
|
|
384
|
+
plugins: { "siberiacancode-playwright": pluginPlaywright },
|
|
385
|
+
rules: { ...Object.entries(playwrightRules).reduce((acc, [key, value]) => {
|
|
386
|
+
acc[key.replace("playwright", "siberiacancode-playwright")] = value;
|
|
387
|
+
return acc;
|
|
388
|
+
}, {}) }
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (stylistic) configs.unshift({
|
|
392
|
+
name: "siberiacancode/formatter",
|
|
393
|
+
rules: {
|
|
394
|
+
"style/arrow-parens": ["error", "always"],
|
|
395
|
+
"style/brace-style": "off",
|
|
396
|
+
"style/comma-dangle": ["error", "never"],
|
|
397
|
+
"style/indent": [
|
|
398
|
+
"error",
|
|
399
|
+
2,
|
|
400
|
+
{ SwitchCase: 1 }
|
|
401
|
+
],
|
|
402
|
+
"style/jsx-curly-newline": "off",
|
|
403
|
+
"style/jsx-one-expression-per-line": "off",
|
|
404
|
+
"style/jsx-quotes": ["error", "prefer-single"],
|
|
405
|
+
"style/linebreak-style": ["error", "unix"],
|
|
406
|
+
"style/max-len": [
|
|
407
|
+
"error",
|
|
408
|
+
100,
|
|
409
|
+
2,
|
|
410
|
+
{
|
|
411
|
+
ignoreComments: true,
|
|
412
|
+
ignoreStrings: true,
|
|
413
|
+
ignoreTemplateLiterals: true
|
|
414
|
+
}
|
|
415
|
+
],
|
|
416
|
+
"style/member-delimiter-style": "off",
|
|
417
|
+
"style/multiline-ternary": "off",
|
|
418
|
+
"style/no-tabs": "error",
|
|
419
|
+
"style/operator-linebreak": "off",
|
|
420
|
+
"style/quote-props": "off",
|
|
421
|
+
"style/quotes": [
|
|
422
|
+
"error",
|
|
423
|
+
"single",
|
|
424
|
+
{ allowTemplateLiterals: true }
|
|
425
|
+
],
|
|
426
|
+
"style/semi": ["error", "always"]
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
configs.unshift({
|
|
430
|
+
name: "siberiacancode",
|
|
431
|
+
plugins: { siberiacancode: siberiacancodePlugin },
|
|
432
|
+
rules: {
|
|
433
|
+
"siberiacancode/function-component-definition": ["error", { namedComponents: ["arrow-function"] }],
|
|
434
|
+
"siberiacancode/no-unused-class": "error"
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
configs.unshift({
|
|
438
|
+
name: "siberiacancode/css",
|
|
439
|
+
plugins: { "siberiacancode-css": pluginCss },
|
|
440
|
+
rules: { ...Object.entries(pluginCss.configs.recommended.rules).reduce((acc, [key, value]) => {
|
|
441
|
+
acc[key.replace("css", "siberiacancode-css")] = value;
|
|
442
|
+
return acc;
|
|
443
|
+
}, {}) }
|
|
444
|
+
});
|
|
445
|
+
return antfu({
|
|
446
|
+
...options,
|
|
447
|
+
typescript,
|
|
448
|
+
stylistic
|
|
449
|
+
}, {
|
|
450
|
+
name: "siberiacancode/rewrite",
|
|
451
|
+
rules: {
|
|
452
|
+
"antfu/curly": "off",
|
|
453
|
+
"antfu/if-newline": "off",
|
|
454
|
+
"antfu/top-level-function": "off",
|
|
455
|
+
"no-console": "warn",
|
|
456
|
+
"react-hooks/exhaustive-deps": "off",
|
|
457
|
+
"test/prefer-lowercase-title": "off"
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
name: "siberiacancode/sort",
|
|
461
|
+
rules: {
|
|
462
|
+
"perfectionist/sort-array-includes": ["error", {
|
|
463
|
+
order: "asc",
|
|
464
|
+
type: "alphabetical"
|
|
465
|
+
}],
|
|
466
|
+
"perfectionist/sort-imports": ["error", {
|
|
467
|
+
groups: [
|
|
468
|
+
"type-import",
|
|
469
|
+
["value-builtin", "value-external"],
|
|
470
|
+
"type-internal",
|
|
471
|
+
"value-internal",
|
|
472
|
+
[
|
|
473
|
+
"type-parent",
|
|
474
|
+
"type-sibling",
|
|
475
|
+
"type-index"
|
|
476
|
+
],
|
|
477
|
+
[
|
|
478
|
+
"value-parent",
|
|
479
|
+
"value-sibling",
|
|
480
|
+
"value-index"
|
|
481
|
+
],
|
|
482
|
+
"side-effect",
|
|
483
|
+
"side-effect-style",
|
|
484
|
+
"ts-equals-import",
|
|
485
|
+
"unknown"
|
|
486
|
+
],
|
|
487
|
+
internalPattern: ["^~/.+", "^@/.+"],
|
|
488
|
+
newlinesBetween: 1,
|
|
489
|
+
order: "asc",
|
|
490
|
+
type: "natural"
|
|
491
|
+
}],
|
|
492
|
+
"perfectionist/sort-interfaces": ["error", {
|
|
493
|
+
groups: [
|
|
494
|
+
"property",
|
|
495
|
+
"member",
|
|
496
|
+
"method",
|
|
497
|
+
"index-signature"
|
|
498
|
+
],
|
|
499
|
+
order: "asc",
|
|
500
|
+
type: "alphabetical"
|
|
501
|
+
}],
|
|
502
|
+
"perfectionist/sort-jsx-props": ["error", {
|
|
503
|
+
customGroups: [{
|
|
504
|
+
groupName: "reserved",
|
|
505
|
+
elementNamePattern: "^(key|ref)$"
|
|
506
|
+
}, {
|
|
507
|
+
groupName: "callback",
|
|
508
|
+
elementNamePattern: "^on[A-Z].*"
|
|
509
|
+
}],
|
|
510
|
+
groups: [
|
|
511
|
+
"shorthand-prop",
|
|
512
|
+
"reserved",
|
|
513
|
+
"multiline-prop",
|
|
514
|
+
"unknown",
|
|
515
|
+
"callback"
|
|
516
|
+
],
|
|
517
|
+
order: "asc",
|
|
518
|
+
type: "alphabetical"
|
|
519
|
+
}],
|
|
520
|
+
"perfectionist/sort-union-types": ["error", {
|
|
521
|
+
groups: [
|
|
522
|
+
"conditional",
|
|
523
|
+
"function",
|
|
524
|
+
"import",
|
|
525
|
+
"intersection",
|
|
526
|
+
"keyword",
|
|
527
|
+
"literal",
|
|
528
|
+
"named",
|
|
529
|
+
"object",
|
|
530
|
+
"operator",
|
|
531
|
+
"tuple",
|
|
532
|
+
"union",
|
|
533
|
+
"nullish"
|
|
534
|
+
],
|
|
535
|
+
order: "asc",
|
|
536
|
+
specialCharacters: "keep",
|
|
537
|
+
type: "alphabetical"
|
|
538
|
+
}]
|
|
539
|
+
}
|
|
540
|
+
}, ...configs);
|
|
195
541
|
};
|
|
542
|
+
|
|
543
|
+
//#endregion
|
|
544
|
+
export { eslint };
|