@cbrl/eslint-config 0.1.0 → 0.1.1
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
|
@@ -40,7 +40,7 @@ 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: [
|
|
@@ -53,17 +53,17 @@ export const layering = [
|
|
|
53
53
|
'server-only',
|
|
54
54
|
],
|
|
55
55
|
message:
|
|
56
|
-
'core/
|
|
56
|
+
'core/ is pure: no Firestore/admin/server-only. Data access lives in adapters/ (e.g. *.repo.ts).',
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
group: ['**/adapters/*', '**/ui/*', '@/features/*/adapters/*', '@/features/*/ui/*'],
|
|
60
60
|
message:
|
|
61
|
-
'
|
|
61
|
+
'Dependencies only point down (ui→adapters→core): core/ must not import adapters/ or ui/.',
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
group: ['@/app/*', '@/app/**'],
|
|
65
65
|
message:
|
|
66
|
-
'features/
|
|
66
|
+
'features/ must not import app/: app is the outer routing shell (inversion).',
|
|
67
67
|
},
|
|
68
68
|
],
|
|
69
69
|
},
|
|
@@ -83,7 +83,7 @@ export const layering = [
|
|
|
83
83
|
patterns: [
|
|
84
84
|
{
|
|
85
85
|
group: ['react', 'react-dom', 'next', 'next/*'],
|
|
86
|
-
message: 'domain/
|
|
86
|
+
message: 'domain/ is the pure kernel: no React/Next.',
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
89
|
group: [
|
|
@@ -95,11 +95,12 @@ export const layering = [
|
|
|
95
95
|
'@/shared/db/*',
|
|
96
96
|
'server-only',
|
|
97
97
|
],
|
|
98
|
-
message: 'domain/
|
|
98
|
+
message: 'domain/ is pure: no Firestore/admin/server-only.',
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
101
|
group: ['@/shared/*', '@/features/*', '@/app/*'],
|
|
102
|
-
message:
|
|
102
|
+
message:
|
|
103
|
+
'domain/ is the innermost ring: it must not import shared/, features/ or app/.',
|
|
103
104
|
},
|
|
104
105
|
],
|
|
105
106
|
},
|
|
@@ -123,7 +124,7 @@ export const layering = [
|
|
|
123
124
|
{
|
|
124
125
|
group: ['@/app/*', '@/app/**'],
|
|
125
126
|
message:
|
|
126
|
-
'features/
|
|
127
|
+
'features/ must not import app/: app is the outer routing shell (inversion).',
|
|
127
128
|
},
|
|
128
129
|
],
|
|
129
130
|
},
|
|
@@ -140,7 +141,7 @@ export const layering = [
|
|
|
140
141
|
{
|
|
141
142
|
group: ['@/features/*', '@/features/**', '@/app/*', '@/app/**'],
|
|
142
143
|
message:
|
|
143
|
-
'shared/
|
|
144
|
+
'shared/ is infrastructure below features/: it must not import features/ or app/ (layer inversion).',
|
|
144
145
|
},
|
|
145
146
|
],
|
|
146
147
|
},
|
|
@@ -156,8 +157,7 @@ export const layering = [
|
|
|
156
157
|
patterns: [
|
|
157
158
|
{
|
|
158
159
|
group: ['@/app/*', '@/app/**'],
|
|
159
|
-
message:
|
|
160
|
-
'components/ é visual compartilhado — não importa app/ (inversão de camada).',
|
|
160
|
+
message: 'components/ is shared UI: it must not import app/ (layer inversion).',
|
|
161
161
|
},
|
|
162
162
|
],
|
|
163
163
|
},
|
|
@@ -186,13 +186,13 @@ export const layering = [
|
|
|
186
186
|
from: ['feat-core'],
|
|
187
187
|
disallow: ['feat-adapters', 'feat-ui'],
|
|
188
188
|
message:
|
|
189
|
-
'core ({{from}})
|
|
189
|
+
'core ({{from}}) must not import {{target}}: dependencies only point down (ui→adapters→core).',
|
|
190
190
|
},
|
|
191
191
|
{
|
|
192
192
|
from: ['feat-adapters'],
|
|
193
193
|
disallow: ['feat-ui'],
|
|
194
194
|
message:
|
|
195
|
-
'adapters ({{from}})
|
|
195
|
+
'adapters ({{from}}) must not import ui: the flow is ui→adapters, never the reverse.',
|
|
196
196
|
},
|
|
197
197
|
],
|
|
198
198
|
},
|
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.1.
|
|
3
|
+
"version": "0.1.1",
|
|
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: {
|