@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.
package/configs/layering.mjs
CHANGED
|
@@ -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,
|
|
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/
|
|
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
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
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/
|
|
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
|
-
'
|
|
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/
|
|
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/
|
|
92
|
+
message: 'domain/ is the pure kernel: no React/Next.',
|
|
87
93
|
},
|
|
88
94
|
{
|
|
89
95
|
group: [
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
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/
|
|
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:
|
|
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/
|
|
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/
|
|
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}})
|
|
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}})
|
|
207
|
+
'adapters ({{from}}) must not import ui: the flow is ui→adapters, never the reverse.',
|
|
196
208
|
},
|
|
197
209
|
],
|
|
198
210
|
},
|
package/configs/test-quality.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Layer: test-quality & ownership gates (paved road).
|
|
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.
|
|
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:
|
|
1
|
+
// Custom rule: bans a conditional spread nested inside another conditional spread.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
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
|
|
14
|
-
// ...(c3 ? { b: y } : {}), //
|
|
11
|
+
// ...(c2 ? { a: x } : {}), // ← spread nested inside
|
|
12
|
+
// ...(c3 ? { b: y } : {}), // another conditional spread
|
|
15
13
|
// }) }
|
|
16
14
|
// : {}),
|
|
17
15
|
// }
|
|
18
16
|
//
|
|
19
|
-
//
|
|
20
|
-
// -
|
|
21
|
-
// - TypeScript
|
|
22
|
-
// -
|
|
23
|
-
// -
|
|
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
|
-
//
|
|
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
|
-
//
|
|
34
|
-
// -
|
|
35
|
-
//
|
|
36
|
-
// -
|
|
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
|
-
//
|
|
43
|
-
//
|
|
44
|
-
// ConditionalExpression branches
|
|
45
|
-
//
|
|
46
|
-
//
|
|
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:
|
|
1
|
+
// Custom rule: bans a hardcoded VALUE fallback on `process.env.<ANY>`.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
-
//
|
|
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' //
|
|
12
|
+
// const p = process.env.A ?? process.env.B ?? 'literal' // chain ending in a literal
|
|
14
13
|
//
|
|
15
|
-
//
|
|
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
|
-
// //
|
|
17
|
+
// // or `requireEnv('APP_URL')` from @cbrl/env.
|
|
19
18
|
//
|
|
20
|
-
//
|
|
21
|
-
// -
|
|
22
|
-
// -
|
|
23
|
-
// -
|
|
24
|
-
// - fallback
|
|
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
|
-
//
|
|
27
|
-
// (ESLint
|
|
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` "
|
|
45
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
5
|
-
// noInlineConfig
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
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: {
|