@odg/eslint-config 3.0.4 → 3.2.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Linter } from 'eslint';
1
+ import type { Linter } from "eslint";
2
2
 
3
3
  /**
4
4
  * ODG ESLint Configuration
@@ -22,4 +22,4 @@ import type { Linter } from 'eslint';
22
22
  */
23
23
  declare const config: Linter.Config[];
24
24
 
25
- export default config;
25
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odg/eslint-config",
3
- "version": "3.0.4",
3
+ "version": "3.2.0",
4
4
  "description": "Linter for JavaScript And Typescript project",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -6,9 +6,11 @@ export default {
6
6
  {
7
7
  code: 120,
8
8
  ignoreUrls: true,
9
- ignoreStrings: true,
9
+ ignoreStrings: false,
10
10
  ignoreTemplateLiterals: true,
11
11
  ignoreRegExpLiterals: true,
12
+ ignoreComments: false,
13
+ ignoreTrailingComments: false,
12
14
  },
13
15
  ], // Caracteres máximo por linhas
14
16
  },
@@ -1,6 +1,15 @@
1
1
  const indentSize = 4;
2
2
  const complexity = 15;
3
3
  const alwaysMultiline = "always-multiline";
4
+ const multiLineBlock = "multiline-block-like";
5
+
6
+ // 1. DEFINIÇÕES (Para deixar a regra limpa)
7
+ const VARIABLES = [ "const", "let", "var" ];
8
+ const EXPORTS = [ "export", "cjs-export" ];
9
+ const IMPORTS = [ "import", "cjs-import" ];
10
+ const TYPES = [ "interface", "type", "enum", "class" ];
11
+ const FLOW_CONTROL = [ "if", "switch", "try", "for", "do", "while" ];
12
+ const BLOCK_LIKE = [ "block-like", multiLineBlock ];
4
13
 
