@cosmicdrift/kumiko-guards 0.413.1 → 0.415.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/README.md +15 -9
- package/package.json +4 -4
- package/src/_lib/agent-docs-api-nodes.ts +9 -2
- package/src/_lib/agent-docs-api-render.ts +31 -10
- package/src/_lib/agent-docs-api.ts +13 -9
- package/src/_lib/agent-docs-feature-imports.ts +12 -1
- package/src/_lib/baseline-compare.ts +1 -2
- package/src/_lib/doc-status.ts +8 -4
- package/src/_lib/dockerfile.ts +28 -5
- package/src/_lib/escaped-literal.ts +26 -0
- package/src/_lib/npm-registry.ts +2 -2
- package/src/_lib/run-slots.ts +4 -6
- package/src/_lib/security-audit.ts +22 -6
- package/src/_lib/test-es-raw-writes.ts +5 -3
- package/src/changes.json +51 -0
- package/src/check-security.ts +4 -3
- package/src/guard-app-dockerfile.ts +29 -12
- package/src/guard-ignore-tag-reason.ts +18 -4
- package/src/guard-internal-subpath-imports.ts +35 -25
- package/src/guard-rls-session-settings.ts +48 -6
- package/src/guard-schema-cli-features.ts +22 -1
- package/src/guard-security-plugin-suppression.ts +368 -0
- package/src/guard-test-es-row-writes.ts +2 -1
- package/src/guard-unsafe-array-param.ts +4 -7
- package/src/pre-push.sh +46 -6
- package/src/run-guards.ts +2 -28
- package/src/run-repo-checks.ts +0 -6
- package/src/run-steps-parallel.ts +4 -4
- package/src/run-ui-guards.ts +1 -15
- package/src/_lib/german-test-title.ts +0 -94
- package/src/_lib/primitives-access.ts +0 -23
- package/src/check-predicates.ts +0 -244
- package/src/guard-admin-api.ts +0 -138
- package/src/guard-direct-fetch.ts +0 -161
- package/src/guard-error-reasons.ts +0 -210
- package/src/guard-event-store-writes.ts +0 -124
- package/src/guard-i18n-locale-terminology.ts +0 -134
- package/src/guard-no-custom-primitives.ts +0 -193
- package/src/guard-no-date-api.ts +0 -183
- package/src/guard-no-direct-fs.ts +0 -346
- package/src/guard-no-direct-process-env.ts +0 -127
- package/src/guard-no-inline-styles.ts +0 -64
- package/src/guard-no-raw-hooks.ts +0 -80
- package/src/guard-no-temporal-polyfill-import.ts +0 -131
- package/src/guard-primitives-discipline.ts +0 -357
- package/src/guard-raw-classname.ts +0 -117
- package/src/guard-raw-interactive-elements.ts +0 -164
- package/src/guard-restricted-symbols.ts +0 -155
- package/src/guard-silent-skip.ts +0 -186
- package/src/guard-test-es-fixtures.ts +0 -85
- package/src/guard-test-title.ts +0 -159
- package/src/guard-thin-wrappers.ts +0 -471
- package/src/guard-unsafe-json-parse.ts +0 -87
|
@@ -56,17 +56,21 @@ export type AppDockerfileFindings = {
|
|
|
56
56
|
readonly warnings: readonly string[];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
function
|
|
60
|
-
if (bunfigText === undefined) return
|
|
59
|
+
function bunfigScopeEntry(bunfigText: string | undefined): unknown {
|
|
60
|
+
if (bunfigText === undefined) return undefined;
|
|
61
61
|
let parsed: unknown;
|
|
62
62
|
try {
|
|
63
63
|
parsed = Bun.TOML.parse(bunfigText);
|
|
64
64
|
} catch {
|
|
65
|
-
return
|
|
65
|
+
return undefined;
|
|
66
66
|
}
|
|
67
67
|
const install = isPlainObject(parsed) ? parsed["install"] : undefined;
|
|
68
68
|
const scopes = isPlainObject(install) ? install["scopes"] : undefined;
|
|
69
|
-
return isPlainObject(scopes)
|
|
69
|
+
return isPlainObject(scopes) ? scopes[PRIVATE_SCOPE] : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function hasBunfigScope(bunfigText: string | undefined): boolean {
|
|
73
|
+
return bunfigScopeEntry(bunfigText) !== undefined;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// A registry line without an auth token routes the scope to GitHub Packages
|
|
@@ -79,14 +83,27 @@ function hasNpmrcScope(npmrcText: string | undefined): boolean {
|
|
|
79
83
|
);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
function variablesIn(text: string | undefined): string[] {
|
|
87
|
+
return [...(text ?? "").matchAll(SHELL_VARIABLE_RE)].flatMap((match) =>
|
|
88
|
+
match[1] ? [match[1]] : [],
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Only the private scope's own credential counts: a variable for another
|
|
93
|
+
// registry would let a mount of the wrong variable pass the guard.
|
|
94
|
+
function tokenVariablesOf(
|
|
95
|
+
bunfigText: string | undefined,
|
|
96
|
+
npmrcText: string | undefined,
|
|
97
|
+
): Set<string> {
|
|
98
|
+
const scope = bunfigScopeEntry(bunfigText);
|
|
99
|
+
const bunfigToken = isPlainObject(scope) ? scope["token"] : undefined;
|
|
100
|
+
const npmrcAuthLine = /^\s*\/\/npm\.pkg\.github\.com\/:_authToken=(.*)$/m.exec(
|
|
101
|
+
npmrcText ?? "",
|
|
102
|
+
)?.[1];
|
|
103
|
+
return new Set([
|
|
104
|
+
...variablesIn(typeof bunfigToken === "string" ? bunfigToken : undefined),
|
|
105
|
+
...variablesIn(npmrcAuthLine),
|
|
106
|
+
]);
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
function registryAuthViolation(input: AppDockerfileInput, stage: DockerStage): string | undefined {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* Ignore-Tag-Reason Guard: every `kumiko-lint-ignore <slug> <reason>` comment states a real reason.
|
|
3
|
+
* Ignore-Tag-Reason Guard: every `kumiko-lint-ignore <slug> <reason>` and `biome-ignore[-all|-start] <rule>: <reason>` comment states a real reason.
|
|
4
4
|
* A missing reason, a generic one (`todo`, `legacy`, ...) or one shorter than three words ("invite-flow")
|
|
5
5
|
* only silences a guard without telling the next reader why the exception is safe. Existing hits are
|
|
6
6
|
* frozen per file in `.kumiko-ignore-tag-reason-baseline.json` and may not grow; without a baseline
|
|
@@ -37,7 +37,11 @@ const SCAN: ScanSpec = {
|
|
|
37
37
|
const EXCLUDE = /(\.d\.(ts|tsx)$|\/dist\/)/;
|
|
38
38
|
const COMMENT_MARKER_PREFIX_RE = /^\s*(?:\/\/+|\/\*+|\*+)?\s*/;
|
|
39
39
|
const COMMENT_CLOSE_SUFFIX_RE = /\s*\*\/\s*\}?\s*$/;
|
|
40
|
-
|
|
40
|
+
// Not anchored: lineHasIgnoreTag honours the tag anywhere in a line, so a prefixed tag must be checked too.
|
|
41
|
+
const TAG_LINE_RE = /\bkumiko-lint-ignore\s+(\S+)(?:\s+(.*))?$/;
|
|
42
|
+
// Only the rules that replaced deleted guards inherit the reason check; other biome-ignore rules never had one.
|
|
43
|
+
const BIOME_TAG_LINE_RE =
|
|
44
|
+
/\bbiome-ignore(?:-all|-start)?\s+(lint\/(?:plugin|style\/(?:noProcessEnv|noInlineStyles|noRestrictedImports|noRestrictedGlobals))\S*?)\s*:\s*(.*)$/;
|
|
41
45
|
|
|
42
46
|
export type WeakIgnoreReason = {
|
|
43
47
|
readonly line: number;
|
|
@@ -53,15 +57,25 @@ function isWeakReason(reason: string): boolean {
|
|
|
53
57
|
return isGenericReason(reason) || reason.split(/\s+/).filter(Boolean).length < MIN_REASON_WORDS;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
function countNewlines(text: string, from: number, to: number): number {
|
|
61
|
+
let count = 0;
|
|
62
|
+
for (let i = text.indexOf("\n", from); i !== -1 && i < to; i = text.indexOf("\n", i + 1)) count++;
|
|
63
|
+
return count;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
export function findWeakIgnoreReasons(fullText: string): WeakIgnoreReason[] {
|
|
57
67
|
const sites: WeakIgnoreReason[] = [];
|
|
68
|
+
let scannedUpTo = 0;
|
|
69
|
+
let firstLine = 1;
|
|
58
70
|
for (const comment of scanCommentTrivia(fullText)) {
|
|
59
|
-
|
|
71
|
+
firstLine += countNewlines(fullText, scannedUpTo, comment.start);
|
|
72
|
+
scannedUpTo = comment.start;
|
|
60
73
|
for (const [offset, rawLine] of comment.text.split("\n").entries()) {
|
|
61
74
|
const body = rawLine
|
|
62
75
|
.replace(COMMENT_MARKER_PREFIX_RE, "")
|
|
63
76
|
.replace(COMMENT_CLOSE_SUFFIX_RE, "");
|
|
64
|
-
const
|
|
77
|
+
const trimmed = body.trim();
|
|
78
|
+
const match = TAG_LINE_RE.exec(trimmed) ?? BIOME_TAG_LINE_RE.exec(trimmed);
|
|
65
79
|
const slug = match?.[1] ?? "";
|
|
66
80
|
const reason = (match?.[2] ?? "").trim();
|
|
67
81
|
const isCheckable = match !== null && !isPlaceholder(slug) && !isPlaceholder(reason);
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* 2. `runInRowLevelSecurityScope`, `runInSystemRowLevelSecurityScope` and
|
|
7
7
|
* `tenantRowLevelSecurityScope` from `@cosmicdrift/kumiko-testing/helpers` are test-only.
|
|
8
8
|
* 3. `runInSystemRowLevelSecurityScope` and `systemScopedRunner` take a non-empty string literal
|
|
9
|
-
* reason, so every system-scope entry stays greppable
|
|
10
|
-
* framework-internal and only used by an allowlist. An object literal passed to
|
|
9
|
+
* reason, so every system-scope entry stays greppable. An object literal passed to
|
|
11
10
|
* `createTenantDb` with `mode: "system"` carries the same kind of `reason`.
|
|
12
11
|
*
|
|
13
12
|
* Usage:
|
|
@@ -16,8 +15,15 @@
|
|
|
16
15
|
* Exit 1 on violations, 0 when clean.
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
type ExportDeclaration,
|
|
20
|
+
type ImportDeclaration,
|
|
21
|
+
Node,
|
|
22
|
+
type SourceFile,
|
|
23
|
+
SyntaxKind,
|
|
24
|
+
} from "ts-morph";
|
|
20
25
|
import { findRepoRootFor } from "./_lib/baseline-compare";
|
|
26
|
+
import { mayContainEscapedLiteral } from "./_lib/escaped-literal";
|
|
21
27
|
import {
|
|
22
28
|
ALL_REPO_KINDS,
|
|
23
29
|
type AstGuard,
|
|
@@ -51,14 +57,6 @@ const REASON_ARG_INDEX: Record<string, number> = {
|
|
|
51
57
|
systemScopedRunner: 1,
|
|
52
58
|
};
|
|
53
59
|
|
|
54
|
-
const FIXED_SCOPE_SYMBOL = "SYSTEM_ROW_LEVEL_SECURITY_SCOPE";
|
|
55
|
-
|
|
56
|
-
const FIXED_SCOPE_ALLOWLIST = [
|
|
57
|
-
/^packages\/framework\/src\/db\/row-level-security-scope\.ts$/,
|
|
58
|
-
/^packages\/framework\/src\/pipeline\/dispatch-scope\.ts$/,
|
|
59
|
-
/^packages\/framework\/src\/db\/migrate-runner\.ts$/,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
60
|
// Exercises the empty-reason rejection, so it passes empty literals on purpose.
|
|
63
61
|
const REASON_RULE_EXEMPT = [
|
|
64
62
|
/^packages\/framework\/src\/db\/__tests__\/row-level-security-scope\.test\.ts$/,
|
|
@@ -76,7 +74,7 @@ type Finding = { line: number; message: string };
|
|
|
76
74
|
// escape could spell a name without its plain text, so any `\u` keeps the walk.
|
|
77
75
|
function mayMention(sf: SourceFile, names: readonly string[]): boolean {
|
|
78
76
|
const text = sf.getFullText();
|
|
79
|
-
return text
|
|
77
|
+
return mayContainEscapedLiteral(text) || names.some((name) => text.includes(name));
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
function isTestFile(rel: string): boolean {
|
|
@@ -99,6 +97,13 @@ function staticSpecifierHead(arg: Node): string | undefined {
|
|
|
99
97
|
return undefined;
|
|
100
98
|
}
|
|
101
99
|
|
|
100
|
+
// `import m = require("x")`
|
|
101
|
+
function requireSpecifierOf(reference: Node): string | undefined {
|
|
102
|
+
if (!Node.isExternalModuleReference(reference)) return undefined;
|
|
103
|
+
const expression = reference.getExpression();
|
|
104
|
+
return expression === undefined ? undefined : staticSpecifierHead(expression);
|
|
105
|
+
}
|
|
106
|
+
|
|
102
107
|
function findInternalImports(sf: SourceFile): Finding[] {
|
|
103
108
|
const findings: Finding[] = [];
|
|
104
109
|
const report = (line: number, specifier: string): void => {
|
|
@@ -113,6 +118,12 @@ function findInternalImports(sf: SourceFile): Finding[] {
|
|
|
113
118
|
report(decl.getStartLineNumber(), specifier);
|
|
114
119
|
}
|
|
115
120
|
}
|
|
121
|
+
for (const decl of sf.getDescendantsOfKind(SyntaxKind.ImportEqualsDeclaration)) {
|
|
122
|
+
const specifier = requireSpecifierOf(decl.getModuleReference());
|
|
123
|
+
if (specifier !== undefined && isInternalSpecifier(specifier)) {
|
|
124
|
+
report(decl.getStartLineNumber(), specifier);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
116
127
|
for (const call of sf.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
117
128
|
const callee = call.getExpression();
|
|
118
129
|
const isDynamicImport = callee.getKind() === SyntaxKind.ImportKeyword;
|
|
@@ -128,6 +139,11 @@ function findInternalImports(sf: SourceFile): Finding[] {
|
|
|
128
139
|
return findings;
|
|
129
140
|
}
|
|
130
141
|
|
|
142
|
+
// `export * from` / `export * as ns from`: no named exports to inspect.
|
|
143
|
+
function isStarReexport(decl: ImportDeclaration | ExportDeclaration): boolean {
|
|
144
|
+
return !("getNamedImports" in decl) && decl.getNamedExports().length === 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
function findTestOnlyScopeImports(sf: SourceFile): Finding[] {
|
|
132
148
|
const findings: Finding[] = [];
|
|
133
149
|
const decls = [
|
|
@@ -136,6 +152,12 @@ function findTestOnlyScopeImports(sf: SourceFile): Finding[] {
|
|
|
136
152
|
];
|
|
137
153
|
for (const decl of decls) {
|
|
138
154
|
if (decl.getModuleSpecifierValue() !== TESTING_HELPERS) continue;
|
|
155
|
+
if (isStarReexport(decl)) {
|
|
156
|
+
findings.push({
|
|
157
|
+
line: decl.getStartLineNumber(),
|
|
158
|
+
message: `[test-only-scope] export * from ${TESTING_HELPERS} re-exports the test-only scope helpers; allowed in test files only`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
139
161
|
const named =
|
|
140
162
|
"getNamedImports" in decl
|
|
141
163
|
? decl.getNamedImports().map((n) => n.getName())
|
|
@@ -249,21 +271,10 @@ function findTenantDbReasonViolations(sf: SourceFile): Finding[] {
|
|
|
249
271
|
return findings;
|
|
250
272
|
}
|
|
251
273
|
|
|
252
|
-
function findFixedScopeUses(sf: SourceFile): Finding[] {
|
|
253
|
-
if (!sf.getFullText().includes(FIXED_SCOPE_SYMBOL)) return [];
|
|
254
|
-
return sf
|
|
255
|
-
.getDescendantsOfKind(SyntaxKind.Identifier)
|
|
256
|
-
.filter((id) => id.getText() === FIXED_SCOPE_SYMBOL)
|
|
257
|
-
.map((id) => ({
|
|
258
|
-
line: id.getStartLineNumber(),
|
|
259
|
-
message: `[fixed-system-scope] ${FIXED_SCOPE_SYMBOL} carries no call-site reason; use runInSystemRowLevelSecurityScope(reason, fn)`,
|
|
260
|
-
}));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
274
|
export const guard: AstGuard = {
|
|
264
275
|
name: "Internal-Subpath-Imports Guard",
|
|
265
276
|
scan: SCAN,
|
|
266
|
-
hint: "Consumer repos use the public subpaths only; `@cosmicdrift/kumiko-framework/internal/*` is for framework packages. Scope helpers from kumiko-testing/helpers belong in tests. Every system-scope entry, including createTenantDb with mode system, passes a specific string-literal reason (why it needs cross-tenant access).
|
|
277
|
+
hint: "Consumer repos use the public subpaths only; `@cosmicdrift/kumiko-framework/internal/*` is for framework packages. Scope helpers from kumiko-testing/helpers belong in tests. Every system-scope entry, including createTenantDb with mode system, passes a specific string-literal reason (why it needs cross-tenant access).",
|
|
267
278
|
run(files, roots = resolveRepoRoots()) {
|
|
268
279
|
const violations: Array<{ file: string; line: number; message: string }> = [];
|
|
269
280
|
|
|
@@ -278,7 +289,6 @@ export const guard: AstGuard = {
|
|
|
278
289
|
if (!isAllowlisted(rel, FORWARDED_TENANT_DB_REASON_ALLOWLIST)) {
|
|
279
290
|
findings.push(...findTenantDbReasonViolations(sf));
|
|
280
291
|
}
|
|
281
|
-
if (!isAllowlisted(rel, FIXED_SCOPE_ALLOWLIST)) findings.push(...findFixedScopeUses(sf));
|
|
282
292
|
for (const f of findings) violations.push({ file: rel, ...f });
|
|
283
293
|
}
|
|
284
294
|
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { existsSync, readFileSync } from "node:fs";
|
|
23
23
|
import { Glob } from "bun";
|
|
24
24
|
import { Node, type SourceFile, SyntaxKind } from "ts-morph";
|
|
25
|
+
import { decodedLiteralText, mayContainEscapedLiteral } from "./_lib/escaped-literal";
|
|
25
26
|
import {
|
|
26
27
|
ALL_REPO_KINDS,
|
|
27
28
|
type AstGuard,
|
|
@@ -145,26 +146,67 @@ const MENTIONS_RLS_SETTING_RE = /kumiko\.|set_config/i;
|
|
|
145
146
|
|
|
146
147
|
function findSessionSettings(sf: SourceFile, rel: string) {
|
|
147
148
|
const found: Array<{ line: number; message: string }> = [];
|
|
148
|
-
|
|
149
|
+
const text = sf.getFullText();
|
|
150
|
+
if (!MENTIONS_RLS_SETTING_RE.test(text) && !mayContainEscapedLiteral(text)) return found;
|
|
149
151
|
for (const node of sf.getDescendants()) {
|
|
150
152
|
if (!isStringLike(node)) continue;
|
|
151
153
|
// A template's own spans are visited as separate nodes; its full text is checked once here.
|
|
152
154
|
if (node.getParent()?.getKind() === SyntaxKind.TemplateSpan) continue;
|
|
153
|
-
for (const message of violationsInText(node
|
|
155
|
+
for (const message of violationsInText(decodedLiteralText(node), rel)) {
|
|
154
156
|
found.push({ line: node.getStartLineNumber(), message: `[rls-session-setting] ${message}` });
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
return found;
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
const SQL_IGNORED_DIRS = /(^|\/)(node_modules|\.wt|\.git|dist)(\/|$)/;
|
|
162
|
+
const SQL_IGNORED_DIRS = /(^|\/)(node_modules|\.wt|\.git|\.turbo|dist|build|coverage)(\/|$)/;
|
|
163
|
+
const DOLLAR_QUOTE_OPEN_RE = /^\$(?:[A-Za-z_]\w*)?\$/;
|
|
164
|
+
|
|
165
|
+
function closingIndex(sql: string, token: string, from: number): number {
|
|
166
|
+
const index = sql.indexOf(token, from);
|
|
167
|
+
return index === -1 ? sql.length : index + token.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Splits on top-level ";" only. Comments are dropped (their newlines kept for line counting);
|
|
171
|
+
// quoted strings, quoted identifiers and dollar-quoted bodies stay intact and never split.
|
|
172
|
+
function sqlStatements(sql: string): string[] {
|
|
173
|
+
const statements: string[] = [];
|
|
174
|
+
let current = "";
|
|
175
|
+
let i = 0;
|
|
176
|
+
while (i < sql.length) {
|
|
177
|
+
if (sql.startsWith("--", i)) {
|
|
178
|
+
const eol = sql.indexOf("\n", i);
|
|
179
|
+
i = eol === -1 ? sql.length : eol;
|
|
180
|
+
} else if (sql.startsWith("/*", i)) {
|
|
181
|
+
const close = closingIndex(sql, "*/", i + 2);
|
|
182
|
+
current += sql.slice(i, close).replace(/[^\n]/g, "");
|
|
183
|
+
i = close;
|
|
184
|
+
} else if (sql.charAt(i) === ";") {
|
|
185
|
+
statements.push(current);
|
|
186
|
+
current = "";
|
|
187
|
+
i++;
|
|
188
|
+
} else {
|
|
189
|
+
const end = quotedSpanEnd(sql, i) ?? i + 1;
|
|
190
|
+
current += sql.slice(i, end);
|
|
191
|
+
i = end;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
statements.push(current);
|
|
195
|
+
return statements;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function quotedSpanEnd(sql: string, from: number): number | undefined {
|
|
199
|
+
const c = sql.charAt(from);
|
|
200
|
+
if (c === "'" || c === '"') return closingIndex(sql, c, from + 1);
|
|
201
|
+
if (c !== "$" || /\w/.test(sql.charAt(from - 1))) return undefined;
|
|
202
|
+
const tag = DOLLAR_QUOTE_OPEN_RE.exec(sql.slice(from, from + 64))?.[0];
|
|
203
|
+
return tag === undefined ? undefined : closingIndex(sql, tag, from + tag.length);
|
|
204
|
+
}
|
|
161
205
|
|
|
162
|
-
// Statements split on ";" with their start line; "--" comment lines are blanked so prose in them never matches.
|
|
163
206
|
export function findSqlSessionSettings(sql: string, rel: string) {
|
|
164
207
|
const found: Array<{ line: number; message: string }> = [];
|
|
165
|
-
const code = sql.replace(/^\s*--.*$/gm, "");
|
|
166
208
|
let line = 1;
|
|
167
|
-
for (const statement of
|
|
209
|
+
for (const statement of sqlStatements(sql)) {
|
|
168
210
|
const startLine =
|
|
169
211
|
line + countNewlines(statement.slice(0, statement.length - statement.trimStart().length));
|
|
170
212
|
for (const message of violationsInText(statement, rel)) {
|
|
@@ -23,7 +23,7 @@ import { type ScanSpec, scanFiles } from "./_lib/scan-scope";
|
|
|
23
23
|
const SCAN: ScanSpec = { scope: "source", extensions: ["ts"], kinds: ["app", "library"] };
|
|
24
24
|
|
|
25
25
|
const SCHEMA_MODULE_REL = "kumiko/schema.ts";
|
|
26
|
-
const SCHEMA_MODULE_SPECIFIER = /(^|\/)kumiko\/schema(\.
|
|
26
|
+
const SCHEMA_MODULE_SPECIFIER = /(^|\/)kumiko\/schema(\.[cm]?[jt]s)?$/;
|
|
27
27
|
const SCHEMA_CLI_CALL = "runSchemaCli";
|
|
28
28
|
const OPTIONS_ARG_INDEX = 3;
|
|
29
29
|
const FEATURES_EXPORT = "FEATURES";
|
|
@@ -49,6 +49,25 @@ function importOf(sf: SourceFile, localName: string): { name: string; module: st
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function schemaNamespaceImports(sf: SourceFile): Set<string> {
|
|
53
|
+
const names = new Set<string>();
|
|
54
|
+
for (const imp of sf.getImportDeclarations()) {
|
|
55
|
+
const namespace = imp.getNamespaceImport();
|
|
56
|
+
if (namespace !== undefined && SCHEMA_MODULE_SPECIFIER.test(imp.getModuleSpecifierValue())) {
|
|
57
|
+
names.add(namespace.getText());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return names;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isSchemaFeaturesNamespaceAccess(sf: SourceFile, value: Node): boolean {
|
|
64
|
+
return (
|
|
65
|
+
Node.isPropertyAccessExpression(value) &&
|
|
66
|
+
value.getName() === FEATURES_EXPORT &&
|
|
67
|
+
schemaNamespaceImports(sf).has(value.getExpression().getText())
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
52
71
|
function isSchemaFeaturesImport(sf: SourceFile, localName: string): boolean {
|
|
53
72
|
const imported = importOf(sf, localName);
|
|
54
73
|
return (
|
|
@@ -73,6 +92,7 @@ function featuresValueOf(options: Node): Node | undefined | "no-literal" {
|
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
function isRunSchemaCliCall(sf: SourceFile, callee: Node): boolean {
|
|
95
|
+
if (Node.isPropertyAccessExpression(callee)) return callee.getName() === SCHEMA_CLI_CALL;
|
|
76
96
|
if (!Node.isIdentifier(callee)) return false;
|
|
77
97
|
const localName = callee.getText();
|
|
78
98
|
return (importOf(sf, localName)?.name ?? localName) === SCHEMA_CLI_CALL;
|
|
@@ -88,6 +108,7 @@ function problemOf(sf: SourceFile, optionsArg: Node | undefined): string | undef
|
|
|
88
108
|
}
|
|
89
109
|
if (value === undefined) return `${SCHEMA_CLI_CALL} options have no \`features\` property`;
|
|
90
110
|
if (Node.isIdentifier(value) && isSchemaFeaturesImport(sf, value.getText())) return undefined;
|
|
111
|
+
if (isSchemaFeaturesNamespaceAccess(sf, value)) return undefined;
|
|
91
112
|
return `${SCHEMA_CLI_CALL} gets \`features: ${snippet(value)}\`, not ${FEATURES_EXPORT} from kumiko/schema`;
|
|
92
113
|
}
|
|
93
114
|
|