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