@yasainet/eslint 0.0.39 → 0.0.41
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/package.json +1 -1
- package/src/common/imports.mjs +52 -4
- package/src/common/layers.mjs +13 -1
- package/src/next/naming.mjs +1 -1
package/package.json
CHANGED
package/src/common/imports.mjs
CHANGED
|
@@ -102,6 +102,15 @@ const LIB_BOUNDARY_PATTERNS = [
|
|
|
102
102
|
},
|
|
103
103
|
];
|
|
104
104
|
|
|
105
|
+
const MAPPING_PATTERNS = [
|
|
106
|
+
{
|
|
107
|
+
group: ["@/utils/mapping.util"],
|
|
108
|
+
importNames: ["mapSnakeToCamel", "mapCamelToSnake"],
|
|
109
|
+
message:
|
|
110
|
+
"Mapping functions are only allowed in services. Snake/camel conversion belongs at the service boundary.",
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
105
114
|
const PAGE_BOUNDARY_PATTERNS = [
|
|
106
115
|
{
|
|
107
116
|
group: ["*/repositories/*", "*/repositories"],
|
|
@@ -138,7 +147,10 @@ export const pageBoundaryConfigs = [
|
|
|
138
147
|
},
|
|
139
148
|
];
|
|
140
149
|
|
|
141
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Next.js-only: restrict @/lib imports and mapping imports outside features.
|
|
152
|
+
* Per-feature subdir rules live in createImportsConfigs to avoid clobbering each other.
|
|
153
|
+
*/
|
|
142
154
|
export const libBoundaryConfigs = [
|
|
143
155
|
{
|
|
144
156
|
name: "imports/lib-boundary",
|
|
@@ -148,11 +160,13 @@ export const libBoundaryConfigs = [
|
|
|
148
160
|
"src/proxy.ts",
|
|
149
161
|
"src/app/sitemap.ts",
|
|
150
162
|
"src/app/**/route.ts",
|
|
151
|
-
"src/features
|
|
152
|
-
"src/features/**/types/**",
|
|
163
|
+
"src/features/**",
|
|
153
164
|
],
|
|
154
165
|
rules: {
|
|
155
|
-
"no-restricted-imports": [
|
|
166
|
+
"no-restricted-imports": [
|
|
167
|
+
"error",
|
|
168
|
+
{ patterns: [...LIB_BOUNDARY_PATTERNS, ...MAPPING_PATTERNS] },
|
|
169
|
+
],
|
|
156
170
|
},
|
|
157
171
|
},
|
|
158
172
|
];
|
|
@@ -192,6 +206,7 @@ export function createImportsConfigs(
|
|
|
192
206
|
[`${featureRoot}/**/repositories/*.ts`],
|
|
193
207
|
LAYER_PATTERNS.repositories,
|
|
194
208
|
LATERAL_PATTERNS.repositories,
|
|
209
|
+
MAPPING_PATTERNS,
|
|
195
210
|
),
|
|
196
211
|
);
|
|
197
212
|
|
|
@@ -205,6 +220,7 @@ export function createImportsConfigs(
|
|
|
205
220
|
LAYER_PATTERNS.repositories,
|
|
206
221
|
LATERAL_PATTERNS.repositories,
|
|
207
222
|
patterns,
|
|
223
|
+
MAPPING_PATTERNS,
|
|
208
224
|
),
|
|
209
225
|
);
|
|
210
226
|
}
|
|
@@ -226,6 +242,7 @@ export function createImportsConfigs(
|
|
|
226
242
|
LAYER_PATTERNS.actions,
|
|
227
243
|
LATERAL_PATTERNS.actions,
|
|
228
244
|
LIB_BOUNDARY_PATTERNS,
|
|
245
|
+
MAPPING_PATTERNS,
|
|
229
246
|
),
|
|
230
247
|
);
|
|
231
248
|
|
|
@@ -234,9 +251,39 @@ export function createImportsConfigs(
|
|
|
234
251
|
"utils",
|
|
235
252
|
[`${featureRoot}/**/utils/*.ts`],
|
|
236
253
|
LIB_BOUNDARY_PATTERNS,
|
|
254
|
+
MAPPING_PATTERNS,
|
|
237
255
|
),
|
|
238
256
|
);
|
|
239
257
|
|
|
258
|
+
// Catch-all for feature subdirs without a per-layer config
|
|
259
|
+
// (constants, hooks, schemas). lib-boundary + mapping ban.
|
|
260
|
+
configs.push({
|
|
261
|
+
name: "imports/feature-other",
|
|
262
|
+
files: [`${featureRoot}/**/*.ts`],
|
|
263
|
+
ignores: [
|
|
264
|
+
`${featureRoot}/**/services/*.ts`,
|
|
265
|
+
`${featureRoot}/**/repositories/*.ts`,
|
|
266
|
+
`${featureRoot}/**/actions/*.ts`,
|
|
267
|
+
`${featureRoot}/**/utils/*.ts`,
|
|
268
|
+
`${featureRoot}/**/types/*.ts`,
|
|
269
|
+
],
|
|
270
|
+
rules: {
|
|
271
|
+
"no-restricted-imports": [
|
|
272
|
+
"error",
|
|
273
|
+
{ patterns: [...LIB_BOUNDARY_PATTERNS, ...MAPPING_PATTERNS] },
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Types: mapping ban only. lib is allowed (Database/Tables type imports).
|
|
279
|
+
configs.push({
|
|
280
|
+
name: "imports/feature-types",
|
|
281
|
+
files: [`${featureRoot}/**/types/*.ts`],
|
|
282
|
+
rules: {
|
|
283
|
+
"no-restricted-imports": ["error", { patterns: MAPPING_PATTERNS }],
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
240
287
|
for (const prefix of ["server", "client", "admin"]) {
|
|
241
288
|
configs.push(
|
|
242
289
|
makeConfig(
|
|
@@ -246,6 +293,7 @@ export function createImportsConfigs(
|
|
|
246
293
|
LATERAL_PATTERNS.actions,
|
|
247
294
|
CARDINALITY_PATTERNS[prefix],
|
|
248
295
|
LIB_BOUNDARY_PATTERNS,
|
|
296
|
+
MAPPING_PATTERNS,
|
|
249
297
|
),
|
|
250
298
|
);
|
|
251
299
|
}
|
package/src/common/layers.mjs
CHANGED
|
@@ -39,7 +39,7 @@ export function createLayersConfigs(featureRoot) {
|
|
|
39
39
|
],
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
|
-
// Services: try-catch + logger
|
|
42
|
+
// Services: try-catch + logger + dead error fallbacks
|
|
43
43
|
{
|
|
44
44
|
name: "layers/services",
|
|
45
45
|
files: [`${featureRoot}/**/services/*.ts`],
|
|
@@ -52,6 +52,18 @@ export function createLayersConfigs(featureRoot) {
|
|
|
52
52
|
"try-catch is not allowed in services. Error handling belongs in actions.",
|
|
53
53
|
},
|
|
54
54
|
{ selector: loggerSelector, message: loggerMessage },
|
|
55
|
+
{
|
|
56
|
+
selector:
|
|
57
|
+
"LogicalExpression[operator='??'][left.type='ChainExpression'][left.expression.property.name='message'][right.type='Literal']",
|
|
58
|
+
message:
|
|
59
|
+
"Dead fallback for error message. If you reached this branch the error is known — return the error directly. Unhandled exceptions belong in actions.",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
selector:
|
|
63
|
+
"LogicalExpression[operator='??'][left.type='MemberExpression'][left.property.name='error'][right.type='ObjectExpression']",
|
|
64
|
+
message:
|
|
65
|
+
"Dead fallback for nullable error. Check `if (error)` and return the error directly. Unhandled exceptions belong in actions.",
|
|
66
|
+
},
|
|
55
67
|
],
|
|
56
68
|
},
|
|
57
69
|
},
|
package/src/next/naming.mjs
CHANGED