@cbrl/eslint-config 0.1.0 → 0.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.
@@ -2,7 +2,7 @@
2
2
  // a machine-checked dependency graph instead of a prose convention. Two walls:
3
3
  //
4
4
  // 1. PURITY — `features/*/core/**` is the functional core: pure rules, view
5
- // models, parsing. It MUST NOT reach for React, Next, Firestore, or any
5
+ // models, parsing. It MUST NOT reach for React, Next, a database client, or any
6
6
  // I/O. The whole point is that core is unit-testable with zero harness, so
7
7
  // coverage + mutation have teeth. Enforced with stock `no-restricted-imports`
8
8
  // (zero false positives — purity is literally "doesn't import these").
@@ -40,30 +40,36 @@ export const layering = [
40
40
  {
41
41
  group: ['react', 'react-dom', 'next', 'next/*'],
42
42
  message:
43
- 'core/ é o functional core: sem React/Next. Estado, efeito ou render vivem em ui/ ou adapters/.',
43
+ 'core/ is the functional core: no React/Next. State, effects and rendering live in ui/ or adapters/.',
44
44
  },
45
45
  {
46
46
  group: [
47
- 'firebase',
48
- 'firebase/*',
49
- 'firebase-admin',
50
- 'firebase-admin/*',
47
+ 'pg',
48
+ 'pg/*',
49
+ 'drizzle-orm',
50
+ 'drizzle-orm/*',
51
+ '@supabase/*',
52
+ 'stripe',
53
+ '@cbrl/pg',
54
+ '@cbrl/pg/*',
55
+ '@cbrl/supabase',
56
+ '@cbrl/supabase/*',
51
57
  '@/shared/db',
52
58
  '@/shared/db/*',
53
59
  'server-only',
54
60
  ],
55
61
  message:
56
- 'core/ é puro: sem Firestore/admin/server-only. Acesso a dado mora em adapters/ (ex.: *.repo.ts).',
62
+ 'core/ is pure: no database, auth or payment client, no server-only. Data access lives in adapters/ (e.g. *.repo.ts).',
57
63
  },
58
64
  {
59
65
  group: ['**/adapters/*', '**/ui/*', '@/features/*/adapters/*', '@/features/*/ui/*'],
60
66
  message:
61
- 'Dependência só desce (ui→adapters→core). core/ não pode importar adapters/ nem ui/.',
67
+ 'Dependencies only point down (ui→adapters→core): core/ must not import adapters/ or ui/.',
62
68
  },
63
69
  {
64
70
  group: ['@/app/*', '@/app/**'],
65
71
  message:
66
- 'features/ não importa app/ — app é a casca externa de roteamento (inversão).',
72
+ 'features/ must not import app/: app is the outer routing shell (inversion).',
67
73
  },
68
74
  ],
69
75
  },
@@ -83,23 +89,30 @@ export const layering = [
83
89
  patterns: [
84
90
  {
85
91
  group: ['react', 'react-dom', 'next', 'next/*'],
86
- message: 'domain/ é o kernel puro: sem React/Next.',
92
+ message: 'domain/ is the pure kernel: no React/Next.',
87
93
  },
88
94
  {
89
95
  group: [
90
- 'firebase',
91
- 'firebase/*',
92
- 'firebase-admin',
93
- 'firebase-admin/*',
96
+ 'pg',
97
+ 'pg/*',
98
+ 'drizzle-orm',
99
+ 'drizzle-orm/*',
100
+ '@supabase/*',
101
+ 'stripe',
102
+ '@cbrl/pg',
103
+ '@cbrl/pg/*',
104
+ '@cbrl/supabase',
105
+ '@cbrl/supabase/*',
94
106
  '@/shared/db',
95
107
  '@/shared/db/*',
96
108
  'server-only',
97
109
  ],
98
- message: 'domain/ é puro: sem Firestore/admin/server-only.',
110
+ message: 'domain/ is pure: no database, auth or payment client, no server-only.',
99
111
  },
100
112
  {
101
113
  group: ['@/shared/*', '@/features/*', '@/app/*'],
102
- message: 'domain/ é o anel mais interno — não importa shared/, features/ nem app/.',
114
+ message:
115
+ 'domain/ is the innermost ring: it must not import shared/, features/ or app/.',
103
116
  },
104
117
  ],
105
118
  },
