@yasainet/eslint 0.0.72 → 0.0.74
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/README.md +17 -60
- package/package.json +1 -1
- package/src/common/{constants.mjs → _internal/constants.mjs} +0 -18
- package/src/common/_internal/import-patterns.mjs +16 -0
- package/src/common/{plugins.mjs → _internal/plugins.mjs} +0 -1
- package/src/common/_internal/selectors.mjs +10 -0
- package/src/common/{rules.mjs → base/typescript.mjs} +2 -29
- package/src/common/{entry-points.mjs → boundaries/entry-point.mjs} +0 -1
- package/src/common/cross-cutting/ban-alias.mjs +22 -0
- package/src/common/cross-cutting/feature-default-imports.mjs +26 -0
- package/src/common/cross-cutting/feature-name.mjs +15 -0
- package/src/common/cross-cutting/features-ts-only.mjs +20 -0
- package/src/common/cross-cutting/form-state.mjs +16 -0
- package/src/common/{jsdoc.mjs → cross-cutting/jsdoc.mjs} +2 -3
- package/src/common/cross-cutting/logger.mjs +21 -0
- package/src/common/cross-cutting/namespace-import.mjs +23 -0
- package/src/common/cross-cutting/no-any-return.mjs +18 -0
- package/src/common/cross-cutting/supabase-columns-satisfies.mjs +18 -0
- package/src/common/index.mjs +42 -24
- package/src/common/layers/constants.mjs +36 -0
- package/src/common/layers/entries.mjs +168 -0
- package/src/common/layers/lib.mjs +18 -0
- package/src/common/layers/queries.mjs +183 -0
- package/src/common/layers/schemas.mjs +45 -0
- package/src/common/layers/services.mjs +115 -0
- package/src/common/layers/top-level-utils.mjs +18 -0
- package/src/common/layers/types.mjs +44 -0
- package/src/common/layers/utils.mjs +50 -0
- package/src/common/local-plugins/entry-single-service-call.mjs +0 -30
- package/src/common/local-plugins/entry-template.mjs +33 -72
- package/src/common/local-plugins/feature-name.mjs +8 -22
- package/src/common/local-plugins/form-state-naming.mjs +0 -10
- package/src/common/local-plugins/form-state-shape.mjs +0 -34
- package/src/common/local-plugins/import-path-style.mjs +0 -7
- package/src/common/local-plugins/index.mjs +0 -1
- package/src/common/local-plugins/layout-main-structural-only.mjs +0 -21
- package/src/common/local-plugins/namespace-import-name.mjs +0 -26
- package/src/common/local-plugins/no-any-return.mjs +0 -8
- package/src/common/local-plugins/queries-export.mjs +0 -8
- package/src/common/local-plugins/queries-namespace-import.mjs +0 -10
- package/src/common/local-plugins/schema-naming.mjs +0 -6
- package/src/common/local-plugins/supabase-columns-satisfies.mjs +0 -24
- package/src/common/local-plugins/supabase-select-typed-columns.mjs +0 -32
- package/src/deno/boundaries/entry-point.mjs +44 -0
- package/src/deno/boundaries/lib.mjs +28 -0
- package/src/deno/boundaries/utils.mjs +25 -0
- package/src/deno/index.mjs +9 -13
- package/src/deno/local-plugins/flat-entry-point.mjs +0 -5
- package/src/deno/local-plugins/index.mjs +0 -1
- package/src/next/boundaries/components.mjs +36 -0
- package/src/next/boundaries/hooks.mjs +36 -0
- package/src/next/boundaries/lib.mjs +23 -0
- package/src/next/boundaries/page.mjs +36 -0
- package/src/next/boundaries/route.mjs +36 -0
- package/src/next/boundaries/sitemap.mjs +36 -0
- package/src/next/directives.mjs +0 -1
- package/src/next/imports.mjs +0 -1
- package/src/next/index.mjs +12 -15
- package/src/next/layers/components.mjs +30 -0
- package/src/next/layers/hooks.mjs +31 -0
- package/src/next/layers/layouts.mjs +12 -0
- package/src/next/tailwindcss.mjs +0 -21
- package/src/node/index.mjs +1 -2
- package/src/common/imports.mjs +0 -457
- package/src/common/layers.mjs +0 -158
- package/src/common/naming.mjs +0 -347
- package/src/deno/imports.mjs +0 -90
- package/src/next/layouts.mjs +0 -18
- package/src/next/naming.mjs +0 -58
|
@@ -1,58 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce the canonical entry template for `**\/entries/*.ts` exports.
|
|
3
|
-
*
|
|
4
|
-
* Two body shapes are accepted:
|
|
5
|
-
*
|
|
6
|
-
* - **Pattern A** (read / mutation entries): body is a single try/catch.
|
|
7
|
-
* - **Pattern B** (redirect entries): body contains exactly one try/catch and
|
|
8
|
-
* ends with a terminal Next.js navigation call (`redirect`, `notFound`,
|
|
9
|
-
* `permanentRedirect`) — placed *outside* try/catch per the Next.js docs,
|
|
10
|
-
* since these helpers throw `NEXT_REDIRECT` / `NEXT_NOT_FOUND` and must not
|
|
11
|
-
* be intercepted by the entry's own catch. Pattern B does not require a
|
|
12
|
-
* `return { data, error: null }` in the try block (success is the redirect).
|
|
13
|
-
*
|
|
14
|
-
* Both patterns share the same try/catch contract:
|
|
15
|
-
*
|
|
16
|
-
* - try first statement: `logger.info(<obj>, "Start <funcName>")`
|
|
17
|
-
* - try success return preceded by: `logger.info(<obj>, "Success <funcName>")`
|
|
18
|
-
* (Pattern A only — Pattern B's success path terminates via redirect)
|
|
19
|
-
* - try failed branch (when present): `logger.error(<obj>, "Failed <funcName>")`
|
|
20
|
-
* followed by a return with the proper error shape
|
|
21
|
-
* - catch param: `error: unknown`
|
|
22
|
-
* - catch first statement: `logger.error(<obj>, "Unexpected error in <funcName>")`
|
|
23
|
-
* - catch return error.message must be the literal "An unexpected error occurred"
|
|
24
|
-
* - every log object must include the `err` key first (when applicable) and
|
|
25
|
-
* propagate all function input parameters as values
|
|
26
|
-
*
|
|
27
|
-
* Why one rule with many messageIds: each invariant is a small rule
|
|
28
|
-
* conceptually, but they share the same structural traversal and access to
|
|
29
|
-
* funcName / inputArgs. Splitting would duplicate the AST walk.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
1
|
const CATCH_RETURN_MESSAGE = "An unexpected error occurred";
|
|
33
|
-
const TERMINAL_CALLEES = new Set([
|
|
34
|
-
"redirect",
|
|
35
|
-
"permanentRedirect",
|
|
36
|
-
"notFound",
|
|
37
|
-
]);
|
|
2
|
+
const TERMINAL_CALLEES = new Set(["redirect", "permanentRedirect", "notFound"]);
|
|
38
3
|
|
|
39
|
-
/**
|
|
40
|
-
* Param identifier names that are excluded from log propagation. These hold
|
|
41
|
-
* secrets that must never be written to logs (Vercel logs are forwarded to
|
|
42
|
-
* external drains, so treating them as sensitive is the conservative default).
|
|
43
|
-
*/
|
|
44
4
|
const REDACT_PARAM_NAMES = new Set([
|
|
45
5
|
"password",
|
|
46
6
|
"newPassword",
|
|
47
7
|
"currentPassword",
|
|
48
8
|
]);
|
|
49
9
|
|
|
50
|
-
/**
|
|
51
|
-
* Param TypeScript type names that are excluded from log propagation. Supabase
|
|
52
|
-
* credential types contain `password` as a field; logging the whole param leaks
|
|
53
|
-
* the secret. Listed types are matched on the type annotation's identifier
|
|
54
|
-
* name (no type-info resolution; aliases must match by name).
|
|
55
|
-
*/
|
|
56
10
|
const REDACT_PARAM_TYPES = new Set([
|
|
57
11
|
"SignUpWithPasswordCredentials",
|
|
58
12
|
"SignInWithPasswordCredentials",
|
|
@@ -91,7 +45,8 @@ function isLoggerCall(node, level) {
|
|
|
91
45
|
|
|
92
46
|
function getStringLiteralArg(callExpr, index) {
|
|
93
47
|
const arg = callExpr.arguments[index];
|
|
94
|
-
if (arg?.type === "Literal" && typeof arg.value === "string")
|
|
48
|
+
if (arg?.type === "Literal" && typeof arg.value === "string")
|
|
49
|
+
return arg.value;
|
|
95
50
|
return null;
|
|
96
51
|
}
|
|
97
52
|
|
|
@@ -112,7 +67,10 @@ function objectContainsValue(objExpr, identifierName) {
|
|
|
112
67
|
) {
|
|
113
68
|
return true;
|
|
114
69
|
}
|
|
115
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
prop.value.type === "Identifier" &&
|
|
72
|
+
prop.value.name === identifierName
|
|
73
|
+
) {
|
|
116
74
|
return true;
|
|
117
75
|
}
|
|
118
76
|
}
|
|
@@ -124,10 +82,10 @@ function firstPropertyIsErrKey(objExpr, errorIdentifierName) {
|
|
|
124
82
|
const first = objExpr.properties[0];
|
|
125
83
|
if (first.type !== "Property") return false;
|
|
126
84
|
if (first.key.type !== "Identifier" || first.key.name !== "err") return false;
|
|
127
|
-
// value must be the catch error identifier (or any Identifier — we accept both
|
|
128
|
-
// `err: error` and `err: result.error` since Failed Pattern C uses MemberExpression)
|
|
129
85
|
if (first.value.type === "Identifier") {
|
|
130
|
-
return errorIdentifierName
|
|
86
|
+
return errorIdentifierName
|
|
87
|
+
? first.value.name === errorIdentifierName
|
|
88
|
+
: true;
|
|
131
89
|
}
|
|
132
90
|
if (first.value.type === "MemberExpression") return true;
|
|
133
91
|
return false;
|
|
@@ -201,7 +159,6 @@ function checkLogCall({
|
|
|
201
159
|
}
|
|
202
160
|
|
|
203
161
|
function isReturnDataErrorNull(ret) {
|
|
204
|
-
// `return { data: ..., error: null }` (data shorthand or explicit)
|
|
205
162
|
const arg = ret.argument;
|
|
206
163
|
if (arg?.type !== "ObjectExpression") return false;
|
|
207
164
|
let hasData = false;
|
|
@@ -230,8 +187,12 @@ function getReturnErrorMessageLiteral(ret) {
|
|
|
230
187
|
if (prop.value.type !== "ObjectExpression") return null;
|
|
231
188
|
for (const inner of prop.value.properties) {
|
|
232
189
|
if (inner.type !== "Property") continue;
|
|
233
|
-
if (inner.key.type !== "Identifier" || inner.key.name !== "message")
|
|
234
|
-
|
|
190
|
+
if (inner.key.type !== "Identifier" || inner.key.name !== "message")
|
|
191
|
+
continue;
|
|
192
|
+
if (
|
|
193
|
+
inner.value.type === "Literal" &&
|
|
194
|
+
typeof inner.value.value === "string"
|
|
195
|
+
) {
|
|
235
196
|
return inner.value.value;
|
|
236
197
|
}
|
|
237
198
|
return "<non-literal>";
|
|
@@ -283,7 +244,6 @@ function endsWithTerminal(node) {
|
|
|
283
244
|
}
|
|
284
245
|
|
|
285
246
|
function caseEndsWithTerminal(switchCase, allCases, idx) {
|
|
286
|
-
// Empty consequent = fallthrough; inherit next case's terminator.
|
|
287
247
|
if (switchCase.consequent.length === 0) {
|
|
288
248
|
const next = allCases[idx + 1];
|
|
289
249
|
if (!next) return false;
|
|
@@ -311,11 +271,14 @@ function classifyBody(body) {
|
|
|
311
271
|
|
|
312
272
|
function checkTryBlock(context, tryBlock, funcName, inputArgNames, options) {
|
|
313
273
|
if (tryBlock.body.length === 0) {
|
|
314
|
-
context.report({
|
|
274
|
+
context.report({
|
|
275
|
+
node: tryBlock,
|
|
276
|
+
messageId: "tryEmpty",
|
|
277
|
+
data: { funcName },
|
|
278
|
+
});
|
|
315
279
|
return;
|
|
316
280
|
}
|
|
317
281
|
|
|
318
|
-
// Start log: first statement
|
|
319
282
|
const first = tryBlock.body[0];
|
|
320
283
|
if (!isExpressionStatementWithLoggerCall(first, "info")) {
|
|
321
284
|
context.report({
|
|
@@ -337,16 +300,12 @@ function checkTryBlock(context, tryBlock, funcName, inputArgNames, options) {
|
|
|
337
300
|
});
|
|
338
301
|
}
|
|
339
302
|
|
|
340
|
-
// Walk body to find Success returns and Failed branches
|
|
341
303
|
let successFound = false;
|
|
342
304
|
for (let i = 0; i < tryBlock.body.length; i++) {
|
|
343
305
|
const stmt = tryBlock.body[i];
|
|
344
306
|
|
|
345
|
-
// Success log + return
|
|
346
307
|
if (stmt.type === "ReturnStatement" && isReturnDataErrorNull(stmt)) {
|
|
347
308
|
successFound = true;
|
|
348
|
-
// The previous non-ExpressionStatement non-IfStatement statement should be
|
|
349
|
-
// the Success log. Walk back to find it.
|
|
350
309
|
const prev = findPrecedingLoggerCall(tryBlock.body, i);
|
|
351
310
|
if (
|
|
352
311
|
!prev ||
|
|
@@ -373,7 +332,6 @@ function checkTryBlock(context, tryBlock, funcName, inputArgNames, options) {
|
|
|
373
332
|
}
|
|
374
333
|
}
|
|
375
334
|
|
|
376
|
-
// Failed branches inside if statements
|
|
377
335
|
if (stmt.type === "IfStatement") {
|
|
378
336
|
checkFailedBranch(context, stmt, funcName, inputArgNames);
|
|
379
337
|
}
|
|
@@ -396,7 +354,6 @@ function findPrecedingLoggerCall(body, returnIndex) {
|
|
|
396
354
|
s.type === "ExpressionStatement" &&
|
|
397
355
|
s.expression.type === "AwaitExpression"
|
|
398
356
|
) {
|
|
399
|
-
// `await revalidatePath(...)` etc — keep walking
|
|
400
357
|
continue;
|
|
401
358
|
}
|
|
402
359
|
if (s.type === "ExpressionStatement") {
|
|
@@ -409,16 +366,13 @@ function findPrecedingLoggerCall(body, returnIndex) {
|
|
|
409
366
|
}
|
|
410
367
|
|
|
411
368
|
function checkFailedBranch(context, ifStmt, funcName, inputArgNames) {
|
|
412
|
-
// We only validate IFs that look like Failed branches: contain a return whose
|
|
413
|
-
// error.message is a string literal (not the catch's "An unexpected ..." literal).
|
|
414
369
|
const consequent = ifStmt.consequent;
|
|
415
370
|
if (consequent.type !== "BlockStatement") return;
|
|
416
371
|
const ret = consequent.body.find((s) => s.type === "ReturnStatement");
|
|
417
372
|
if (!ret) return;
|
|
418
373
|
const errMsg = getReturnErrorMessageLiteral(ret);
|
|
419
|
-
if (errMsg === null) return;
|
|
374
|
+
if (errMsg === null) return;
|
|
420
375
|
|
|
421
|
-
// Must have logger.error("Failed <funcName>") preceding the return
|
|
422
376
|
const idx = consequent.body.indexOf(ret);
|
|
423
377
|
let loggerCall = null;
|
|
424
378
|
for (let j = 0; j < idx; j++) {
|
|
@@ -440,7 +394,7 @@ function checkFailedBranch(context, ifStmt, funcName, inputArgNames) {
|
|
|
440
394
|
return;
|
|
441
395
|
}
|
|
442
396
|
|
|
443
|
-
const isPatternC = errMsg === "<non-literal>";
|
|
397
|
+
const isPatternC = errMsg === "<non-literal>";
|
|
444
398
|
checkLogCall({
|
|
445
399
|
context,
|
|
446
400
|
callExpr: loggerCall,
|
|
@@ -471,7 +425,11 @@ function checkCatchClause(context, handler, funcName, inputArgNames) {
|
|
|
471
425
|
}
|
|
472
426
|
const block = handler.body;
|
|
473
427
|
if (block.body.length === 0) {
|
|
474
|
-
context.report({
|
|
428
|
+
context.report({
|
|
429
|
+
node: block,
|
|
430
|
+
messageId: "catchEmpty",
|
|
431
|
+
data: { funcName },
|
|
432
|
+
});
|
|
475
433
|
return;
|
|
476
434
|
}
|
|
477
435
|
const first = block.body[0];
|
|
@@ -495,7 +453,6 @@ function checkCatchClause(context, handler, funcName, inputArgNames) {
|
|
|
495
453
|
});
|
|
496
454
|
}
|
|
497
455
|
|
|
498
|
-
// Last statement must be a return whose error.message is the catch literal
|
|
499
456
|
const last = block.body[block.body.length - 1];
|
|
500
457
|
if (last?.type !== "ReturnStatement") {
|
|
501
458
|
context.report({
|
|
@@ -510,7 +467,11 @@ function checkCatchClause(context, handler, funcName, inputArgNames) {
|
|
|
510
467
|
context.report({
|
|
511
468
|
node: last,
|
|
512
469
|
messageId: "catchWrongReturnMessage",
|
|
513
|
-
data: {
|
|
470
|
+
data: {
|
|
471
|
+
funcName,
|
|
472
|
+
expected: CATCH_RETURN_MESSAGE,
|
|
473
|
+
actual: msg ?? "<missing>",
|
|
474
|
+
},
|
|
514
475
|
});
|
|
515
476
|
}
|
|
516
477
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Extract table names from Supabase generated types file.
|
|
6
|
-
* Looks for top-level keys under `Tables: {` inside the `public` schema.
|
|
7
|
-
* Uses brace counting to handle deeply nested type definitions.
|
|
8
|
-
*/
|
|
9
4
|
function extractTableNames(supabaseTypePath) {
|
|
10
5
|
if (!fs.existsSync(supabaseTypePath)) {
|
|
11
6
|
return [];
|
|
@@ -13,7 +8,6 @@ function extractTableNames(supabaseTypePath) {
|
|
|
13
8
|
|
|
14
9
|
const content = fs.readFileSync(supabaseTypePath, "utf-8");
|
|
15
10
|
|
|
16
|
-
// Find `public:` excluding `graphql_public:` via negative lookbehind
|
|
17
11
|
const publicMatch = /(?<!\w)public:\s*\{/.exec(content);
|
|
18
12
|
if (!publicMatch) {
|
|
19
13
|
return [];
|
|
@@ -25,13 +19,11 @@ function extractTableNames(supabaseTypePath) {
|
|
|
25
19
|
return [];
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
// Find the opening brace of `Tables: {`
|
|
29
22
|
const braceStart = content.indexOf("{", tablesIdx + tablesLabel.length);
|
|
30
23
|
if (braceStart === -1) {
|
|
31
24
|
return [];
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
// Extract the Tables block using brace counting
|
|
35
27
|
let depth = 0;
|
|
36
28
|
let blockEnd = -1;
|
|
37
29
|
for (let i = braceStart; i < content.length; i++) {
|
|
@@ -46,14 +38,12 @@ function extractTableNames(supabaseTypePath) {
|
|
|
46
38
|
return [];
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
// Extract top-level keys (depth 0) inside the Tables block
|
|
50
41
|
const tablesBlock = content.slice(braceStart + 1, blockEnd);
|
|
51
42
|
const names = [];
|
|
52
43
|
depth = 0;
|
|
53
44
|
const keyRegex = /(\w+)\s*:/g;
|
|
54
45
|
let match;
|
|
55
46
|
while ((match = keyRegex.exec(tablesBlock)) !== null) {
|
|
56
|
-
// Count braces before this match to determine depth
|
|
57
47
|
const preceding = tablesBlock.slice(0, match.index);
|
|
58
48
|
let d = 0;
|
|
59
49
|
for (const ch of preceding) {
|
|
@@ -67,15 +57,10 @@ function extractTableNames(supabaseTypePath) {
|
|
|
67
57
|
return names;
|
|
68
58
|
}
|
|
69
59
|
|
|
70
|
-
/** Convert snake_case to kebab-case. */
|
|
71
60
|
function toKebab(name) {
|
|
72
61
|
return name.replace(/_/g, "-");
|
|
73
62
|
}
|
|
74
63
|
|
|
75
|
-
/**
|
|
76
|
-
* Enforce that feature directory names match allowed values:
|
|
77
|
-
* "shared", "auth", plus Supabase table names converted to kebab-case.
|
|
78
|
-
*/
|
|
79
64
|
export const featureNameRule = {
|
|
80
65
|
meta: {
|
|
81
66
|
type: "problem",
|
|
@@ -107,14 +92,15 @@ export const featureNameRule = {
|
|
|
107
92
|
if (!featureName) return {};
|
|
108
93
|
|
|
109
94
|
const projectRoot = filename.slice(0, rootIdx).replace(/\/src$/, "");
|
|
110
|
-
// Prefer the Supabase types file adjacent to `featureRoot` (e.g. `src/lib/...`
|
|
111
|
-
// for `src/features`). Fall back to `src/lib/...` at the project root so that
|
|
112
|
-
// non-`src` feature roots (e.g. `scripts/features`) can reuse the same
|
|
113
|
-
// generated types without duplicating the file. Both `types.ts` (plural) and
|
|
114
|
-
// `type.ts` (singular) are accepted to match either naming convention.
|
|
115
95
|
const candidateTypePaths = [
|
|
116
|
-
path.join(
|
|
117
|
-
|
|
96
|
+
path.join(
|
|
97
|
+
projectRoot,
|
|
98
|
+
featureRoot.replace(/features$/, "lib/supabase/types.ts"),
|
|
99
|
+
),
|
|
100
|
+
path.join(
|
|
101
|
+
projectRoot,
|
|
102
|
+
featureRoot.replace(/features$/, "lib/supabase/type.ts"),
|
|
103
|
+
),
|
|
118
104
|
path.join(projectRoot, "src/lib/supabase/types.ts"),
|
|
119
105
|
path.join(projectRoot, "src/lib/supabase/type.ts"),
|
|
120
106
|
];
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce {Verb}{Subject}FormState pattern for FormState type names.
|
|
3
|
-
*
|
|
4
|
-
* Targets TSInterfaceDeclaration and TSTypeAliasDeclaration whose name ends
|
|
5
|
-
* with "FormState". Requires at least two PascalCase words before FormState
|
|
6
|
-
* (e.g. SignInFormState, CreateCommentFormState) so the verb prefix is never
|
|
7
|
-
* omitted. Single-noun names like "ContactFormState" are forbidden — rename
|
|
8
|
-
* to "CreateContactFormState" to make intent explicit.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
const FORM_STATE_ALLOW = /^[A-Z][a-z]+[A-Z]\w*FormState$/;
|
|
12
2
|
|
|
13
3
|
function reportIfInvalid(context, idNode) {
|
|
@@ -1,37 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce the canonical `{ data, error: { message } }` shape for FormState types.
|
|
3
|
-
*
|
|
4
|
-
* Targets `TSInterfaceDeclaration` and `TSTypeAliasDeclaration` whose name ends
|
|
5
|
-
* with `FormState`. Required shape:
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* interface XxxFormState {
|
|
9
|
-
* data: T | null; // T may be any type; `data: null` literal also OK
|
|
10
|
-
* error: { message: string } | null;
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Why this shape:
|
|
15
|
-
*
|
|
16
|
-
* - Single uniform shape lets entry / hook / UI be templated and lint-checked.
|
|
17
|
-
* - Forbids `code` / `status` / similar discriminator fields that tend to grow
|
|
18
|
-
* defensive branches (e.g. `error.code === "unauthenticated"`) which usually
|
|
19
|
-
* indicate a missing upstream guard (route gate, button conditional render),
|
|
20
|
-
* not a legitimate need for in-action discrimination.
|
|
21
|
-
* - Discriminated unions (`{ data: T; error: null } | { data: null; error: ... }`)
|
|
22
|
-
* are rejected for the same reason — they leak shape complexity into hooks
|
|
23
|
-
* (`useActionState<T | null>`), components (`state?.error`), and entries.
|
|
24
|
-
*
|
|
25
|
-
* Future extension when Stripe / payment libraries actually need `code` / `status`:
|
|
26
|
-
*
|
|
27
|
-
* - a) Add a `// allow-error-code: <reason>` comment opt-out to this rule, so
|
|
28
|
-
* individual FormStates can justify their extra field on the previous line.
|
|
29
|
-
* - b) Change the rule to whitelist a fixed set of allowed extra fields (enum
|
|
30
|
-
* of standard error codes shared across the codebase).
|
|
31
|
-
*
|
|
32
|
-
* Until that need materializes, this rule is strict (no opt-out) per YAGNI.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
1
|
const FORM_STATE_SUFFIX = "FormState";
|
|
36
2
|
|
|
37
3
|
function isNullLiteralType(node) {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Enforce import path style within features:
|
|
5
|
-
* - Same-feature imports must use relative paths
|
|
6
|
-
* - Cross-feature imports must use @/ alias
|
|
7
|
-
*/
|
|
8
3
|
export const importPathStyleRule = {
|
|
9
4
|
meta: {
|
|
10
5
|
type: "problem",
|
|
@@ -48,7 +43,6 @@ export const importPathStyleRule = {
|
|
|
48
43
|
if (!source || typeof source.value !== "string") return;
|
|
49
44
|
const importPath = source.value;
|
|
50
45
|
|
|
51
|
-
// Same-feature alias should be a relative path for consistency.
|
|
52
46
|
if (
|
|
53
47
|
importPath.startsWith(sameFeaturePrefix) ||
|
|
54
48
|
importPath === sameFeatureExact
|
|
@@ -61,7 +55,6 @@ export const importPathStyleRule = {
|
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
// Cross-feature relative path should use @/ alias for clarity.
|
|
65
58
|
if (importPath.startsWith(".")) {
|
|
66
59
|
const resolved = path.resolve(path.dirname(filename), importPath);
|
|
67
60
|
if (
|
|
@@ -13,7 +13,6 @@ import { schemaNamingRule } from "./schema-naming.mjs";
|
|
|
13
13
|
import { supabaseColumnsSatisfiesRule } from "./supabase-columns-satisfies.mjs";
|
|
14
14
|
import { supabaseSelectTypedColumnsRule } from "./supabase-select-typed-columns.mjs";
|
|
15
15
|
|
|
16
|
-
/** Single plugin object to avoid ESLint "Cannot redefine plugin" errors. */
|
|
17
16
|
export const localPlugin = {
|
|
18
17
|
rules: {
|
|
19
18
|
"entry-single-service-call": entrySingleServiceCallRule,
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Forbid decoration utility classes on the `<main>` element.
|
|
3
|
-
*
|
|
4
|
-
* Design philosophy: `app/**\/layout.tsx` の `<main>` は Header / Footer の
|
|
5
|
-
* 縦積みを受け持つ構造スロット。装飾(余白・間隔)は page.tsx 側の Container 等が
|
|
6
|
-
* 持つべき。main に padding / margin / gap を直接当てると、page 全体に暗黙の
|
|
7
|
-
* オフセットが生まれ、page ごとの調整余地が失われる。
|
|
8
|
-
*
|
|
9
|
-
* Disallowed Tailwind token prefixes (case-sensitive):
|
|
10
|
-
*
|
|
11
|
-
* - `p`, `m`, `py`, `px`, `pt`, `pb`, `pl`, `pr`, `my`, `mx`, `mt`, `mb`, `ml`, `mr` — padding / margin
|
|
12
|
-
* - `space-x`, `space-y` — sibling spacing
|
|
13
|
-
* - `gap` — flex / grid gap
|
|
14
|
-
*
|
|
15
|
-
* Allowed: structural utilities (`flex`, `flex-1`, `flex-col`, `min-h-*`,
|
|
16
|
-
* `block`, `relative`, etc.)
|
|
17
|
-
*
|
|
18
|
-
* className value forms supported: string Literal, TemplateLiteral,
|
|
19
|
-
* `cn(...)` / `clsx(...)` style CallExpression args (string args only).
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
1
|
const DISALLOWED_TOKEN = /^(?:[pm][xytrbl]?-|space-[xy]-|gap-)/;
|
|
23
2
|
|
|
24
3
|
function collectStringLiterals(node, out) {
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce consistent naming for `import * as` namespace imports
|
|
3
|
-
* within feature-based architecture.
|
|
4
|
-
*
|
|
5
|
-
* Convention: import * as {featureName}{Scope}{Layer} from "{path}/{layerDir}/{scope}"
|
|
6
|
-
*
|
|
7
|
-
* Layer はファイル名 suffix ではなくディレクトリ名 (`queries/` / `services/` 等) から識別する。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** @type {Record<string, string>} */
|
|
11
1
|
const LAYER_DIR_MAP = {
|
|
12
2
|
queries: "Query",
|
|
13
3
|
services: "Service",
|
|
@@ -19,39 +9,27 @@ const LAYER_DIR_MAP = {
|
|
|
19
9
|
constants: "Constant",
|
|
20
10
|
};
|
|
21
11
|
|
|
22
|
-
/** Convert a snake_case or kebab-case string to camelCase. */
|
|
23
12
|
function toCamelCase(str) {
|
|
24
13
|
return str.replace(/[-_]+(.)/g, (_, c) => c.toUpperCase());
|
|
25
14
|
}
|
|
26
15
|
|
|
27
|
-
/** Convert a snake_case or kebab-case string to PascalCase. */
|
|
28
16
|
function toPascalCase(str) {
|
|
29
17
|
const camel = toCamelCase(str);
|
|
30
18
|
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
31
19
|
}
|
|
32
20
|
|
|
33
|
-
/**
|
|
34
|
-
* Parse import source to extract featureName, scope, and layer:
|
|
35
|
-
*
|
|
36
|
-
* - feature root 内の path のみを対象とする (外部 lib / shared / 相対インポートで feature 外に行くものは無視)
|
|
37
|
-
* - segments は `[feature, layerDir, ..., file]` の形式を想定し、末尾要素を scope として取り出す
|
|
38
|
-
* - layerDir が LAYER_DIR_MAP に無い場合は対象外
|
|
39
|
-
*/
|
|
40
21
|
function parseImportSource(importPath, featureRoot) {
|
|
41
|
-
// Normalize alias: @/features/... → features/...
|
|
42
22
|
let normalized = importPath;
|
|
43
23
|
const aliasBase = featureRoot.replace(/^src\//, "@/");
|
|
44
24
|
if (normalized.startsWith(aliasBase + "/")) {
|
|
45
25
|
normalized = featureRoot + normalized.slice(aliasBase.length);
|
|
46
26
|
}
|
|
47
27
|
|
|
48
|
-
// Only process paths within the feature root
|
|
49
28
|
const rootPrefix = featureRoot + "/";
|
|
50
29
|
const rootIdx = normalized.indexOf(rootPrefix);
|
|
51
30
|
if (rootIdx === -1) return null;
|
|
52
31
|
|
|
53
32
|
const afterRoot = normalized.slice(rootIdx + rootPrefix.length);
|
|
54
|
-
// Expected: {feature}/{layerDir}/{scope}
|
|
55
33
|
const segments = afterRoot.split("/");
|
|
56
34
|
if (segments.length < 3) return null;
|
|
57
35
|
|
|
@@ -65,7 +43,6 @@ function parseImportSource(importPath, featureRoot) {
|
|
|
65
43
|
return { featureDir, scope, layer };
|
|
66
44
|
}
|
|
67
45
|
|
|
68
|
-
/** Build the expected namespace import name. */
|
|
69
46
|
function buildExpectedName(featureDir, scope, layer) {
|
|
70
47
|
const featureCamel = toCamelCase(featureDir);
|
|
71
48
|
const scopePascal = toPascalCase(scope);
|
|
@@ -96,7 +73,6 @@ export const namespaceImportNameRule = {
|
|
|
96
73
|
|
|
97
74
|
return {
|
|
98
75
|
ImportDeclaration(node) {
|
|
99
|
-
// Only check namespace imports: import * as Name
|
|
100
76
|
const nsSpecifier = node.specifiers.find(
|
|
101
77
|
(s) => s.type === "ImportNamespaceSpecifier",
|
|
102
78
|
);
|
|
@@ -104,7 +80,6 @@ export const namespaceImportNameRule = {
|
|
|
104
80
|
|
|
105
81
|
const importPath = node.source.value;
|
|
106
82
|
|
|
107
|
-
// Skip external/built-in imports (only check relative and alias)
|
|
108
83
|
if (
|
|
109
84
|
!importPath.startsWith("./") &&
|
|
110
85
|
!importPath.startsWith("../") &&
|
|
@@ -113,7 +88,6 @@ export const namespaceImportNameRule = {
|
|
|
113
88
|
return;
|
|
114
89
|
}
|
|
115
90
|
|
|
116
|
-
// For relative imports, resolve to an absolute-like path for parsing
|
|
117
91
|
let resolvedPath = importPath;
|
|
118
92
|
if (importPath.startsWith(".")) {
|
|
119
93
|
const fileDir = context.filename.replace(/\/[^/]+$/, "");
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Exported function の return type が any を含んでいる場合に error:
|
|
5
|
-
*
|
|
6
|
-
* - typescript-eslint の type checker を使って inferred type まで見る
|
|
7
|
-
* - queries / services の API 境界を any 汚染から守ることで、domain shape が型で保証される
|
|
8
|
-
* - Promise<any>, Promise<{ data: any }>, Array<any> など nested も展開して検査する
|
|
9
|
-
*/
|
|
10
3
|
export const noAnyReturnRule = {
|
|
11
4
|
meta: {
|
|
12
5
|
type: "problem",
|
|
@@ -41,7 +34,6 @@ export const noAnyReturnRule = {
|
|
|
41
34
|
return checker.getReturnTypeOfSignature(signature);
|
|
42
35
|
};
|
|
43
36
|
|
|
44
|
-
// `any` を type tree 全体で検出する (Promise<any>, { a: any }, any[] 等を展開)
|
|
45
37
|
const containsAny = (type, seen = new Set()) => {
|
|
46
38
|
if (!type) return false;
|
|
47
39
|
if (seen.has(type)) return false;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce verb allow list for `queries/*.ts` exports:
|
|
3
|
-
*
|
|
4
|
-
* - The queries layer is the TS-idiomatic translation of Rails 5 actions
|
|
5
|
-
* (index/show -> get, create, update, destroy -> delete)
|
|
6
|
-
* - Auth ceremonies (signUp / signIn / signOut) are admitted as industry-standard exceptions
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
1
|
const QUERIES_ALLOW = /^(get|create|update|delete|signUp|signIn|signOut)([A-Z]|$)/;
|
|
10
2
|
|
|
11
3
|
function isFunctionLike(initNode) {
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce namespace imports for files under `queries/`:
|
|
3
|
-
*
|
|
4
|
-
* - Value imports must use `import * as xxxQuery from "..."` so that the
|
|
5
|
-
* `naming/namespace-import-name` rule can guarantee a single canonical
|
|
6
|
-
* binding (e.g. `comicsServerQuery.getComics`)
|
|
7
|
-
* - Type-only imports are exempted because they have no runtime presence
|
|
8
|
-
* - 検出は path に `/queries/<name>` が含まれることのみで行い、suffix には依存しない
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
const QUERIES_PATH = /\/queries\/[^/]+$/;
|
|
12
2
|
|
|
13
3
|
export const queriesNamespaceImportRule = {
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce that exported variables in schema files use camelCase with a "Schema" suffix.
|
|
3
|
-
* e.g., `export const userSchema = z.object(...)` is valid.
|
|
4
|
-
* `export const UserSchema = ...` or `export const user = ...` are invalid.
|
|
5
|
-
* `export type` declarations are ignored (used for `z.infer` types).
|
|
6
|
-
*/
|
|
7
1
|
export const schemaNamingRule = {
|
|
8
2
|
meta: {
|
|
9
3
|
type: "problem",
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce `<string literal> as const` for `*_COLUMNS` constant declarations.
|
|
3
|
-
*
|
|
4
|
-
* Apply to `**\/queries/*.ts` and `**\/constants/*.ts`.
|
|
5
|
-
*
|
|
6
|
-
* `*_COLUMNS` 定数は Supabase の `.select()` に直接渡される。`as const` を
|
|
7
|
-
* 外すと TypeScript が `string` に widen し、Supabase の `.select<Query>()`
|
|
8
|
-
* が literal を parse できなくなって row 型推論が壊れる(戻り値が
|
|
9
|
-
* `GenericStringError` になる)。
|
|
10
|
-
*
|
|
11
|
-
* Allowed:
|
|
12
|
-
* const POST_DETAIL_COLUMNS = "id,url,platform" as const;
|
|
13
|
-
*
|
|
14
|
-
* Banned:
|
|
15
|
-
* const POST_DETAIL_COLUMNS = "id,url,platform"; // string に widen
|
|
16
|
-
* const POST_DETAIL_COLUMNS = ["id", "url"] as const; // 配列
|
|
17
|
-
* const POST_DETAIL_COLUMNS = [...] as const satisfies ...; // 配列 + satisfies
|
|
18
|
-
* const POST_DETAIL_COLUMNS = `id,${col}`; // template literal
|
|
19
|
-
*
|
|
20
|
-
* Why: シンプルな string literal を `as const` で保つだけで、Supabase の
|
|
21
|
-
* 型推論(row 型 / column 名タイポ検出)はすべて自動で効く。runtime helper
|
|
22
|
-
* (`joinColumns` 等)は不要。
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
1
|
const COLUMNS_NAME = /^[A-Z][A-Z0-9_]*_COLUMNS$/;
|
|
26
2
|
|
|
27
3
|
function isStringAsConst(initNode) {
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforce explicit column lists for Supabase `.select()` calls.
|
|
3
|
-
*
|
|
4
|
-
* Apply to `**\/queries/*.ts`. `.select()` の引数は次のいずれかでなければならない:
|
|
5
|
-
*
|
|
6
|
-
* - inline string literal(例: `.select("id,url,platform")`)
|
|
7
|
-
* - `*_COLUMNS` という UPPER_SNAKE 命名の identifier(例: `.select(POST_DETAIL_COLUMNS)`)
|
|
8
|
-
*
|
|
9
|
-
* `*_COLUMNS` 定数は companion rule `supabase-columns-satisfies` で
|
|
10
|
-
* `<string literal> as const` の形が強制される。これにより:
|
|
11
|
-
*
|
|
12
|
-
* - Supabase の `.select()` は literal string を parse して row 型を推論できる
|
|
13
|
-
* - 存在しない column 名は Supabase の型推論が `SelectQueryError` として弾く(compile time)
|
|
14
|
-
* - runtime helper(`joinColumns`)は不要
|
|
15
|
-
*
|
|
16
|
-
* Banned:
|
|
17
|
-
* .select() implicit "all columns"
|
|
18
|
-
* .select("*") silent exposure of new schema columns
|
|
19
|
-
* .select(`${x},y`) dynamic concatenation
|
|
20
|
-
* .select(cols.join(",")) runtime expression
|
|
21
|
-
* .select(someVar) non-conforming variable
|
|
22
|
-
*
|
|
23
|
-
* Allowed:
|
|
24
|
-
* .select("id,url,platform") inline literal
|
|
25
|
-
* .select(POST_DETAIL_COLUMNS) *_COLUMNS named constant
|
|
26
|
-
*
|
|
27
|
-
* Why: column lists must be (1) statically analyzable for grep / review,
|
|
28
|
-
* (2) literal so Supabase can infer the row shape, (3) never silently grow
|
|
29
|
-
* on schema additions. For column-level access control, use Postgres views
|
|
30
|
-
* (`from("posts_public")`).
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
1
|
const COLUMNS_NAME = /^[A-Z][A-Z0-9_]*_COLUMNS$/;
|
|
34
2
|
|
|
35
3
|
export const supabaseSelectTypedColumnsRule = {
|