-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
187 lines (170 loc) · 7.39 KB
/
Copy patheslint.config.mjs
File metadata and controls
187 lines (170 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import boundaries from 'eslint-plugin-boundaries'
import functional from 'eslint-plugin-functional'
import oxlint from 'eslint-plugin-oxlint'
import preferArrowFunctions from 'eslint-plugin-prefer-arrow-functions'
import { defineConfig } from 'eslint/config'
import tseslint from 'typescript-eslint'
// ── Boundary mode ──────────────────────────────────────────────
// "feature" → src/orders/domain.ts, src/orders/use-cases.ts, ...
// "layer" → src/domain/orders.ts, src/application/orders.ts, ...
// "none" → no boundary enforcement
const BOUNDARY_MODE = 'feature'
// ── Boundary element definitions per mode ──────────────────────
const boundaryElements = {
feature: [
{ type: 'domain', pattern: ['src/*/domain.ts', 'src/*/domain/**'] },
{ type: 'application', pattern: ['src/*/use-cases.ts', 'src/*/logic.ts', 'src/*/ports.ts'] },
{ type: 'infrastructure', pattern: ['src/*/repo.ts', 'src/*/io.ts', 'src/*/adapter.ts', 'src/cli/**'] },
{ type: 'shared', pattern: ['src/shared/**'] },
{ type: 'composition', pattern: ['src/main.ts'] },
{ type: 'test', pattern: ['src/**/*.spec.ts', 'src/test/**'] },
],
layer: [
{ type: 'domain', pattern: ['src/domain/**'] },
{ type: 'application', pattern: ['src/application/**'] },
{ type: 'infrastructure', pattern: ['src/infrastructure/**'] },
{ type: 'shared', pattern: ['src/shared/**'] },
{ type: 'composition', pattern: ['src/main.ts'] },
{ type: 'test', pattern: ['src/**/*.spec.ts', 'src/test/**'] },
],
}
// Dependency inversion: inner layers cannot import outer layers
const boundaryRules = [
{ from: 'domain', allow: ['domain', 'shared'] },
{ from: 'application', allow: ['domain', 'application', 'shared'] },
{ from: 'infrastructure', allow: ['domain', 'application', 'infrastructure', 'shared'] },
{ from: 'composition', allow: ['domain', 'application', 'infrastructure', 'shared', 'composition'] },
{ from: 'test', allow: ['domain', 'application', 'infrastructure', 'shared', 'test'] },
]
// Domain file globs (used for purity + FP strictness overrides)
const domainFiles = BOUNDARY_MODE === 'feature' ?
['src/*/domain.ts', 'src/*/domain/**/*.ts'] :
['src/domain/**/*.ts']
// Infra file globs (relaxed FP rules)
const infraFiles = BOUNDARY_MODE === 'feature' ?
['src/*/repo.ts', 'src/*/io.ts', 'src/*/adapter.ts', 'src/cli/**/*.ts'] :
['src/infrastructure/**/*.ts']
// ── Functional rules (global defaults) ─────────────────────────
// These are the core FP rules that oxlint cannot replicate.
// ESLint owns all functional/* enforcement.
const functionalRules = {
'functional/no-loop-statements': 'error',
'functional/no-try-statements': 'error',
'functional/no-throw-statements': 'error',
'functional/no-let': ['error', { allowInForLoopInit: false }],
'functional/no-classes': 'error',
'functional/no-this-expressions': 'error',
'functional/immutable-data': ['warn', { ignoreImmediateMutation: true, ignoreClasses: true }],
'functional/prefer-readonly-type': 'warn',
'functional/no-expression-statements': ['error', {
ignoreVoid: true,
ignoreCodePattern: ['^expect', '^assert'],
}],
'functional/no-return-void': 'error',
}
// ── AST selector bans (oxlint cannot do ESQuery selectors) ─────
const restrictedSyntax = ['error', {
selector: ":function > Identifier.params[typeAnnotation.typeAnnotation.type='TSBooleanKeyword']",
message: 'Boolean params are banned. Split into separate functions.',
}, {
selector: "CallExpression[callee.property.name='_unsafeUnwrap']",
message: 'Use .map(), .andThen(), or .match() instead.',
}, {
selector: "CallExpression[callee.property.name='_unsafeUnwrapErr']",
message: 'Use .mapErr(), .andThen(), or .match() instead.',
}]
// ── Domain purity: ban IO imports in domain files ──────────────
const domainImportBans = {
patterns: [{
group: ['fs', 'fs/*', 'path', 'http', 'https', 'net', 'child_process', 'crypto'],
message: 'Domain must be pure. No Node.js IO.',
}, {
group: ['express', 'fastify', 'koa', 'hono', 'elysia'],
message: 'Domain must be pure. No HTTP frameworks.',
}, {
group: ['pg', 'mysql*', 'redis', 'ioredis', 'mongoose', '@prisma/*', 'kysely'],
message: 'Domain must be pure. No database drivers.',
}, {
group: ['@aws-sdk/*', '@azure/*', '@google-cloud/*'],
message: 'Domain must be pure. No cloud SDKs.',
}],
}
// ── Build config array ─────────────────────────────────────────
const config = [
{ ignores: ['node_modules/**', 'dist/**', 'eslint.config.mjs'] },
// Global: all source files
{
files: ['src/**/*.ts'],
languageOptions: {
parser: tseslint.parser,
parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
},
plugins: {
functional,
'prefer-arrow-functions': preferArrowFunctions,
...(BOUNDARY_MODE !== 'none' && { boundaries }),
},
...(BOUNDARY_MODE !== 'none' && { settings: { 'boundaries/elements': boundaryElements[BOUNDARY_MODE] } }),
rules: {
...functionalRules,
'no-restricted-syntax': restrictedSyntax,
// Arrow function enforcement: ESLint owns the *semantic* rule
// (must use arrows). dprint owns arrow *formatting* (parens, wrapping).
'prefer-arrow-functions/prefer-arrow-functions': ['error', {
allowNamedFunctions: false,
classPropertiesAllowed: false,
disallowPrototype: true,
returnStyle: 'unchanged',
singleReturnOnly: false,
}],
// Boundaries (only when enabled)
...(BOUNDARY_MODE !== 'none' &&
{ 'boundaries/element-types': ['error', { default: 'disallow', rules: boundaryRules }] }),
},
},
// Domain purity: ban IO imports
{
files: domainFiles,
rules: {
'no-restricted-imports': ['error', domainImportBans],
'functional/prefer-readonly-type': 'error',
},
},
// Tests: fully relax FP rules
{
files: ['src/**/*.spec.ts', 'src/test/**/*.ts'],
rules: {
'functional/no-let': 'off',
'functional/no-loop-statements': 'off',
'functional/no-try-statements': 'off',
'functional/no-throw-statements': 'off',
'functional/no-expression-statements': 'off',
'functional/no-return-void': 'off',
'functional/immutable-data': 'off',
'functional/no-classes': 'off',
'functional/no-this-expressions': 'off',
'no-restricted-syntax': 'off',
},
},
// Infrastructure: imperative shell allowances
{
files: infraFiles,
rules: {
'functional/no-let': 'warn',
'functional/no-loop-statements': 'warn',
'functional/no-try-statements': 'off',
'functional/no-throw-statements': 'off',
'functional/no-expression-statements': 'off',
'functional/no-return-void': 'off',
'functional/immutable-data': 'off',
'functional/no-classes': ['error', {
ignoreIdentifierPattern: '^.*(Controller|Adapter|Module|Client|Provider|Gateway)$',
}],
'functional/no-this-expressions': 'off',
},
},
// Deduplicate: turn off anything oxlint already handles
...oxlint.buildFromOxlintConfigFile('./.oxlintrc.json'),
]
// eslint-disable no-default-export
export default defineConfig(...config)