@@ -123,7 +136,7 @@ export const layering = [
123
136
  {
124
137
  group: ['@/app/*', '@/app/**'],
125
138
  message:
126
- 'features/ não importa app/ — app é a casca externa de roteamento (inversão).',
139
+ 'features/ must not import app/: app is the outer routing shell (inversion).',
127
140
  },
128
141
  ],
129
142
  },
@@ -140,7 +153,7 @@ export const layering = [
140
153
  {
141
154
  group: ['@/features/*', '@/features/**', '@/app/*', '@/app/**'],
142
155
  message:
143
- 'shared/ é infra abaixo de features/ — não importa features/ nem app/ (inversão de camada).',
156
+ 'shared/ is infrastructure below features/: it must not import features/ or app/ (layer inversion).',
144
157
  },
145
158
  ],
146
159
  },
@@ -156,8 +169,7 @@ export const layering = [
156
169
  patterns: [
157
170
  {
158
171
  group: ['@/app/*', '@/app/**'],
159
- message:
160
- 'components/ é visual compartilhado — não importa app/ (inversão de camada).',
172
+ message: 'components/ is shared UI: it must not import app/ (layer inversion).',
161
173
  },
162
174
  ],
163
175
  },
@@ -186,13 +198,13 @@ export const layering = [
186
198
  from: ['feat-core'],
187
199
  disallow: ['feat-adapters', 'feat-ui'],
188
200
  message:
189
- 'core ({{from}}) não importa {{target}} — dependência só desce (ui→adapters→core).',
201
+ 'core ({{from}}) must not import {{target}}: dependencies only point down (ui→adapters→core).',
190
202
  },
191
203
  {
192
204
  from: ['feat-adapters'],
193
205
  disallow: ['feat-ui'],
194
206
  message:
195
- 'adapters ({{from}}) não importa ui — o fluxo é ui→adapters, nunca o contrário.',
207
+ 'adapters ({{from}}) must not import ui: the flow is ui→adapters, never the reverse.',
196
208
  },
197
209
  ],
198
210
  },
@@ -1,5 +1,4 @@
1
- // Layer: test-quality & ownership gates (paved road). See CONTRIBUTING.md
2
- // §"Princípios de engenharia". Prefer the canonical community plugin over a
1
+ // Layer: test-quality & ownership gates (paved road). Prefer the canonical community plugin over a
3
2
  // custom rule; a built-in `no-restricted-*` is used ONLY where no plugin rule
4
3
  // exists (the data-testid and raw-primitive bans). Existing violations are
5
4
  // grandfathered via the native bulk-suppressions file and pruned over time —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cbrl/eslint-config",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Strict ESLint flat config for TypeScript, React and Next.js apps, with custom fail-fast rules (no eslint-disable, no env fallbacks).",
5
5
  "license": "MIT",
6
6
  "author": "Kayron Cabral",
@@ -1,8 +1,6 @@
1
- // Custom rule: proíbe spread condicional aninhado em outro spread condicional.
1
+ // Custom rule: bans a conditional spread nested inside another conditional spread.
2
2
  //
3
- // Codifica decisão canônica do PR #971 (commit `abec9de7`) + recidiva no
4
- // PR #972 (commit `285e0f1c`). Memória de projeto não previne recidiva
5
- // cross-instância de Claude; análise sintática previne.
3
+ // A recurring review finding turned into a syntactic check, so it cannot regress.
6
4
  //
7
5
  // Anti-pattern:
8
6
  //
@@ -10,19 +8,19 @@
10
8
  // base: 1,
11
9
  // ...(c1
12
10
  // ? { foo: mapValue({
13
- // ...(c2 ? { a: x } : {}), // ← spread aninhado dentro
14
- // ...(c3 ? { b: y } : {}), // de outro spread cond
11
+ // ...(c2 ? { a: x } : {}), // ← spread nested inside
12
+ // ...(c3 ? { b: y } : {}), // another conditional spread
15
13
  // }) }
16
14
  // : {}),
17
15
  // }
18
16
  //
