@numbado/eslint-config 0.0.0-stage → 1.0.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/index.js ADDED
@@ -0,0 +1,826 @@
1
+ // src/index.ts
2
+ import tseslint from "@typescript-eslint/eslint-plugin";
3
+ import tsParser from "@typescript-eslint/parser";
4
+ import prettierConfig from "eslint-config-prettier";
5
+ import simpleImportSort from "eslint-plugin-simple-import-sort";
6
+ import unusedImports from "eslint-plugin-unused-imports";
7
+
8
+ // src/utils/rules.ts
9
+ import { ESLintUtils } from "@typescript-eslint/utils";
10
+
11
+ // src/data/tools.ts
12
+ var LOCAL_RULES_PREFIX = "@numbado";
13
+ var LOCAL_RULES_JOINER = "/";
14
+
15
+ // src/utils/rules.ts
16
+ var getRuleName = (name) => LOCAL_RULES_PREFIX + LOCAL_RULES_JOINER + name;
17
+ var createRule = ESLintUtils.RuleCreator(getRuleName);
18
+
19
+ // src/data/react-components-content.ts
20
+ var REACT_COMPONENTS_CONTENT_NAME = "react-components-content";
21
+ var REACT_COMPONENTS_CONTENT_FULL_NAME = getRuleName(REACT_COMPONENTS_CONTENT_NAME);
22
+ var REACT_COMPONENTS_TRANSLATES_VAR_NAME = "translates";
23
+ var DOCS_DESCRIPTION = "Validate React component file content";
24
+ var ERROR_MESSAGES = {
25
+ ["only-one-component" /* OnlyOneComponent */]: "Component file must declare exactly one component named {{name}}.",
26
+ ["no-string-class-name" /* NoStringClassName */]: "String className is forbidden. Use CSS module or non-string expression.",
27
+ ["extra-component-file-declaration" /* ExtraComponentFileDeclaration */]: "Component file can contain only imports and one component declaration named {{name}}.",
28
+ ["data-only-constants" /* DataOnlyConstants */]: "Data file can contain only exported const data declarations.",
29
+ ["data-const-name" /* DataConstName */]: "Data constant name must be SCREAMING_SNAKE_CASE: {{name}}.",
30
+ ["data-no-functions" /* DataNoFunctions */]: "Functions are forbidden in data file. Move this to utils or hooks.",
31
+ ["translates-only" /* TranslatesOnly */]: "Translates file must declare only one const variable: translates.",
32
+ ["translates-type" /* TranslatesType */]: "translates must have TranslateMap type.",
33
+ ["translates-import" /* TranslatesImport */]: "TranslateMap must be imported from core library.",
34
+ ["hooks-only" /* HooksOnly */]: "Hooks file can declare only hook functions or hook functional constants.",
35
+ ["hook-name" /* HookName */]: "Hook name must start with use.",
36
+ ["hook-must-use-hook" /* HookMustUseHook */]: "Hook function must call at least one hook.",
37
+ ["utils-only" /* UtilsOnly */]: "Utils file can declare only functions or functional constants.",
38
+ ["no-hooks-in-utils" /* NoHooksInUtils */]: "Hooks are forbidden in utils file."
39
+ };
40
+
41
+ // src/data/react-components-structure.ts
42
+ var REACT_COMPONENTS_STRUCTURE_NAME = "react-components-structure";
43
+ var REACT_COMPONENTS_STRUCTURE_FULL_NAME = getRuleName(REACT_COMPONENTS_STRUCTURE_NAME);
44
+ var DOCS_DESCRIPTION2 = "Validate React component folder structure";
45
+ var ERROR_MESSAGES2 = {
46
+ ["invalid-name" /* InvalidName */]: "Component folder name must be PascalCase: {{name}}",
47
+ ["missing-file" /* MissingFile */]: "Missing required file: {{file}}",
48
+ ["extra-file" /* ExtraFile */]: "Extra file is not allowed: {{file}}"
49
+ };
50
+
51
+ // src/utils/node-react-componet.validation.ts
52
+ import path3 from "path";
53
+
54
+ // src/data/react-components.ts
55
+ var COMPONENT_ENTRY_FILE_NAME = "index.ts";
56
+ var COMPONENT_MAIN_FILE_POSTFIX = ".tsx";
57
+ var COMPONENT_DATA_FILE_POSTFIX = ".data.ts";
58
+ var COMPONENT_TYPES_FILE_POSTFIX = ".types.ts";
59
+ var COMPONENT_TRANSLATES_FILE_POSTFIX = ".translates.ts";
60
+ var COMPONENT_HOOKS_FILE_POSTFIX = ".hooks.ts";
61
+ var COMPONENT_UTILS_FILE_POSTFIX = ".utils.ts";
62
+ var COMPONENT_STYLE_FILE_POSTFIX = ".module.scss";
63
+ var COMPONENT_NAME_REGEXP = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/;
64
+
65
+ // src/utils/files.ts
66
+ import { relative, resolve } from "path";
67
+ var isPathMatch = (fileParts, patternParts) => {
68
+ if (fileParts.length <= patternParts.length) {
69
+ return false;
70
+ }
71
+ return patternParts.every((patternPart, index) => patternPart === "*" || patternPart === fileParts[index]);
72
+ };
73
+ var normalizePath = (value) => value.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
74
+ var getComponentDir = (filename, pathes, cwd) => {
75
+ const relativeFilename = normalizePath(relative(cwd, filename));
76
+ const fileParts = relativeFilename.split("/");
77
+ for (const componentPath of pathes) {
78
+ const patternParts = normalizePath(componentPath).split("/");
79
+ if (!isPathMatch(fileParts, patternParts)) {
80
+ continue;
81
+ }
82
+ const componentNameIndex = patternParts.length;
83
+ if (fileParts.length < componentNameIndex + 2) {
84
+ continue;
85
+ }
86
+ const componentDirRelativePath = fileParts.slice(0, componentNameIndex + 1).join("/");
87
+ return resolve(cwd, componentDirRelativePath);
88
+ }
89
+ return null;
90
+ };
91
+ var isValidComponentName = (name) => COMPONENT_NAME_REGEXP.test(name);
92
+
93
+ // src/utils/node-react-data.validation.ts
94
+ import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
95
+
96
+ // src/utils/node.ts
97
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
98
+ var isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
99
+ var isFunctionExpression = (node) => node?.type === AST_NODE_TYPES.ArrowFunctionExpression || node?.type === AST_NODE_TYPES.FunctionExpression;
100
+ var isFunctionDeclaration = (node) => node?.type === AST_NODE_TYPES.FunctionDeclaration;
101
+ var isVariableDeclaration = (node) => node?.type === AST_NODE_TYPES.VariableDeclaration;
102
+ var getIdentifierName = (id) => id.type === AST_NODE_TYPES.Identifier ? id.name : null;
103
+ var isStringClassNameValue = (node) => {
104
+ if (!node.value) {
105
+ return false;
106
+ }
107
+ if (node.value.type === AST_NODE_TYPES.Literal && typeof node.value.value === "string") {
108
+ return true;
109
+ }
110
+ if (node.value.type === AST_NODE_TYPES.JSXExpressionContainer && (node.value.expression.type === AST_NODE_TYPES.Literal || node.value.expression.type === AST_NODE_TYPES.TemplateLiteral)) {
111
+ return true;
112
+ }
113
+ return node.value.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.TemplateLiteral;
114
+ };
115
+ var isClassNameAttribute = (node) => node.name.type === AST_NODE_TYPES.JSXIdentifier && node.name.name === "className";
116
+ var unwrapExportDeclaration = (node) => {
117
+ if (node.type === AST_NODE_TYPES.ExportNamedDeclaration || node.type === AST_NODE_TYPES.ExportDefaultDeclaration) {
118
+ return node.declaration ?? null;
119
+ }
120
+ return node;
121
+ };
122
+ var isDirectFunctionValue = (node) => node?.type === AST_NODE_TYPES.ArrowFunctionExpression || node?.type === AST_NODE_TYPES.FunctionExpression;
123
+
124
+ // src/data/validators.ts
125
+ var CASE_VALIDATORS = {
126
+ ["uppercase-snake-case" /* UpperCaseSnakeCase */]: /^[A-Z][A-Z0-9]*(?:_[A-Z][A-Z0-9]*)*$/,
127
+ ["camel-case" /* CamelCase */]: /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/,
128
+ ["pascal-case" /* PascalCase */]: /^[A-Z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/,
129
+ ["kebab-case" /* KebabCase */]: /^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/,
130
+ ["snake-case" /* SnakeCase */]: /^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$/
131
+ };
132
+
133
+ // src/utils/strings.ts
134
+ var validateCase = (value, type) => CASE_VALIDATORS[type].test(value);
135
+
136
+ // src/utils/node-react-data.validation.ts
137
+ var validateDataStatement = (context, node) => {
138
+ if (node.type === AST_NODE_TYPES2.ImportDeclaration || node.type === AST_NODE_TYPES2.EmptyStatement) {
139
+ return;
140
+ }
141
+ const declaration = unwrapExportDeclaration(node);
142
+ if (!isVariableDeclaration(declaration) || declaration.kind !== "const") {
143
+ context.report({
144
+ node,
145
+ messageId: "data-only-constants" /* DataOnlyConstants */
146
+ });
147
+ return;
148
+ }
149
+ for (const declarator of declaration.declarations) {
150
+ const name = getIdentifierName(declarator.id);
151
+ if (typeof name !== "string" || !name.length) {
152
+ context.report({
153
+ node: declarator,
154
+ messageId: "data-only-constants" /* DataOnlyConstants */
155
+ });
156
+ continue;
157
+ }
158
+ if (!validateCase(name, "uppercase-snake-case" /* UpperCaseSnakeCase */)) {
159
+ context.report({
160
+ node: declarator,
161
+ messageId: "data-const-name" /* DataConstName */,
162
+ data: { name }
163
+ });
164
+ }
165
+ if (isDirectFunctionValue(declarator.init)) {
166
+ context.report({
167
+ node: declarator,
168
+ messageId: "data-no-functions" /* DataNoFunctions */
169
+ });
170
+ }
171
+ }
172
+ };
173
+ var validateDataFile = (context, program) => {
174
+ for (const node of program.body) {
175
+ validateDataStatement(context, node);
176
+ }
177
+ };
178
+
179
+ // src/utils/node-react-hooks.validation.ts
180
+ import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
181
+ var validateHookStatement = (context, node) => {
182
+ const declaration = unwrapExportDeclaration(node);
183
+ if (node.type === AST_NODE_TYPES3.ImportDeclaration || node.type === AST_NODE_TYPES3.EmptyStatement) {
184
+ return;
185
+ }
186
+ if (isFunctionDeclaration(declaration) || declaration?.type === AST_NODE_TYPES3.TSDeclareFunction) {
187
+ const name = declaration.id?.name;
188
+ if (!name) {
189
+ context.report({
190
+ node,
191
+ messageId: "hooks-only" /* HooksOnly */
192
+ });
193
+ return;
194
+ }
195
+ if (!isValidHookName(name)) {
196
+ context.report({ node, messageId: "hook-name" /* HookName */ });
197
+ }
198
+ if (isFunctionDeclaration(declaration) && declaration.body && !hasHookCall(declaration.body)) {
199
+ context.report({ node, messageId: "hook-must-use-hook" /* HookMustUseHook */ });
200
+ }
201
+ return;
202
+ }
203
+ if (isVariableDeclaration(declaration) && declaration.kind === "const") {
204
+ for (const item of declaration.declarations) {
205
+ const name = getIdentifierName(item.id);
206
+ if (!name || !isFunctionExpression(item.init)) {
207
+ context.report({
208
+ node: item,
209
+ messageId: "hooks-only" /* HooksOnly */
210
+ });
211
+ continue;
212
+ }
213
+ if (!isValidHookName(name)) {
214
+ context.report({
215
+ node: item,
216
+ messageId: "hook-name" /* HookName */
217
+ });
218
+ }
219
+ if (!hasHookCall(item.init)) {
220
+ context.report({
221
+ node: item,
222
+ messageId: "hook-must-use-hook" /* HookMustUseHook */
223
+ });
224
+ }
225
+ }
226
+ return;
227
+ }
228
+ context.report({
229
+ node,
230
+ messageId: "hooks-only" /* HooksOnly */
231
+ });
232
+ };
233
+ var isHookCallee = (callee) => {
234
+ if (callee.type === AST_NODE_TYPES3.Identifier) {
235
+ return isValidHookName(callee.name);
236
+ }
237
+ if (callee.type === AST_NODE_TYPES3.MemberExpression && callee.property.type === AST_NODE_TYPES3.Identifier) {
238
+ return isValidHookName(callee.property.name);
239
+ }
240
+ return false;
241
+ };
242
+ var hasHookCall = (node, visited = /* @__PURE__ */ new WeakSet(), isRoot = true) => {
243
+ if (visited.has(node)) {
244
+ return false;
245
+ }
246
+ visited.add(node);
247
+ if (node.type === AST_NODE_TYPES3.CallExpression && isHookCallee(node.callee)) {
248
+ return true;
249
+ }
250
+ if (!isRoot && (node.type === AST_NODE_TYPES3.ArrowFunctionExpression || node.type === AST_NODE_TYPES3.FunctionExpression || node.type === AST_NODE_TYPES3.FunctionDeclaration)) {
251
+ return false;
252
+ }
253
+ return Object.entries(node).some(([key, value]) => {
254
+ if (key === "parent" || key === "loc" || key === "range" || key === "tokens" || key === "comments") {
255
+ return false;
256
+ }
257
+ if (Array.isArray(value)) {
258
+ return value.some((item) => isNode(item) && hasHookCall(item, visited, false));
259
+ }
260
+ return isNode(value) && hasHookCall(value, visited, false);
261
+ });
262
+ };
263
+ var isValidHookName = (name) => validateCase(name, "camel-case" /* CamelCase */) && /^use[A-Z0-9]/.test(name);
264
+ var validateHooksFile = (context, program) => {
265
+ for (const node of program.body) {
266
+ validateHookStatement(context, node);
267
+ }
268
+ };
269
+
270
+ // src/utils/node-react-main.validation.ts
271
+ import path from "path";
272
+ import { AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
273
+ var isMainComponentDeclaration = (node, componentName) => {
274
+ const declaration = unwrapExportDeclaration(node);
275
+ if (declaration?.type === AST_NODE_TYPES4.FunctionDeclaration && declaration.id?.name === componentName) {
276
+ return true;
277
+ }
278
+ if (declaration?.type !== AST_NODE_TYPES4.VariableDeclaration || declaration.kind !== "const" || declaration.declarations.length !== 1) {
279
+ return false;
280
+ }
281
+ const declarator = declaration.declarations[0];
282
+ return declarator.id.type === AST_NODE_TYPES4.Identifier && declarator.id.name === componentName && (declarator.init?.type === AST_NODE_TYPES4.ArrowFunctionExpression || declarator.init?.type === AST_NODE_TYPES4.FunctionExpression);
283
+ };
284
+ var validateComponentFile = (context, program, componentName) => {
285
+ let componentDeclarationCount = 0;
286
+ for (const node of program.body) {
287
+ if (node.type === AST_NODE_TYPES4.ImportDeclaration || node.type === AST_NODE_TYPES4.EmptyStatement) {
288
+ continue;
289
+ }
290
+ if (isMainComponentDeclaration(node, componentName)) {
291
+ componentDeclarationCount += 1;
292
+ continue;
293
+ }
294
+ context.report({
295
+ node,
296
+ messageId: "extra-component-file-declaration" /* ExtraComponentFileDeclaration */,
297
+ data: { name: componentName }
298
+ });
299
+ }
300
+ if (componentDeclarationCount !== 1) {
301
+ context.report({
302
+ node: program,
303
+ messageId: "only-one-component" /* OnlyOneComponent */,
304
+ data: { name: componentName }
305
+ });
306
+ }
307
+ };
308
+ var validateComponentJSX = (context, pathes, node) => {
309
+ const filename = context.filename;
310
+ const componentDir = getComponentDir(filename, pathes, context.cwd);
311
+ if (!componentDir) {
312
+ return;
313
+ }
314
+ const componentName = path.basename(componentDir);
315
+ const basename = path.basename(filename);
316
+ if (basename !== `${componentName}${COMPONENT_MAIN_FILE_POSTFIX}`) {
317
+ return;
318
+ }
319
+ if (isClassNameAttribute(node) && isStringClassNameValue(node)) {
320
+ context.report({
321
+ node,
322
+ messageId: "no-string-class-name" /* NoStringClassName */
323
+ });
324
+ }
325
+ };
326
+
327
+ // src/utils/node-react-translates.validation.ts
328
+ import { AST_NODE_TYPES as AST_NODE_TYPES5 } from "@typescript-eslint/utils";
329
+ var isTranslateMapTypeNode = (node) => node?.type === AST_NODE_TYPES5.TSTypeReference && node.typeName.type === AST_NODE_TYPES5.Identifier && node.typeName.name === "TranslateMap";
330
+ var hasTranslateMapTypeAnnotation = (declarator) => {
331
+ if (declarator.id.type !== AST_NODE_TYPES5.Identifier) {
332
+ return false;
333
+ }
334
+ return isTranslateMapTypeNode(
335
+ declarator.id.typeAnnotation?.typeAnnotation
336
+ );
337
+ };
338
+ var hasTranslateMapSatisfies = (node) => {
339
+ if (!node) {
340
+ return false;
341
+ }
342
+ if (node.type === AST_NODE_TYPES5.TSSatisfiesExpression && isTranslateMapTypeNode(node.typeAnnotation)) {
343
+ return true;
344
+ }
345
+ if (node.type === AST_NODE_TYPES5.TSAsExpression || node.type === AST_NODE_TYPES5.TSNonNullExpression) {
346
+ return hasTranslateMapSatisfies(node.expression);
347
+ }
348
+ return false;
349
+ };
350
+ var isTranslateMapType = (declarator) => hasTranslateMapTypeAnnotation(declarator) || hasTranslateMapSatisfies(declarator.init);
351
+ var hasTranslateMapCoreImport = (program) => program.body.some((node) => {
352
+ if (node.type !== AST_NODE_TYPES5.ImportDeclaration) {
353
+ return false;
354
+ }
355
+ if (typeof node.source.value !== "string" || !node.source.value.includes("core")) {
356
+ return false;
357
+ }
358
+ return node.specifiers.some((specifier) => specifier.type === AST_NODE_TYPES5.ImportSpecifier && specifier.local.name === "TranslateMap");
359
+ });
360
+ var validateTranslatesStatement = (context, node) => {
361
+ if (node.type === AST_NODE_TYPES5.ImportDeclaration || node.type === AST_NODE_TYPES5.EmptyStatement) {
362
+ return false;
363
+ }
364
+ const declaration = unwrapExportDeclaration(node);
365
+ if (!isVariableDeclaration(declaration) || declaration.kind !== "const" || declaration.declarations.length !== 1) {
366
+ context.report({
367
+ node,
368
+ messageId: "translates-only" /* TranslatesOnly */
369
+ });
370
+ return false;
371
+ }
372
+ const declarator = declaration.declarations[0];
373
+ const name = getIdentifierName(declarator.id);
374
+ if (name !== REACT_COMPONENTS_TRANSLATES_VAR_NAME) {
375
+ context.report({
376
+ node: declarator,
377
+ messageId: "translates-only" /* TranslatesOnly */
378
+ });
379
+ return false;
380
+ }
381
+ if (!isTranslateMapType(declarator)) {
382
+ context.report({
383
+ node: declarator,
384
+ messageId: "translates-type" /* TranslatesType */
385
+ });
386
+ }
387
+ return true;
388
+ };
389
+ var validateTranslatesFile = (context, program) => {
390
+ let translatesCount = 0;
391
+ for (const node of program.body) {
392
+ translatesCount += validateTranslatesStatement(context, node) ? 1 : 0;
393
+ }
394
+ if (translatesCount !== 1) {
395
+ context.report({
396
+ node: program,
397
+ messageId: "translates-only" /* TranslatesOnly */
398
+ });
399
+ }
400
+ if (!hasTranslateMapCoreImport(program)) {
401
+ context.report({
402
+ node: program,
403
+ messageId: "translates-import" /* TranslatesImport */
404
+ });
405
+ }
406
+ };
407
+
408
+ // src/utils/node-react-utils.validation.ts
409
+ import path2 from "path";
410
+ import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
411
+ var isValidUtilName = (name) => validateCase(name, "camel-case" /* CamelCase */) && !isValidHookName(name);
412
+ var validateUtilStatement = (context, node) => {
413
+ const declaration = unwrapExportDeclaration(node);
414
+ if (node.type === AST_NODE_TYPES6.ImportDeclaration || node.type === AST_NODE_TYPES6.EmptyStatement) {
415
+ return;
416
+ }
417
+ if (isFunctionDeclaration(declaration) || declaration?.type === AST_NODE_TYPES6.TSDeclareFunction) {
418
+ const name = declaration.id?.name;
419
+ if (!name || !isValidUtilName(name)) {
420
+ context.report({
421
+ node,
422
+ messageId: "utils-only" /* UtilsOnly */
423
+ });
424
+ if (!name) {
425
+ return;
426
+ }
427
+ }
428
+ if (isValidHookName(name)) {
429
+ context.report({
430
+ node,
431
+ messageId: "no-hooks-in-utils" /* NoHooksInUtils */
432
+ });
433
+ }
434
+ return;
435
+ }
436
+ if (isVariableDeclaration(declaration) && declaration.kind === "const") {
437
+ for (const item of declaration.declarations) {
438
+ const name = getIdentifierName(item.id);
439
+ if (!name || !isFunctionExpression(item.init) || !isValidUtilName(name)) {
440
+ context.report({
441
+ node: item,
442
+ messageId: "utils-only" /* UtilsOnly */
443
+ });
444
+ if (!name || !isFunctionExpression(item.init)) {
445
+ continue;
446
+ }
447
+ }
448
+ if (isValidHookName(name)) {
449
+ context.report({
450
+ node: item,
451
+ messageId: "no-hooks-in-utils" /* NoHooksInUtils */
452
+ });
453
+ }
454
+ }
455
+ return;
456
+ }
457
+ context.report({
458
+ node,
459
+ messageId: "utils-only" /* UtilsOnly */
460
+ });
461
+ };
462
+ var validateUtilsFile = (context, program) => {
463
+ for (const node of program.body) {
464
+ validateUtilStatement(context, node);
465
+ }
466
+ };
467
+ var validateUtilsCalls = (context, pathes, node) => {
468
+ const filename = context.filename;
469
+ const componentDir = getComponentDir(filename, pathes, context.cwd);
470
+ if (typeof componentDir !== "string" || !componentDir.length) {
471
+ return;
472
+ }
473
+ const componentName = path2.basename(componentDir);
474
+ const basename = path2.basename(filename);
475
+ if (basename !== `${componentName}${COMPONENT_UTILS_FILE_POSTFIX}`) {
476
+ return;
477
+ }
478
+ if (isHookCallee(node.callee)) {
479
+ context.report({
480
+ node,
481
+ messageId: "no-hooks-in-utils" /* NoHooksInUtils */
482
+ });
483
+ }
484
+ };
485
+
486
+ // src/utils/node-react-componet.validation.ts
487
+ var validateComponentFiles = (context, pathes, program) => {
488
+ const filename = context.filename;
489
+ const componentDir = getComponentDir(filename, pathes, context.cwd);
490
+ if (!componentDir) {
491
+ return;
492
+ }
493
+ const componentName = path3.basename(componentDir);
494
+ const basename = path3.basename(filename);
495
+ switch (basename) {
496
+ case `${componentName}${COMPONENT_MAIN_FILE_POSTFIX}`:
497
+ return validateComponentFile(context, program, componentName);
498
+ case `${componentName}${COMPONENT_DATA_FILE_POSTFIX}`:
499
+ return validateDataFile(context, program);
500
+ case `${componentName}${COMPONENT_TRANSLATES_FILE_POSTFIX}`:
501
+ return validateTranslatesFile(context, program);
502
+ case `${componentName}${COMPONENT_HOOKS_FILE_POSTFIX}`:
503
+ return validateHooksFile(context, program);
504
+ case `${componentName}${COMPONENT_UTILS_FILE_POSTFIX}`:
505
+ return validateUtilsFile(context, program);
506
+ }
507
+ };
508
+
509
+ // src/tools/react-components-content.ts
510
+ var REACT_COMPONENTS_CONTENT = createRule({
511
+ name: REACT_COMPONENTS_CONTENT_NAME,
512
+ meta: {
513
+ type: "problem",
514
+ docs: {
515
+ description: DOCS_DESCRIPTION
516
+ },
517
+ messages: ERROR_MESSAGES,
518
+ schema: [
519
+ {
520
+ type: "object",
521
+ properties: {
522
+ pathes: {
523
+ type: "array",
524
+ items: {
525
+ type: "string"
526
+ },
527
+ minItems: 1
528
+ }
529
+ },
530
+ additionalProperties: false,
531
+ required: ["pathes"]
532
+ }
533
+ ]
534
+ },
535
+ defaultOptions: [
536
+ {
537
+ pathes: []
538
+ }
539
+ ],
540
+ create: (context, [{ pathes }]) => ({
541
+ Program: validateComponentFiles.bind(null, context, pathes),
542
+ JSXAttribute: validateComponentJSX.bind(null, context, pathes),
543
+ CallExpression: validateUtilsCalls.bind(null, context, pathes)
544
+ })
545
+ });
546
+
547
+ // src/tools/react-components-structure.ts
548
+ import fs from "fs";
549
+ import path4 from "path";
550
+ var checkedDirs = /* @__PURE__ */ new Set();
551
+ var REACT_COMPONENTS_STRUCTURE = createRule({
552
+ name: REACT_COMPONENTS_STRUCTURE_NAME,
553
+ meta: {
554
+ type: "problem",
555
+ docs: {
556
+ description: DOCS_DESCRIPTION2
557
+ },
558
+ messages: ERROR_MESSAGES2,
559
+ schema: [
560
+ {
561
+ type: "object",
562
+ properties: {
563
+ pathes: {
564
+ type: "array",
565
+ items: {
566
+ type: "string"
567
+ },
568
+ minItems: 1
569
+ }
570
+ },
571
+ additionalProperties: false,
572
+ required: ["pathes"]
573
+ }
574
+ ]
575
+ },
576
+ defaultOptions: [
577
+ {
578
+ pathes: []
579
+ }
580
+ ],
581
+ create: (context, [{ pathes }]) => ({
582
+ Program: () => {
583
+ const filename = context.filename;
584
+ const cwd = context.cwd;
585
+ const componentDir = getComponentDir(filename, pathes, cwd);
586
+ if (!componentDir || checkedDirs.has(componentDir)) {
587
+ return;
588
+ }
589
+ checkedDirs.add(componentDir);
590
+ const componentName = path4.basename(componentDir);
591
+ if (!isValidComponentName(componentName)) {
592
+ context.report({
593
+ loc: { line: 1, column: 0 },
594
+ messageId: "invalid-name" /* InvalidName */,
595
+ data: { name: componentName }
596
+ });
597
+ return;
598
+ }
599
+ const requiredFiles = [
600
+ COMPONENT_ENTRY_FILE_NAME,
601
+ `${componentName}${COMPONENT_MAIN_FILE_POSTFIX}`
602
+ ];
603
+ const optionalFiles = [
604
+ `${componentName}${COMPONENT_DATA_FILE_POSTFIX}`,
605
+ `${componentName}${COMPONENT_TYPES_FILE_POSTFIX}`,
606
+ `${componentName}${COMPONENT_HOOKS_FILE_POSTFIX}`,
607
+ `${componentName}${COMPONENT_UTILS_FILE_POSTFIX}`,
608
+ `${componentName}${COMPONENT_STYLE_FILE_POSTFIX}`,
609
+ `${componentName}${COMPONENT_TRANSLATES_FILE_POSTFIX}`
610
+ ];
611
+ const allowedFiles = /* @__PURE__ */ new Set([
612
+ ...requiredFiles,
613
+ ...optionalFiles
614
+ ]);
615
+ const actualFiles = fs.readdirSync(componentDir);
616
+ for (const file of requiredFiles) {
617
+ if (!actualFiles.includes(file)) {
618
+ context.report({
619
+ loc: { line: 1, column: 0 },
620
+ messageId: "missing-file" /* MissingFile */,
621
+ data: { file }
622
+ });
623
+ }
624
+ }
625
+ for (const file of actualFiles) {
626
+ if (!allowedFiles.has(file)) {
627
+ context.report({
628
+ loc: { line: 1, column: 0 },
629
+ messageId: "extra-file" /* ExtraFile */,
630
+ data: { file }
631
+ });
632
+ }
633
+ }
634
+ }
635
+ })
636
+ });
637
+
638
+ // src/tools/plugins.ts
639
+ var NUMBADO_PLUGINS = {
640
+ rules: {
641
+ [REACT_COMPONENTS_STRUCTURE_NAME]: REACT_COMPONENTS_STRUCTURE,
642
+ [REACT_COMPONENTS_CONTENT_NAME]: REACT_COMPONENTS_CONTENT
643
+ }
644
+ };
645
+
646
+ // src/index.ts
647
+ var basePlugins = {
648
+ "eslint-plugin-simple-import-sort": simpleImportSort,
649
+ "eslint-plugin-unused-imports": unusedImports,
650
+ [LOCAL_RULES_PREFIX]: NUMBADO_PLUGINS
651
+ };
652
+ var baseRules = {
653
+ quotes: ["error", "single"],
654
+ eqeqeq: ["error", "always"],
655
+ semi: ["error", "always"],
656
+ "operator-linebreak": ["error", "before", { overrides: { "=": "after" } }],
657
+ "prefer-const": "error",
658
+ "object-shorthand": "error",
659
+ "arrow-body-style": ["error", "as-needed"],
660
+ "no-extra-parens": "off",
661
+ "no-constant-binary-expression": "error",
662
+ "no-unsafe-optional-chaining": "error",
663
+ "no-duplicate-imports": "error",
664
+ "no-useless-return": "error",
665
+ "multiline-ternary": ["error", "always-multiline"],
666
+ curly: ["error", "all"],
667
+ "padding-line-between-statements": [
668
+ "error",
669
+ {
670
+ blankLine: "always",
671
+ prev: "import",
672
+ next: "*"
673
+ },
674
+ {
675
+ blankLine: "any",
676
+ prev: "import",
677
+ next: "import"
678
+ },
679
+ {
680
+ blankLine: "always",
681
+ prev: ["const", "let", "var"],
682
+ next: "return"
683
+ }
684
+ ],
685
+ "sort-imports": "off",
686
+ "eslint-plugin-simple-import-sort/imports": "error",
687
+ "eslint-plugin-simple-import-sort/exports": "error",
688
+ "eslint-plugin-unused-imports/no-unused-imports": "error",
689
+ "eslint-plugin-unused-imports/no-unused-vars": "error",
690
+ "space-before-blocks": ["error", "always"],
691
+ "keyword-spacing": [
692
+ "error",
693
+ {
694
+ before: true,
695
+ after: true
696
+ }
697
+ ],
698
+ "space-in-parens": ["error", "never"],
699
+ "object-curly-spacing": ["error", "always"],
700
+ "key-spacing": ["error", { afterColon: true }],
701
+ indent: "off",
702
+ "no-trailing-spaces": ["error", { skipBlankLines: false }],
703
+ "space-infix-ops": ["error", { int32Hint: false }],
704
+ "no-magic-numbers": [
705
+ "error",
706
+ {
707
+ ignore: [0, 1],
708
+ ignoreArrayIndexes: true,
709
+ ignoreDefaultValues: true,
710
+ enforceConst: true,
711
+ detectObjects: false
712
+ }
713
+ ]
714
+ };
715
+ var createConfig = ({
716
+ tsconfigRootDir,
717
+ reactComponentsPathes,
718
+ projects
719
+ }) => {
720
+ const tsconfigRootDirValue = tsconfigRootDir || process.cwd();
721
+ const rules = {};
722
+ if (Array.isArray(reactComponentsPathes)) {
723
+ const pathes = reactComponentsPathes.filter((path5) => typeof path5 === "string" && path5.trim() !== "");
724
+ if (pathes.length > 0) {
725
+ rules[REACT_COMPONENTS_STRUCTURE_FULL_NAME] = [
726
+ "error",
727
+ { pathes }
728
+ ];
729
+ rules[REACT_COMPONENTS_CONTENT_FULL_NAME] = [
730
+ "error",
731
+ { pathes }
732
+ ];
733
+ }
734
+ }
735
+ return [
736
+ {
737
+ ignores: [
738
+ "node_modules/**",
739
+ ".vscode/**",
740
+ "build/**",
741
+ ".build/**",
742
+ "dist/**",
743
+ ".dist/**",
744
+ "generated/**"
745
+ ]
746
+ },
747
+ {
748
+ files: ["**/*.{ts,tsx}"],
749
+ languageOptions: {
750
+ parser: tsParser,
751
+ ecmaVersion: "latest",
752
+ sourceType: "module",
753
+ parserOptions: {
754
+ projectService: true,
755
+ tsconfigRootDir: tsconfigRootDirValue,
756
+ projects: projects || []
757
+ }
758
+ },
759
+ plugins: {
760
+ ...basePlugins,
761
+ "@typescript-eslint": tseslint
762
+ },
763
+ rules: {
764
+ ...baseRules,
765
+ ...rules,
766
+ "@typescript-eslint/strict-boolean-expressions": "warn",
767
+ "@typescript-eslint/no-explicit-any": "error",
768
+ "no-duplicate-imports": ["error", { allowSeparateTypeImports: true }],
769
+ "@typescript-eslint/consistent-type-imports": [
770
+ "error",
771
+ {
772
+ prefer: "type-imports",
773
+ fixStyle: "separate-type-imports",
774
+ disallowTypeAnnotations: false
775
+ }
776
+ ],
777
+ "@typescript-eslint/no-floating-promises": "error",
778
+ "@typescript-eslint/no-misused-promises": "error",
779
+ "@typescript-eslint/no-unused-vars": "off",
780
+ "@typescript-eslint/explicit-function-return-type": [
781
+ "error",
782
+ {
783
+ allowExpressions: false,
784
+ allowTypedFunctionExpressions: true,
785
+ allowHigherOrderFunctions: true,
786
+ allowDirectConstAssertionInArrowFunctions: true
787
+ }
788
+ ],
789
+ "@typescript-eslint/typedef": [
790
+ "error",
791
+ {
792
+ propertyDeclaration: true,
793
+ parameter: true,
794
+ variableDeclaration: false
795
+ }
796
+ ],
797
+ "no-magic-numbers": "off",
798
+ "@typescript-eslint/no-magic-numbers": [
799
+ "error",
800
+ {
801
+ ignore: [0, 1],
802
+ ignoreArrayIndexes: true,
803
+ ignoreDefaultValues: true,
804
+ enforceConst: true,
805
+ ignoreEnums: true,
806
+ ignoreNumericLiteralTypes: true,
807
+ ignoreReadonlyClassProperties: true
808
+ }
809
+ ]
810
+ }
811
+ },
812
+ {
813
+ files: ["**/*.{js,jsx}"],
814
+ languageOptions: {
815
+ ecmaVersion: "latest",
816
+ sourceType: "module"
817
+ },
818
+ plugins: basePlugins,
819
+ rules: baseRules
820
+ },
821
+ prettierConfig
822
+ ];
823
+ };
824
+ export {
825
+ createConfig
826
+ };