5
14
  export default {
6
15
  rules: {
@@ -86,6 +95,48 @@ export default {
86
95
  // "regexp/prefer-regexp-exec": [ "error" ], // Prefira exec em regex // Match retorna 1 resultado apenas
87
96
 
88
97
  "unicorn/no-empty-file": [ "error" ], // Não crie arquivo vazio
98
+ "unicorn/filename-case": [
99
+ "error",
100
+ {
101
+ "cases": {
102
+ "kebabCase": true,
103
+ "pascalCase": true,
104
+ },
105
+ "ignore": [ ".md$" ],
106
+ },
107
+ ],
108
+ "no-restricted-syntax": [
109
+ "error",
110
+ {
111
+ "selector": "NewExpression[callee.name='Error']",
112
+ "message": "Do not use 'new Error()'. Use the exception classes from the @odg/exception"
113
+ + " package to maintain logging standardization.",
114
+ },
115
+ {
116
+ "selector": "CallExpression[callee.property.name='log']",
117
+ "message": "Do not use console.log. Use the @odg/log injected in the container to ensure traceability.",
118
+ },
119
+ {
120
+ "selector": "CallExpression[callee.property.name='forEach'][arguments.0.async=true]",
121
+ "message": "Do not use `.forEach` with async functions. `.forEach` does not wait for Promises."
122
+ + " Use `for...of` or`Promise.all()` instead.",
123
+ },
124
+ {
125
+ "selector": "CallExpression[callee.property.name='waitForTimeout']",
126
+ "message": "The use of 'waitForTimeout' is prohibited because it's intimidating."
127
+ + " Use 'waitForSelector', 'waitForResponse', or 'waitForFunction' instead.",
128
+ },
129
+ {
130
+ "selector": String.raw`CallExpression[callee.property.name=/^(click|waitForSelector|\$|\$\$|eval|type)$/][arguments.0.type='Literal'][arguments.0.value=/^[.#].*/]`,
131
+ "message": "Do not use hardcoded selectors."
132
+ + " Move a string to a file in the 'Selectors' folder to ensure decoupling.",
133
+ },
134
+ {
135
+ "selector": "BinaryExpression[operator='instanceof'][right.name='Error']",
136
+ "message": "Avoid 'error instances'. Use the specific specifications of your @odg/exception"
137
+ + "(Exception.isError) or structural type checking for greater security between packets.",
138
+ },
139
+ ],
89
140
  "no-magic-numbers": [
90
141
  "warn",
91
142
  {
@@ -193,6 +244,7 @@ export default {
193
244
  allowBlockStart: true,
194
245
  allowInterfaceStart: true,
195
246
  allowTypeStart: true,
247
+ allowArrayStart: true,
196
248
  },
197
249
  ], // Linha em branco antes do comentário
198
250
  "@stylistic/lines-between-class-members": [
@@ -205,9 +257,11 @@ export default {
205
257
  {
206
258
  code: 120,
207
259
  ignoreUrls: true,
208
- ignoreStrings: true,
260
+ ignoreStrings: false,
209
261
  ignoreTemplateLiterals: true,
210
262
  ignoreRegExpLiterals: true,
263
+ ignoreComments: false,
264
+ ignoreTrailingComments: false,
211
265
  },
212
266
  ], // Caracteres máximo por linhas
213
267
  "@stylistic/max-statements-per-line": [ "error", { max: 1 } ], // Máximo operação em 1 linha
@@ -323,16 +377,85 @@ export default {
323
377
  ], // Força não usar blocos com espaços
324
378
  "@stylistic/padding-line-between-statements": [
325
379
  "error",
326
- { "blankLine": "always", "prev": "*", "next": "export" }, // Uma linha em branco antes do export
327
- { "blankLine": "always", "prev": "export", "next": "*" }, // Uma linha em branco apos o export
328
- { "blankLine": "always", "prev": "*", "next": "class" }, // Uma linha em branco antes da classe
329
- { "blankLine": "always", "prev": "class", "next": "*" }, // Uma linha em branco apos a classe
330
- { "blankLine": "always", "prev": "*", "next": "interface" }, // Uma linha em branco antes da interface
331
- { "blankLine": "always", "prev": "interface", "next": "*" }, // Uma linha em branco apos a interface
332
- { "blankLine": "always", "prev": "*", "next": "type" }, // Uma linha em branco antes do type
333
- { "blankLine": "always", "prev": "type", "next": "*" }, // Uma linha em branco apos o type
334
- { "blankLine": "always", "prev": "multiline-block-like", "next": "*" },
335
- { "blankLine": "always", "prev": "*", "next": [ "enum", "interface", "type" ] },
380
+
381
+ /*
382
+ * ------------------------------------------------------
383
+ * 1. DIRETIVAS (ex: "use strict")
384
+ * ------------------------------------------------------
385
+ * Separa diretivas do resto do código
386
+ */
387
+ { "blankLine": "always", "prev": "directive", "next": "*" },
388
+ { "blankLine": "any", "prev": "directive", "next": "directive" },
389
+
390
+ /*
391
+ * ------------------------------------------------------
392
+ * 2. IMPORTS
393
+ * ------------------------------------------------------
394
+ * Imports sempre separados do código que vem depois
395
+ */
396
+ { "blankLine": "always", "prev": IMPORTS, "next": "*" },
397
+
398
+ // Entre imports, não força espaço (deixa agrupar)
399
+ { "blankLine": "any", "prev": IMPORTS, "next": IMPORTS },
400
+
401
+ /*
402
+ * ------------------------------------------------------
403
+ * 3. VARIÁVEIS
404
+ * ------------------------------------------------------
405
+ * A. REGRA GERAL: Variável seguida de *Qualquer coisa* = Espaço
406
+ */
407
+ { "blankLine": "always", "prev": VARIABLES, "next": "*" },
408
+
409
+ // B. EXCEÇÃO 1: Variável seguida de Variável = Pode colar
410
+ { "blankLine": "any", "prev": VARIABLES, "next": VARIABLES },
411
+
412
+ // C. EXCEÇÃO 2: Variável seguida de IF = Pode colar (Guard Clauses)
413
+ { "blankLine": "any", "prev": VARIABLES, "next": "if" },
414
+
415
+ /*
416
+ * ------------------------------------------------------
417
+ * 4. ESTRUTURAS DE TIPO (Types, Interfaces, Enums, Classes)
418
+ * ------------------------------------------------------
419
+ * Sempre dá espaço antes de declarar um tipo/classe
420
+ */
421
+ { "blankLine": "always", "prev": "*", "next": TYPES },
422
+
423
+ // Sempre dá espaço depois de declarar um tipo/classe
424
+ { "blankLine": "always", "prev": TYPES, "next": "*" },
425
+
426
+ /*
427
+ * ------------------------------------------------------
428
+ * 5. FLUXO E LÓGICA (If, For, While, Return)
429
+ * ------------------------------------------------------
430
+ * Espaço antes de comandos de saída (return, throw, break)
431
+ */
432
+ { "blankLine": "always", "prev": "*", "next": [ "return", "throw", "break", "continue" ] },
433
+
434
+ // Espaço ao redor de blocos de controle (if, for, while)
435
+ { "blankLine": "always", "prev": "*", "next": [ ...BLOCK_LIKE, ...FLOW_CONTROL ] },
436
+ { "blankLine": "always", "prev": [ ...BLOCK_LIKE, ...FLOW_CONTROL ], "next": "*" },
437
+
438
+ // EXCEÇÃO: IF seguido de IF (if-inline vai funcionar)
439
+ { "blankLine": "any", "prev": "if", "next": "if" },
440
+
441
+ /*
442
+ * ------------------------------------------------------
443
+ * 6. EXPORTS
444
+ * ------------------------------------------------------
445
+ * Export sempre isolado (antes e depois)
446
+ */
447
+ { "blankLine": "always", "prev": "*", "next": EXPORTS },
448
+ { "blankLine": "always", "prev": EXPORTS, "next": EXPORTS },
449
+
450
+ /*
451
+ * ------------------------------------------------------
452
+ * 7. O MARTELO (Regras de Segurança para Blocos Grandes)
453
+ * ------------------------------------------------------
454
+ * Se qualquer coisa for seguida por um bloco multilinha, OBRIGA espaço.
455
+ * Isso garante que se o seu 'if' colado crescer e virar um bloco, ele ganha espaço.
456
+ */
457
+ { "blankLine": "always", "prev": "*", "next": multiLineBlock },
458
+ { "blankLine": "always", "prev": multiLineBlock, "next": "*" },
336
459
  ],
337
460
  "@stylistic/quote-props": [ "error", "consistent" ], // Objeto com aspas ou sem consistent
338
461
  "@stylistic/quotes": [ "error", "double" ], // Força aspas dupla
@@ -344,10 +467,10 @@ export default {
344
467
  "@stylistic/space-before-function-paren": [
345
468
  "error",
346
469
  {
347
- anonymous: "never",
348
- named: "never",
349
- asyncArrow: "always",
350
- catch: "always",
470
+ "anonymous": "never",
471
+ "named": "never",
472
+ "asyncArrow": "always",
473
+ "catch": "always",
351
474
  },
352
475
  ], // Não permite espaço antes dos parenteses
353
476
  "@stylistic/space-in-parens": [ "error", "never" ], // Não permite espaço entre parenteses
@@ -358,7 +481,6 @@ export default {
358
481
  words: true, // Espaço apos Await e palavras chaves
359
482
  nonwords: false, // Força nao ter espaço antes de operadores unários !, -, +
360
483
  overrides: {
361
- "new": false,
362
484
  "++": false, // Nao permite espaço no ++
363
485
  },
364
486
  },
@@ -6,9 +6,11 @@ export default {
6
6
  {
7
7
  code: 120,
8
8
  ignoreUrls: true,
9
- ignoreStrings: true,
9
+ ignoreStrings: false,
10
10
  ignoreTemplateLiterals: true,
11
11
  ignoreRegExpLiterals: true,
12
+ ignoreComments: false,
13
+ ignoreTrailingComments: false,
12
14
  },
13
15
  ], // Caracteres máximo por linhas
14
16
  "toml/indent": [ "error" ], // Indent
@@ -343,6 +343,84 @@ export default {
343
343
  "vars-on-top": [ "error" ], // Caso a regra de var seja desativa elas devem ficar no topo
344
344
  "strict": [ "error" ], // Strict javascript top file
345
345
  "no-shadow-restricted-names": [ "error" ], // Sem variável com palavra reservada
346
+ "id-denylist": [
347
+ "error",
348
+
349
+ // Tipos TS
350
+ "number",
351
+ "string",
352
+ "boolean",
353
+ "any",
354
+ "void",
355
+ "never",
356
+ "unknown",
357
+
358
+ // Controle de Fluxo
359
+ "yield",
360
+ "await",
361
+ "async",
362
+
363
+ // Modificadores de Acesso
364
+ "public",
365
+ "protected",
366
+ "private",
367
+ "readonly",
368
+ "static",
369
+
370
+ // Estrutura
371
+ "class",
372
+ "interface",
373
+ "type",
374
+ "enum",
375
+ "namespace",
376
+ "module",
377
+
378
+ // Declaração
379
+ "function",
380
+ "var",
381
+ "let",
382
+ "const",
383
+
384
+ // Condicionais/Loops
385
+ "if",
386
+ "else",
387
+ "for",
388
+ "while",
389
+ "do",
390
+ "switch",
391
+ "case",
392
+ "default",
393
+
394
+ // Exceções
395
+ "try",
396
+ "catch",
397
+ "finally",
398
+ "throw",
399
+
400
+ // Módulos
401
+ "import",
402
+ "export",
403
+ "from",
404
+ "as",
405
+
406
+ // POO
407
+ "this",
408
+ "super",
409
+ "new",
410
+ "extends",
411
+ "implements",
412
+
413
+ // Genéricos proibidos
414
+ "data",
415
+ "val",
416
+ "obj",
417
+ "item",
418
+ "list",
419
+ "res",
420
+ "req",
421
+
422
+ // "callback", Callback parâmetro é bloqueado tb
423
+ ], // Sem variável com palavra reservada
346
424
  "logical-assignment-operators": [ "error", "always" ], // Faça ||= ao invés a = a || b
347
425
  "no-with": [ "error" ], // Não use with
348
426
 
@@ -19,9 +19,11 @@ export default {
19
19
  {
20
20
  code: 120,
21
21
  ignoreUrls: true,
22
- ignoreStrings: true,
22
+ ignoreStrings: false,
23
23
  ignoreTemplateLiterals: true,
24
24
  ignoreRegExpLiterals: true,
25
+ ignoreComments: false,
26
+ ignoreTrailingComments: false,
25
27
  },
26
28
  ], // Caracteres máximo por linhas
27
29
  "jsonc/no-irregular-whitespace": [ "error" ], // Não faça espaço irregular
@@ -14,20 +14,20 @@ const allAccessibility = [
14
14
  /**
15
15
  * Order member of class
16
16
  *
17
- * @param {Array<string>} types Tags name position
17
+ * @param {Array<string>} propertyTypes Tags name position
18
18
  * @param {string} tag Type of order
19
19
  * @param {Array<string>} accessibilityList Accessibility list of class
20
20
  * @returns {Array<string>}
21
21
  */
22
- function orderMember(types, tag, accessibilityList) {
22
+ function orderMember(propertyTypes, tag, accessibilityList) {
23
23
  return [
24
- ...accessibilityList.flatMap((accessibility) => types.map(
25
- (type) => {
24
+ ...accessibilityList.flatMap((accessibility) => propertyTypes.map(
25
+ (propertyType) => {
26
26
  const accessibilityName = accessibility ? `${accessibility}-` : "";
27
27
 
28
- if (accessibility === "private" && type === "abstract") return "";
28
+ if (accessibility === "private" && propertyType === "abstract") return "";
29
29
 
30
- return `${accessibilityName}${type}-${tag}`;
30
+ return `${accessibilityName}${propertyType}-${tag}`;
31
31
  },
32
32
  )).filter(Boolean),
33
33
  `${tag}`,
@@ -61,6 +61,7 @@ export default {
61
61
  ], // Não Crie tipos vazios
62
62
  "@typescript-eslint/no-import-type-side-effects": [ "error" ], // Coloque type fora para n importar no build
63
63
  "@typescript-eslint/explicit-function-return-type": [ "error" ], // Força tipo de retorno
64
+ "@typescript-eslint/explicit-module-boundary-types": [ "error" ], // Força tipo de retorno
64
65
  "no-unused-vars": [ "off" ], // Não permite variáveis não utilizadas
65
66
  "@typescript-eslint/no-unused-vars": [
66
67
  "error",
@@ -94,8 +95,8 @@ export default {
94
95
  "@typescript-eslint/array-type": [
95
96
  "error",
96
97
  {
97
- default: "array-simple",
98
- readonly: "array-simple",
98
+ "default": "array-simple",
99
+ "readonly": "array-simple",
99
100
  },
100
101
  ], // Não permite tipos de array incorretos
101
102
  "jsdoc/require-returns-check": [ "off" ],
@@ -104,7 +105,7 @@ export default {
104
105
  "error",
105
106
  "method",
106
107
  ], // Use arrow function em method signature interface
107
- "@typescript-eslint/no-unnecessary-type-assertion": [ "error" ], // Não permite declaração que não altera expressão
108
+ "@typescript-eslint/no-unnecessary-type-assertion": [ "error" ], // Não As declaração que não altera expressão
108
109
  "@typescript-eslint/no-unsafe-call": [ "error" ], // Não permite chamadas de funções em tipo any
109
110
  "space-infix-ops": [ "off" ], // Espaço na separação operadores
110
111
  "no-underscore-dangle": [ "error" ], // Não permite _ no nome
@@ -166,6 +167,7 @@ export default {
166
167
  "call-signature",
167
168
 
168
169
  ...orderMember([ "static", "decorated", "instance" ], "field", allAccessibility),
170
+ ...orderMember([ "abstract" ], "field", allAccessibility),
169
171
 
170
172
  // Static initialization
171
173
  "static-initialization",
@@ -184,7 +186,6 @@ export default {
184
186
 
185
187
  // Methods
186
188
  ...orderMember([ "static", "decorated", "instance" ], "method", allAccessibility),
187
- ...orderMember([ "abstract" ], "field", allAccessibility),
188
189
  ...orderMember([ "abstract" ], "method", allAccessibility),
189
190
  ],
190
191
  },
@@ -202,6 +203,7 @@ export default {
202
203
  "[accessors]",
203
204
  "[setters]",
204
205
  "[non-accessors]",
206
+ "[static-methods]",
205
207
  "[methods]",
206
208
  "[conventional-private-methods]",
207
209
  "[readonly]",
@@ -26,9 +26,11 @@ export default {
26
26
  {
27
27
  code: 120,
28
28
  ignoreUrls: true,
29
- ignoreStrings: true,
29
+ ignoreStrings: false,
30
30
  ignoreTemplateLiterals: true,
31
31
  ignoreRegExpLiterals: true,
32
+ ignoreComments: false,
33
+ ignoreTrailingComments: false,
32
34
  },
33
35
  ], // Caracteres máximo por linhas
34
36
  },