@cosmicdrift/kumiko-guards 0.413.1 → 0.414.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 +44 -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-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 +0 -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
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
// No inline CSS in app code: `style={...}` props and `React.CSSProperties`
|
|
3
|
-
// style objects bypass theme tokens and dark mode. Use widgets/tokens.
|
|
4
|
-
//
|
|
5
|
-
// Part of App-Mounting 2.0.
|
|
6
|
-
|
|
7
|
-
import { type SourceFile, SyntaxKind } from "ts-morph";
|
|
8
|
-
import {
|
|
9
|
-
type AstGuard,
|
|
10
|
-
type GuardViolation,
|
|
11
|
-
relativeToCwd,
|
|
12
|
-
runStandalone,
|
|
13
|
-
type ScanSpec,
|
|
14
|
-
} from "./_lib/guard-kit";
|
|
15
|
-
import { hasIgnoreTag } from "./_lib/ignore-tag";
|
|
16
|
-
|
|
17
|
-
const SCAN: ScanSpec = {
|
|
18
|
-
scope: "source",
|
|
19
|
-
extensions: ["ts", "tsx"],
|
|
20
|
-
frameworkWithin: ["packages/bundled-features/src/**"],
|
|
21
|
-
};
|
|
22
|
-
const EXCLUDE = /(__tests__|\.test\.tsx?$|\.integration\.tsx?$|\.d\.ts$)/;
|
|
23
|
-
const IGNORE_TAG = "kumiko-lint-ignore no-inline-styles";
|
|
24
|
-
|
|
25
|
-
export const guard: AstGuard = {
|
|
26
|
-
name: "No-Inline-Styles Guard (App-Repos)",
|
|
27
|
-
scan: SCAN,
|
|
28
|
-
hint:
|
|
29
|
-
"Replace style=/CSSProperties in app code with widgets + theme tokens. " +
|
|
30
|
-
`Justified exception (e.g. dynamic width from data): // ${IGNORE_TAG} <reason>`,
|
|
31
|
-
run(files: readonly SourceFile[]) {
|
|
32
|
-
const violations: GuardViolation[] = [];
|
|
33
|
-
for (const sf of files) {
|
|
34
|
-
if (EXCLUDE.test(sf.getFilePath())) continue;
|
|
35
|
-
for (const attr of sf.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {
|
|
36
|
-
if (attr.getNameNode().getText() !== "style") continue;
|
|
37
|
-
if (hasIgnoreTag(attr, IGNORE_TAG)) continue;
|
|
38
|
-
violations.push({
|
|
39
|
-
file: relativeToCwd(sf.getFilePath()),
|
|
40
|
-
line: attr.getStartLineNumber(),
|
|
41
|
-
message: "style= prop in app code (use theme tokens/widgets)",
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
// ponytail: name-text comparison doesn't tolerate aliased imports
|
|
45
|
-
// (import { CSSProperties as CSS }) and false-positives on same-named
|
|
46
|
-
// local types. The style=-JsxAttribute above is the primary, more
|
|
47
|
-
// robust signal path — this TypeReference check is deliberately
|
|
48
|
-
// best-effort.
|
|
49
|
-
for (const ref of sf.getDescendantsOfKind(SyntaxKind.TypeReference)) {
|
|
50
|
-
const name = ref.getTypeName().getText();
|
|
51
|
-
if (name !== "CSSProperties" && name !== "React.CSSProperties") continue;
|
|
52
|
-
if (hasIgnoreTag(ref, IGNORE_TAG)) continue;
|
|
53
|
-
violations.push({
|
|
54
|
-
file: relativeToCwd(sf.getFilePath()),
|
|
55
|
-
line: ref.getStartLineNumber(),
|
|
56
|
-
message: "CSSProperties style object in app code (use theme tokens/widgets)",
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return { violations };
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
if (import.meta.main) runStandalone(guard);
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
// Rerender protection: raw useEffect/useLayoutEffect + fetch() in app
|
|
3
|
-
// screens are the source of the endless-rerender class (unstable deps,
|
|
4
|
-
// setState-in-effect) and bypass the framework hook set (useQuery/
|
|
5
|
-
// useMutation/useDisclosure — useQuery can go live via SSE). Endless
|
|
6
|
-
// rerenders aren't reliably detectable statically; the guard eliminates the
|
|
7
|
-
// pattern that produces them.
|
|
8
|
-
//
|
|
9
|
-
// Local UI state via useState stays allowed.
|
|
10
|
-
|
|
11
|
-
import { Node, type SourceFile, SyntaxKind } from "ts-morph";
|
|
12
|
-
import {
|
|
13
|
-
type AstGuard,
|
|
14
|
-
type GuardViolation,
|
|
15
|
-
relativeToCwd,
|
|
16
|
-
runStandalone,
|
|
17
|
-
type ScanSpec,
|
|
18
|
-
} from "./_lib/guard-kit";
|
|
19
|
-
import { hasIgnoreTag } from "./_lib/ignore-tag";
|
|
20
|
-
|
|
21
|
-
// Match property/identifier names instead of call text — otherwise
|
|
22
|
-
// namespace-/alias-qualified calls (`React.useEffect(...)`, a renamed
|
|
23
|
-
// import `useEffect as useFx`) slip through, because getText() returns the
|
|
24
|
-
// full expression ("React.useEffect") instead of just the banned name.
|
|
25
|
-
function calleeName(expr: import("ts-morph").Node): string {
|
|
26
|
-
if (Node.isPropertyAccessExpression(expr)) return expr.getName();
|
|
27
|
-
return expr.getText();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Only component files in web/public code. API clients (*.ts) stay out of
|
|
31
|
-
// scope — they encapsulate fetch deliberately in one place.
|
|
32
|
-
const SCAN: ScanSpec = {
|
|
33
|
-
scope: "source",
|
|
34
|
-
extensions: ["tsx"],
|
|
35
|
-
within: ["**/web/**", "public/**"],
|
|
36
|
-
frameworkWithin: ["packages/bundled-features/src/**"],
|
|
37
|
-
};
|
|
38
|
-
const EXCLUDE = /(__tests__|\.test\.tsx?$|\.integration\.tsx?$|\.d\.ts$)/;
|
|
39
|
-
const IGNORE_TAG = "kumiko-lint-ignore no-raw-hooks";
|
|
40
|
-
|
|
41
|
-
const BANNED_HOOKS = new Set(["useEffect", "useLayoutEffect"]);
|
|
42
|
-
|
|
43
|
-
export const guard: AstGuard = {
|
|
44
|
-
name: "No-Raw-Hooks Guard (App-Repos)",
|
|
45
|
-
scan: SCAN,
|
|
46
|
-
hint:
|
|
47
|
-
"Use the framework hook set: useQuery (live: true for SSE), useMutation, useDisclosure, " +
|
|
48
|
-
"useReportStepComplete (wizard extension steps). " +
|
|
49
|
-
`Real special case (DOM integration or similar): // ${IGNORE_TAG} <reason>`,
|
|
50
|
-
run(files: readonly SourceFile[]) {
|
|
51
|
-
const violations: GuardViolation[] = [];
|
|
52
|
-
for (const sf of files) {
|
|
53
|
-
if (EXCLUDE.test(sf.getFilePath())) continue;
|
|
54
|
-
for (const call of sf.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
55
|
-
const callee = call.getExpression();
|
|
56
|
-
const name = calleeName(callee);
|
|
57
|
-
if (BANNED_HOOKS.has(name)) {
|
|
58
|
-
if (hasIgnoreTag(call, IGNORE_TAG)) continue;
|
|
59
|
-
violations.push({
|
|
60
|
-
file: relativeToCwd(sf.getFilePath()),
|
|
61
|
-
line: call.getStartLineNumber(),
|
|
62
|
-
message: `${name} in App-Screen — use framework hooks (useQuery/useMutation/useDisclosure)`,
|
|
63
|
-
});
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (name === "fetch") {
|
|
67
|
-
if (hasIgnoreTag(call, IGNORE_TAG)) continue;
|
|
68
|
-
violations.push({
|
|
69
|
-
file: relativeToCwd(sf.getFilePath()),
|
|
70
|
-
line: call.getStartLineNumber(),
|
|
71
|
-
message: "fetch() in App-Screen — use useQuery/useMutation or an API client (*.ts)",
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return { violations };
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
if (import.meta.main) runStandalone(guard);
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* Guard: finds value imports from `temporal-polyfill` outside kumiko-types.
|
|
4
|
-
*
|
|
5
|
-
* Since 0.351.0 `@cosmicdrift/kumiko-types/temporal` is the single source of
|
|
6
|
-
* the Temporal API: native `globalThis.Temporal` wins, the polyfill is only a
|
|
7
|
-
* fallback. A module that imports `Temporal` straight from `temporal-polyfill`
|
|
8
|
-
* gets the polyfill classes while framework-made values are native ones, so
|
|
9
|
-
* `instanceof Temporal.Instant` and `z.instanceof(Temporal.Instant)` reject
|
|
10
|
-
* them ("expected Instant, received Instant"). Side-effect imports such as
|
|
11
|
-
* `temporal-polyfill/global` are flagged too: they can put a second
|
|
12
|
-
* implementation on the global.
|
|
13
|
-
*
|
|
14
|
-
* Not flagged: `import type` (erased at runtime) and the
|
|
15
|
-
* `/// <reference types="temporal-polyfill/global" />` directive.
|
|
16
|
-
*
|
|
17
|
-
* Usage:
|
|
18
|
-
* bun guards/guard-no-temporal-polyfill-import.ts
|
|
19
|
-
*
|
|
20
|
-
* Exit 1 on violations, 0 when clean.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { type ImportDeclaration, Node, type SourceFile, SyntaxKind } from "ts-morph";
|
|
24
|
-
import {
|
|
25
|
-
type AstGuard,
|
|
26
|
-
findRepoRootFor,
|
|
27
|
-
type GuardViolation,
|
|
28
|
-
relFromRepoRoot,
|
|
29
|
-
runStandalone,
|
|
30
|
-
type ScanSpec,
|
|
31
|
-
} from "./_lib/guard-kit";
|
|
32
|
-
import { type RepoRoot, resolveRepoRoots } from "./_lib/roots";
|
|
33
|
-
|
|
34
|
-
const SCAN: ScanSpec = {
|
|
35
|
-
scope: "source+tests",
|
|
36
|
-
extensions: ["ts", "tsx"],
|
|
37
|
-
frameworkWithin: ["packages/*/src/**", "samples/**"],
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const REPLACEMENT_IMPORT = 'import { Temporal } from "@cosmicdrift/kumiko-types/temporal";';
|
|
41
|
-
|
|
42
|
-
// The one module that resolves native-vs-polyfill; repo-scoped so an app file
|
|
43
|
-
// at the same relative path does not inherit the exception.
|
|
44
|
-
const TEMPORAL_SOURCE = { repo: "kumiko-framework", relPath: "packages/types/src/temporal.ts" };
|
|
45
|
-
|
|
46
|
-
export function isTemporalSingleSource(repoName: string | undefined, relPath: string): boolean {
|
|
47
|
-
return repoName === TEMPORAL_SOURCE.repo && relPath === TEMPORAL_SOURCE.relPath;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isPolyfillSpecifier(specifier: string): boolean {
|
|
51
|
-
return specifier === "temporal-polyfill" || specifier.startsWith("temporal-polyfill/");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isTypeOnlyImport(decl: ImportDeclaration): boolean {
|
|
55
|
-
if (decl.isTypeOnly()) return true;
|
|
56
|
-
const named = decl.getNamedImports();
|
|
57
|
-
const hasValueBinding =
|
|
58
|
-
decl.getDefaultImport() !== undefined || decl.getNamespaceImport() !== undefined;
|
|
59
|
-
return !hasValueBinding && named.length > 0 && named.every((n) => n.isTypeOnly());
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type PolyfillImport = { readonly line: number; readonly specifier: string };
|
|
63
|
-
|
|
64
|
-
function findPolyfillImportDeclarations(sf: SourceFile): PolyfillImport[] {
|
|
65
|
-
const found: PolyfillImport[] = [];
|
|
66
|
-
for (const decl of sf.getImportDeclarations()) {
|
|
67
|
-
const specifier = decl.getModuleSpecifierValue();
|
|
68
|
-
if (isPolyfillSpecifier(specifier) && !isTypeOnlyImport(decl)) {
|
|
69
|
-
found.push({ line: decl.getStartLineNumber(), specifier });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return found;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function findPolyfillExportDeclarations(sf: SourceFile): PolyfillImport[] {
|
|
76
|
-
const found: PolyfillImport[] = [];
|
|
77
|
-
for (const decl of sf.getExportDeclarations()) {
|
|
78
|
-
const specifier = decl.getModuleSpecifierValue();
|
|
79
|
-
if (specifier !== undefined && isPolyfillSpecifier(specifier) && !decl.isTypeOnly()) {
|
|
80
|
-
found.push({ line: decl.getStartLineNumber(), specifier });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return found;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function findPolyfillRequireOrDynamicImports(sf: SourceFile): PolyfillImport[] {
|
|
87
|
-
const found: PolyfillImport[] = [];
|
|
88
|
-
for (const call of sf.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
89
|
-
const callee = call.getExpression();
|
|
90
|
-
const isRequireCall = Node.isIdentifier(callee) && callee.getText() === "require";
|
|
91
|
-
const isDynamicImport = callee.getKind() === SyntaxKind.ImportKeyword;
|
|
92
|
-
if (!isRequireCall && !isDynamicImport) continue;
|
|
93
|
-
const arg = call.getArguments()[0];
|
|
94
|
-
if (arg && Node.isStringLiteral(arg) && isPolyfillSpecifier(arg.getLiteralValue())) {
|
|
95
|
-
found.push({ line: call.getStartLineNumber(), specifier: arg.getLiteralValue() });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return found;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function findPolyfillValueImports(sf: SourceFile): PolyfillImport[] {
|
|
102
|
-
return [
|
|
103
|
-
...findPolyfillImportDeclarations(sf),
|
|
104
|
-
...findPolyfillExportDeclarations(sf),
|
|
105
|
-
...findPolyfillRequireOrDynamicImports(sf),
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const guard: AstGuard = {
|
|
110
|
-
name: "No-Temporal-Polyfill-Import Guard",
|
|
111
|
-
scan: SCAN,
|
|
112
|
-
hint: `Import Temporal from the kumiko single source instead: ${REPLACEMENT_IMPORT} A direct "temporal-polyfill" import creates a second Temporal implementation, so instanceof and z.instanceof(Temporal.Instant) reject framework-made values.`,
|
|
113
|
-
run(files, roots: readonly RepoRoot[] = resolveRepoRoots()) {
|
|
114
|
-
const violations: GuardViolation[] = [];
|
|
115
|
-
for (const sf of files) {
|
|
116
|
-
const file = sf.getFilePath();
|
|
117
|
-
const rel = relFromRepoRoot(file, roots);
|
|
118
|
-
if (isTemporalSingleSource(findRepoRootFor(file, roots)?.name, rel)) continue;
|
|
119
|
-
for (const hit of findPolyfillValueImports(sf)) {
|
|
120
|
-
violations.push({
|
|
121
|
-
file: rel,
|
|
122
|
-
line: hit.line,
|
|
123
|
-
message: `[${hit.specifier}] direct temporal-polyfill import — use ${REPLACEMENT_IMPORT}`,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return { violations };
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
if (import.meta.main) runStandalone(guard);
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* Guard: enforces that app-/feature-web code uses UI building blocks from
|
|
4
|
-
* the framework primitives, not hand-rolled Tailwind on raw HTML tags.
|
|
5
|
-
*
|
|
6
|
-
* Why: hand-rolled Tailwind in `web/` folders costs twice: every
|
|
7
|
-
* renderer/theme update then has to be re-applied to each hand-tailwound
|
|
8
|
-
* screen individually (style drift), and direct DOM tags bypass the
|
|
9
|
-
* primitives contract (`<DataTable>`, `<Form>`, `<Button>`).
|
|
10
|
-
*
|
|
11
|
-
* Forbidden in app-/feature-web code:
|
|
12
|
-
*
|
|
13
|
-
* <table>/<thead>/<tbody>/<tr>/<td>/<th> → <DataTable>
|
|
14
|
-
* <form> → <Form>
|
|
15
|
-
* <input> → <Input> (in <Field>)
|
|
16
|
-
* <button> → <Button>
|
|
17
|
-
* <select> → <ComboboxInput>
|
|
18
|
-
* <textarea> → <Input kind="textarea">
|
|
19
|
-
* <dialog> → <DefaultDialog>
|
|
20
|
-
* alert() / window.alert() → <DefaultDialog> from @cosmicdrift/kumiko-renderer/web
|
|
21
|
-
* className "bg-card" (hand-rolled card) → <Card> (slots/options)
|
|
22
|
-
* className "mx-auto" + "max-w-*" (hand-rolled screen container)
|
|
23
|
-
* → <PageSection maxWidth> (3xl/4xl/full)
|
|
24
|
-
*
|
|
25
|
-
* Allowed: containers and text — `<div>`, `<span>`, `<section>`,
|
|
26
|
-
* `<header>`, `<main>`, `<nav>`, `<aside>`, `<article>`,
|
|
27
|
-
* `<h1>`-`<h6>`, `<p>`, `<ul>`, `<ol>`, `<li>`, `<a>`, `<img>`,
|
|
28
|
-
* `<svg>`, `<label>`, `<small>`, `<strong>`, `<em>`, `<br>`, `<hr>`,
|
|
29
|
-
* `<pre>`, `<code>`.
|
|
30
|
-
*
|
|
31
|
-
* `__tests__` folders are excluded. Per-line override:
|
|
32
|
-
* `// kumiko-lint-ignore primitives-discipline <reason>`
|
|
33
|
-
* (on the same line or the line directly above).
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
import * as fs from "node:fs";
|
|
37
|
-
import * as path from "node:path";
|
|
38
|
-
import { type RepoCheck, reportResults, runRepoChecks } from "./_lib/guard-kit";
|
|
39
|
-
import { lineHasIgnoreTag } from "./_lib/ignore-tag";
|
|
40
|
-
import { isFlatSrcLayout, type RepoRoot, sourceRootDirs } from "./_lib/roots";
|
|
41
|
-
|
|
42
|
-
const FORBIDDEN_TAGS: ReadonlyArray<{
|
|
43
|
-
readonly tag: string;
|
|
44
|
-
readonly counterpart: string;
|
|
45
|
-
}> = [
|
|
46
|
-
{ tag: "table", counterpart: "<DataTable>" },
|
|
47
|
-
{ tag: "thead", counterpart: "<DataTable>" },
|
|
48
|
-
{ tag: "tbody", counterpart: "<DataTable>" },
|
|
49
|
-
{ tag: "tr", counterpart: "<DataTable>" },
|
|
50
|
-
{ tag: "td", counterpart: "<DataTable>" },
|
|
51
|
-
{ tag: "th", counterpart: "<DataTable>" },
|
|
52
|
-
{ tag: "form", counterpart: "<Form>" },
|
|
53
|
-
{ tag: "input", counterpart: "<Input> (via <Field>)" },
|
|
54
|
-
{ tag: "button", counterpart: "<Button>" },
|
|
55
|
-
{ tag: "select", counterpart: "<ComboboxInput>" },
|
|
56
|
-
{ tag: "textarea", counterpart: '<Input kind="textarea">' },
|
|
57
|
-
{ tag: "dialog", counterpart: "<DefaultDialog>" },
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
const FORBIDDEN_CALLS: ReadonlyArray<{
|
|
61
|
-
readonly call: string;
|
|
62
|
-
readonly counterpart: string;
|
|
63
|
-
}> = [{ call: "alert", counterpart: "<DefaultDialog> from @cosmicdrift/kumiko-renderer/web" }];
|
|
64
|
-
|
|
65
|
-
// Forbidden className tokens: an allowed tag (`<div>`), but the class gives
|
|
66
|
-
// away hand-rolled primitive chrome. `bg-card` is the dedicated card-surface
|
|
67
|
-
// token — seeing it in a className means a hand-rebuilt card instead of
|
|
68
|
-
// `<Card>` (slots/options). Exactly the copy-paste drift the Card primitive
|
|
69
|
-
// is meant to eliminate. Real exceptions (foundation token swatches,
|
|
70
|
-
// navigation surfaces) carry `// kumiko-lint-ignore primitives-discipline`.
|
|
71
|
-
const FORBIDDEN_CLASSES: ReadonlyArray<{
|
|
72
|
-
readonly token: string;
|
|
73
|
-
readonly counterpart: string;
|
|
74
|
-
}> = [{ token: "bg-card", counterpart: "<Card>" }];
|
|
75
|
-
|
|
76
|
-
// Hand-rolled screen container: `mx-auto` and a `max-w-*` token in the same
|
|
77
|
-
// line. Screens get their width from `<PageSection maxWidth>`; a private
|
|
78
|
-
// container drifts from the shell (an ai-models screen rendered 896px wide).
|
|
79
|
-
const SCREEN_CONTAINER_LABEL = "mx-auto + max-w-*";
|
|
80
|
-
const SCREEN_CONTAINER_COUNTERPART = "<PageSection maxWidth> (3xl/4xl/full)";
|
|
81
|
-
const MX_AUTO_PATTERN = /(?<![\w-])mx-auto(?![\w-])/u;
|
|
82
|
-
// Arbitrary values (`max-w-[1100px]`) contain `[`/`]`/`.`, so the token body
|
|
83
|
-
// is any non-whitespace/non-quote run.
|
|
84
|
-
const MAX_W_PATTERN = /(?<![\w-])max-w-[^\s"'`}]+/u;
|
|
85
|
-
|
|
86
|
-
const IGNORE_TAG = "kumiko-lint-ignore primitives-discipline";
|
|
87
|
-
|
|
88
|
-
export type ScopeKind = "bundled-features" | "samples" | "app";
|
|
89
|
-
|
|
90
|
-
type ScanScope = {
|
|
91
|
-
readonly kind: ScopeKind;
|
|
92
|
-
readonly root: string;
|
|
93
|
-
/** Repo root the reported file labels are relative to. */
|
|
94
|
-
readonly repoRoot: string;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Framework checkout enforces bundled-features + samples. App-repo checkout
|
|
98
|
-
// scans the app's web/ screens — primitives-discipline as a ratchet per app
|
|
99
|
-
// repo. Every other resolved repo (enterprise, platform, ...)
|
|
100
|
-
// scans alongside the others in one run — flatMap all of them instead of
|
|
101
|
-
// cascading, which would silently skip every root after the first, exactly
|
|
102
|
-
// the silent-skip this guard fixes.
|
|
103
|
-
function resolveScopes(roots: readonly RepoRoot[]): ScanScope[] {
|
|
104
|
-
const frameworkRoot = roots.find((r) => r.kind === "framework");
|
|
105
|
-
if (frameworkRoot) {
|
|
106
|
-
const repoRoot = frameworkRoot.absPath;
|
|
107
|
-
return [
|
|
108
|
-
{
|
|
109
|
-
kind: "bundled-features",
|
|
110
|
-
root: path.join(repoRoot, "packages/bundled-features/src"),
|
|
111
|
-
repoRoot,
|
|
112
|
-
},
|
|
113
|
-
{ kind: "samples", root: path.join(repoRoot, "samples"), repoRoot },
|
|
114
|
-
];
|
|
115
|
-
}
|
|
116
|
-
const appRoots = roots.filter((r) => r.kind === "app" && isFlatSrcLayout(r));
|
|
117
|
-
if (appRoots.length > 0) {
|
|
118
|
-
return appRoots.map((r) => ({
|
|
119
|
-
kind: "app" as const,
|
|
120
|
-
root: path.join(r.absPath, "src"),
|
|
121
|
-
repoRoot: r.absPath,
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
return roots
|
|
125
|
-
.filter((r) => r.kind !== "framework" && !isFlatSrcLayout(r))
|
|
126
|
-
.flatMap((r) =>
|
|
127
|
-
sourceRootDirs(r).map((root) => ({ kind: "app" as const, root, repoRoot: r.absPath })),
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
type Violation = {
|
|
132
|
-
readonly file: string;
|
|
133
|
-
readonly line: number;
|
|
134
|
-
readonly kind: "tag" | "call" | "class";
|
|
135
|
-
readonly tag: string;
|
|
136
|
-
readonly counterpart: string;
|
|
137
|
-
readonly excerpt: string;
|
|
138
|
-
readonly scope: ScopeKind;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
function isWebFile(absPath: string, scopeRoot: string): boolean {
|
|
142
|
-
// Only .tsx files under a `web/`, `client/` or `public/` path segment
|
|
143
|
-
// (`client` = enterprise ai-foundation keeps its web code there; prevents
|
|
144
|
-
// scanning random .tsx in screens/ or feature roots — those are schema
|
|
145
|
-
// definitions, not web code).
|
|
146
|
-
if (!absPath.endsWith(".tsx")) return false;
|
|
147
|
-
const rel = path.relative(scopeRoot, absPath);
|
|
148
|
-
const parts = rel.split(path.sep);
|
|
149
|
-
return parts.includes("web") || parts.includes("client") || parts.includes("public");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function walk(dir: string, out: string[]): void {
|
|
153
|
-
// skip: not every scope has every candidate directory
|
|
154
|
-
if (!fs.existsSync(dir)) return;
|
|
155
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
156
|
-
const full = path.join(dir, entry.name);
|
|
157
|
-
if (entry.isDirectory()) {
|
|
158
|
-
if (entry.name === "__tests__") continue;
|
|
159
|
-
if (entry.name === "node_modules") continue;
|
|
160
|
-
if (entry.name === "dist") continue;
|
|
161
|
-
walk(full, out);
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (entry.isFile()) out.push(full);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function buildTagPattern(tag: string): RegExp {
|
|
169
|
-
// Match `<tag` at the JSX opening: at line start or after a char that can't
|
|
170
|
-
// end an identifier/member access (`cond?<input/>:<div/>` hits, `Array<input` doesn't).
|
|
171
|
-
// Negative lookahead `[a-zA-Z0-9-]` so `<input` doesn't match `<inputfoo`.
|
|
172
|
-
// Doesn't match the closing tag (`</tag>`) — that would be redundant.
|
|
173
|
-
return new RegExp(`(^|[^\\w$.])<${tag}(?![a-zA-Z0-9-])`, "u");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const TAG_PATTERNS = FORBIDDEN_TAGS.map((t) => ({ ...t, pattern: buildTagPattern(t.tag) }));
|
|
177
|
-
|
|
178
|
-
// Match `alert(` and `window.alert(` — the native browser dialog is forbidden.
|
|
179
|
-
const CALL_PATTERNS = FORBIDDEN_CALLS.map((c) => ({
|
|
180
|
-
...c,
|
|
181
|
-
// Lookbehind instead of \b: \b also matches after a dot — `toast.alert(`
|
|
182
|
-
// would otherwise be a hit. window.alert( stays deliberately forbidden.
|
|
183
|
-
pattern: new RegExp(`(?<![.\\w$])(?:window\\.)?${c.call}\\s*\\(`, "u"),
|
|
184
|
-
}));
|
|
185
|
-
|
|
186
|
-
// `\b` alone isn't enough: `-` is itself a non-word character, so
|
|
187
|
-
// `\bbg-card\b` also matches as a substring in a longer hyphen-prefixed
|
|
188
|
-
// token (e.g. a hypothetical `my-bg-card`). A lookaround against word
|
|
189
|
-
// characters AND `-` on both sides keeps `bg-card` exact, without losing
|
|
190
|
-
// `hover:bg-card`/`bg-card/40`.
|
|
191
|
-
const CLASS_PATTERNS = FORBIDDEN_CLASSES.map((c) => ({
|
|
192
|
-
...c,
|
|
193
|
-
pattern: new RegExp(`(?<![\\w-])${c.token}(?![\\w-])`, "u"),
|
|
194
|
-
}));
|
|
195
|
-
|
|
196
|
-
function isPublicPage(file: string): boolean {
|
|
197
|
-
// Public pages live outside the app shell; PublicShell is their container,
|
|
198
|
-
// so a centered max-width there is not a screen container.
|
|
199
|
-
return file.split(path.sep).includes("public");
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function hasIgnore(currentLine: string, prevLine: string): boolean {
|
|
203
|
-
return lineHasIgnoreTag(currentLine, IGNORE_TAG) || lineHasIgnoreTag(prevLine, IGNORE_TAG);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Block-comment tracking (heuristic): `/* ... */` across multiple lines.
|
|
207
|
-
// Single-line `//` and `*` (inside /* */) are skipped.
|
|
208
|
-
function isCommentOnlyLine(trimmed: string, state: { inBlockComment: boolean }): boolean {
|
|
209
|
-
if (state.inBlockComment) {
|
|
210
|
-
if (trimmed.includes("*/")) state.inBlockComment = false;
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
if (trimmed.startsWith("/*") && !trimmed.includes("*/")) {
|
|
214
|
-
state.inBlockComment = true;
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
return trimmed.startsWith("//") || trimmed.startsWith("*");
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
type LineContext = Pick<Violation, "file" | "line" | "excerpt" | "scope">;
|
|
221
|
-
|
|
222
|
-
function violationsOnLine(
|
|
223
|
-
codeOnly: string,
|
|
224
|
-
context: LineContext,
|
|
225
|
-
publicPage: boolean,
|
|
226
|
-
): Violation[] {
|
|
227
|
-
const violations: Violation[] = [];
|
|
228
|
-
for (const { tag, counterpart, pattern } of TAG_PATTERNS) {
|
|
229
|
-
if (pattern.test(codeOnly)) violations.push({ ...context, kind: "tag", tag, counterpart });
|
|
230
|
-
}
|
|
231
|
-
for (const { call, counterpart, pattern } of CALL_PATTERNS) {
|
|
232
|
-
if (pattern.test(codeOnly)) {
|
|
233
|
-
violations.push({ ...context, kind: "call", tag: call, counterpart });
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
for (const { token, counterpart, pattern } of CLASS_PATTERNS) {
|
|
237
|
-
if (pattern.test(codeOnly)) {
|
|
238
|
-
violations.push({ ...context, kind: "class", tag: token, counterpart });
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (!publicPage && MX_AUTO_PATTERN.test(codeOnly) && MAX_W_PATTERN.test(codeOnly)) {
|
|
242
|
-
violations.push({
|
|
243
|
-
...context,
|
|
244
|
-
kind: "class",
|
|
245
|
-
tag: SCREEN_CONTAINER_LABEL,
|
|
246
|
-
counterpart: SCREEN_CONTAINER_COUNTERPART,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
return violations;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export function checkFile(
|
|
253
|
-
file: string,
|
|
254
|
-
scope: ScopeKind,
|
|
255
|
-
root: string = process.cwd(),
|
|
256
|
-
): Violation[] {
|
|
257
|
-
const text = fs.readFileSync(file, "utf-8");
|
|
258
|
-
const lines = text.split("\n");
|
|
259
|
-
const violations: Violation[] = [];
|
|
260
|
-
const relativeFile = path.relative(root, file);
|
|
261
|
-
const publicPage = isPublicPage(relativeFile);
|
|
262
|
-
const commentState = { inBlockComment: false };
|
|
263
|
-
for (let i = 0; i < lines.length; i++) {
|
|
264
|
-
const line = lines[i] ?? "";
|
|
265
|
-
const trimmed = line.trim();
|
|
266
|
-
if (isCommentOnlyLine(trimmed, commentState)) continue;
|
|
267
|
-
// Strip trailing inline comments — `foo(); // alert() would be wrong`
|
|
268
|
-
// must not match. (?<!:) leaves URLs (https://…) in strings alone;
|
|
269
|
-
// string contents themselves stay an accepted heuristic gap.
|
|
270
|
-
const codeOnly = line.replace(/(?<!:)\/\/.*$/u, "");
|
|
271
|
-
|
|
272
|
-
const prev = i > 0 ? (lines[i - 1] ?? "") : "";
|
|
273
|
-
if (hasIgnore(line, prev)) continue;
|
|
274
|
-
|
|
275
|
-
const excerpt = trimmed.length > 120 ? `${trimmed.slice(0, 117)}...` : trimmed;
|
|
276
|
-
violations.push(
|
|
277
|
-
...violationsOnLine(
|
|
278
|
-
codeOnly,
|
|
279
|
-
{ file: relativeFile, line: i + 1, excerpt, scope },
|
|
280
|
-
publicPage,
|
|
281
|
-
),
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
return violations;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function violationMessage(v: Violation): string {
|
|
288
|
-
const label =
|
|
289
|
-
v.kind === "call" ? `${v.tag}()` : v.kind === "class" ? `class "${v.tag}"` : `<${v.tag}>`;
|
|
290
|
-
return `${label} → ${v.counterpart} | ${v.excerpt}`;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const HINT =
|
|
294
|
-
"Migration: usePrimitives() in a custom screen component, or schema-driven via EntityListScreenDefinition / EntityEditScreenDefinition where possible. Per-line override: // kumiko-lint-ignore primitives-discipline <reason>";
|
|
295
|
-
|
|
296
|
-
export const check: RepoCheck = {
|
|
297
|
-
name: "Primitives-Discipline Guard",
|
|
298
|
-
hint: HINT,
|
|
299
|
-
run(roots) {
|
|
300
|
-
const scopes = resolveScopes(roots);
|
|
301
|
-
if (scopes.length === 0) {
|
|
302
|
-
// infra exits 1 here ("neither FRAMEWORK_ROOT, APP_ROOT nor any other
|
|
303
|
-
// repo root resolved") — the vacuity floor below reproduces that.
|
|
304
|
-
return { violations: [], matchedFiles: 0, notApplicable: false };
|
|
305
|
-
}
|
|
306
|
-
// Pre-filter count (every file walk() found, before the web/-segment
|
|
307
|
-
// filter): an app repo whose screens are schema-driven with zero
|
|
308
|
-
// web/*.tsx (phronexsis before its first screen) must not be flagged as
|
|
309
|
-
// vacuous just because isWebFile() legitimately matched nothing.
|
|
310
|
-
let walkedFiles = 0;
|
|
311
|
-
const violations: { file: string; line: number; message: string }[] = [];
|
|
312
|
-
const warnings: { file: string; line: number; message: string }[] = [];
|
|
313
|
-
|
|
314
|
-
for (const scope of scopes) {
|
|
315
|
-
const files: string[] = [];
|
|
316
|
-
walk(scope.root, files);
|
|
317
|
-
walkedFiles += files.length;
|
|
318
|
-
const webFiles = files.filter((f) => isWebFile(f, scope.root));
|
|
319
|
-
for (const file of webFiles) {
|
|
320
|
-
const target = scope.kind === "samples" ? warnings : violations;
|
|
321
|
-
for (const v of checkFile(file, scope.kind, scope.repoRoot)) {
|
|
322
|
-
target.push({ file: v.file, line: v.line, message: violationMessage(v) });
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return {
|
|
328
|
-
violations,
|
|
329
|
-
warnings: warnings.length > 0 ? warnings : undefined,
|
|
330
|
-
matchedFiles: walkedFiles,
|
|
331
|
-
notApplicable: false,
|
|
332
|
-
};
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
if (import.meta.main) {
|
|
337
|
-
// --strict also blocks the samples scope (infra's `--strict` mode);
|
|
338
|
-
// --strict-bundled is accepted for CLI compatibility — bundled-features is
|
|
339
|
-
// already always-blocking here (what framework CI ran as --strict-bundled).
|
|
340
|
-
const strict = process.argv.includes("--strict");
|
|
341
|
-
const effectiveCheck: RepoCheck = strict
|
|
342
|
-
? {
|
|
343
|
-
name: check.name,
|
|
344
|
-
hint: check.hint,
|
|
345
|
-
async run(roots) {
|
|
346
|
-
const outcome = await check.run(roots);
|
|
347
|
-
return {
|
|
348
|
-
violations: [...outcome.violations, ...(outcome.warnings ?? [])],
|
|
349
|
-
matchedFiles: outcome.matchedFiles,
|
|
350
|
-
notApplicable: outcome.notApplicable,
|
|
351
|
-
};
|
|
352
|
-
},
|
|
353
|
-
}
|
|
354
|
-
: check;
|
|
355
|
-
const failed = reportResults(await runRepoChecks([effectiveCheck]));
|
|
356
|
-
process.exit(failed > 0 ? 1 : 0);
|
|
357
|
-
}
|