19
- // Por quê é ruim:
20
- // - Legibilidade ruim (nesting profundo, ternário + spread misturados)
21
- // - TypeScript infer fica frágil (vira `Partial<X>` / `Record<string,unknown>`)
22
- // - Repetição da expressão de teste (`c1.x` 3-6× no mesmo bloco)
23
- // - Esconde forma final do objeto — leitor expande mentalmente
17
+ // Why it hurts:
18
+ // - Poor readability (deep nesting, ternaries mixed with spreads)
19
+ // - Fragile TypeScript inference (degrades to `Partial<X>` / `Record<string, unknown>`)
20
+ // - The test expression repeats (`c1.x` 3-6 times in the same block)
21
+ // - Hides the final shape of the object — the reader expands it mentally
24
22
  //
25
- // Padrão correto: record intermediário + `if`s explícitos.
23
+ // Correct pattern: an intermediate record plus explicit `if`s.
26
24
  //
27
25
  // const inner: Record<string, X> = {}
28
26
  // if (c2) inner.a = x
@@ -30,20 +28,20 @@
30
28
  // const obj: Record<string, Y> = { base: 1 }
31
29
  // if (c1) obj.foo = mapValue(inner)
32
30
  //
33
- // Distinção (NÃO confundir):
34
- // - Spread condicional ÚNICO E RASO (`...(opts.foo ? { foo: ... } : {})`)
35
- // é idiomático — esta rule NÃO dispara nele.
36
- // - Só dispara quando há aninhamento (spread cond dentro de spread cond).
31
+ // Do NOT confuse with:
32
+ // - A SINGLE, SHALLOW conditional spread (`...(opts.foo ? { foo: ... } : {})`)
33
+ // is idiomatic — this rule does NOT fire on it.
34
+ // - It only fires on nesting (a conditional spread inside a conditional spread).
37
35
 
38
36
  function isConditionalSpread(node) {
39
37
  return node?.type === 'SpreadElement' && node.argument?.type === 'ConditionalExpression'
40
38
  }
41
39
 
