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