42
- // Walk recursivo procurando outro spread condicional dentro do nó dado.
43
- // Caminha por ObjectExpression, CallExpression args, ArrayExpression,
44
- // ConditionalExpression branches e Property values — cobre os formatos
45
- // reais do anti-pattern (incluindo o caso `mapValue({...cond...})` onde o
46
- // spread aninhado mora dentro de uma chamada de helper).
40
+ // Recursive walk looking for another conditional spread inside the given node.
41
+ // Visits ObjectExpression, CallExpression args, ArrayExpression,
42
+ // ConditionalExpression branches and Property values — the real shapes of the
43
+ // anti-pattern (including `mapValue({...cond...})`, where the nested spread
44
+ // lives inside a helper call).
47
45
  function containsConditionalSpread(node, depthBudget = 50) {
48
46
  if (!node || depthBudget <= 0) return false
49
47
  if (isConditionalSpread(node)) return true
@@ -1,30 +1,29 @@
1
- // Custom rule: proíbe fallback hardcoded de VALOR em `process.env.<ANY>`.
1
+ // Custom rule: bans a hardcoded VALUE fallback on `process.env.<ANY>`.
2
2
  //
3
- // Codifica princípio canônico do harness: "fail-fast > silent default".
4
- // Vale pra QUALQUER env var (não só secrets): um default literal mascara
5
- // misconfig — o app roda com um valor trivial em vez de quebrar e expor que a
6
- // env não foi setada.
3
+ // Encodes "fail-fast over silent default". It applies to ANY env var, not only
4
+ // secrets: a literal default hides misconfiguration — the app runs with a
5
+ // trivial value instead of failing and revealing the variable was never set.
7
6
  //
8
- // Anti-pattern detectado (right operand é um literal de VALOR):
7
+ // Flagged anti-pattern (the right operand is a VALUE literal):
9
8
  // const url = process.env.APP_URL ?? 'http://localhost:3000'
10
9
  // const x = process.env.X || 'default'
11
10
  // process.env.X ??= 'literal'
12
11
  // process.env.X ||= 'literal'
13
- // const p = process.env.A ?? process.env.B ?? 'literal' // cadeia que termina em literal
12
+ // const p = process.env.A ?? process.env.B ?? 'literal' // chain ending in a literal
14
13
  //
15
- // Padrão correto: leia e falhe alto se ausente.
14
+ // Correct pattern: read it and fail loudly when missing.
16
15
  // const url = process.env.APP_URL
17
16
  // if (!url) throw new Error('APP_URL not set')
18
- // // ou um helper `env('APP_URL')` que faz isso.
17
+ // // or `requireEnv('APP_URL')` from @cbrl/env.
19
18
  //
20
- // NÃO viola (default não é literal de valor — não mascara misconfig):
21
- // - `||` booleano / lógica: `if (process.env.X || process.env.Y)`, `!!a || !!b`
22
- // - cadeia env→env sem literal: `process.env.A ?? process.env.B` (termina em throw downstream)
23
- // - normalização de ausência: `process.env.X ?? null`, `?? undefined`
24
- // - fallback que não é literal: `process.env.XDG_CONFIG_HOME ?? join(homedir(), ...)`
19
+ // NOT a violation (the default is not a value literal, so nothing is masked):
20
+ // - boolean / logical `||`: `if (process.env.X || process.env.Y)`, `!!a || !!b`
21
+ // - env→env chain with no literal: `process.env.A ?? process.env.B` (throws downstream)
22
+ // - absence normalization: `process.env.X ?? null`, `?? undefined`
23
+ // - non-literal fallback: `process.env.XDG_CONFIG_HOME ?? join(homedir(), ...)`
25
24
 
26
- // Literal de VALOR: string/number/boolean/bigint/template. Exclui `null`
27
- // (ESLint: Literal com value === null) — `?? null` é normalização, não default.
25
+ // VALUE literal: string/number/boolean/bigint/template. Excludes `null`
26
+ // (an ESLint Literal with value === null): `?? null` normalizes, it is not a default.
28
27
  function isValueLiteralFallback(node) {
29
28
  if (!node) return false
30
29
  if (node.type === 'TemplateLiteral') return true
@@ -41,8 +40,8 @@ function isProcessEnvAccess(node) {
41
40
  )
42
41
  }
43
42
 
44
- // `left` "vem de process.env" se é um acesso direto OU uma cadeia ??/|| cuja
45
- // raiz à esquerda é process.env — pega `process.env.A ?? process.env.B ?? 'lit'`.
43
+ // `left` "comes from process.env" when it is a direct access OR a ??/|| chain
44
+ // whose leftmost root is process.env — catches `process.env.A ?? process.env.B ?? 'lit'`.
46
45
  function leftRootIsProcessEnv(node) {
47
46
  if (isProcessEnvAccess(node)) return true
48
47
  if (node?.type === 'LogicalExpression' && (node.operator === '??' || node.operator === '||')) {
@@ -51,7 +50,7 @@ function leftRootIsProcessEnv(node) {
51
50
  return false
52
51
  }
53
52
 
54
- // Nome da env mais à esquerda (pra mensagem), descendo a cadeia ??/||.
53
+ // Leftmost env var name (for the message), walking down the ??/|| chain.
55
54
  function leftmostEnvVarName(node) {
56
55
  if (isProcessEnvAccess(node)) return node.property?.name
57
56
  if (node?.type === 'LogicalExpression') return leftmostEnvVarName(node.left)
@@ -1,12 +1,12 @@
1
1
  // Custom rule: bans EVERY `eslint-disable*` directive in code. A wrong rule is
2
2
  // changed in eslint.config.mjs through review, never silenced inline.
3
3
  //
4
- // Por que custom e não só o nativo `linterOptions.noInlineConfig`:
5
- // noInlineConfig neutraliza os directives mas reporta apenas WARNING (não
6
- // configurável pra error) — não barra um lint que roda sem `--max-warnings 0`.
7
- // Esta rule reporta ERROR (hard-fail). O `noInlineConfig` fica ligado em
8
- // paralelo como backstop: torna o disable inerte, então NÃO dá pra silenciar
9
- // esta própria regra com um `// eslint-disable-line cbrl/no-eslint-disable`.
4
+ // Why a custom rule and not just the native `linterOptions.noInlineConfig`:
5
+ // noInlineConfig neutralizes the directives but only reports a WARNING (not
6
+ // configurable as an error), so it does not fail a lint run without
7
+ // `--max-warnings 0`. This rule reports an ERROR (hard fail). `noInlineConfig`
8
+ // stays on alongside it as a backstop: it makes the directive inert, so this
9
+ // rule cannot be silenced with `// eslint-disable-line cbrl/no-eslint-disable`.
10
10
 
11
11
  export const noEslintDisable = {
12
12
  meta: {