architecture-harness 0.25.0 → 0.26.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/package.json +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +53 -0
- package/src/plugin.test.mjs +3 -2
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A resource that loads optional packages from the consumer's installation.
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
const OPTIONAL_PEERS = new Set(["yaml", "playwright", "pngjs", "pixelmatch"]);
|
|
8
|
+
|
|
9
|
+
export async function importConsumerPackage(name, root = process.cwd()) {
|
|
10
|
+
if (!OPTIONAL_PEERS.has(name)) throw new Error(`Unsupported optional peer '${name}'`);
|
|
11
|
+
for (const start of [root, path.dirname(fileURLToPath(import.meta.url))]) {
|
|
12
|
+
for (let directory = path.resolve(start); ; directory = path.dirname(directory)) {
|
|
13
|
+
const manifest = path.join(directory, "node_modules", name, "package.json");
|
|
14
|
+
if (existsSync(manifest)) {
|
|
15
|
+
const pkg = JSON.parse(readFileSync(manifest, "utf8"));
|
|
16
|
+
let entry = pkg.exports?.["."] ?? pkg.exports ?? pkg.main ?? "index.js";
|
|
17
|
+
while (entry && typeof entry === "object") entry = entry.node ?? entry.import ?? entry.default;
|
|
18
|
+
if (typeof entry === "string") return import(pathToFileURL(path.resolve(path.dirname(manifest), entry)).href);
|
|
19
|
+
}
|
|
20
|
+
if (path.dirname(directory) === directory) break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let resolved;
|
|
24
|
+
try {
|
|
25
|
+
resolved = createRequire(path.join(root, "package.json")).resolve(name);
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
if (cause.code !== "MODULE_NOT_FOUND" || cause.message.split("\n")[0] !== `Cannot find module '${name}'`) throw cause;
|
|
28
|
+
throw Object.assign(new Error(`Cannot find package '${name}'`, { cause }), { code: "ERR_MODULE_NOT_FOUND" });
|
|
29
|
+
}
|
|
30
|
+
return import(pathToFileURL(resolved).href);
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { importConsumerPackage } from "./consumer-package.mjs";
|
|
8
|
+
|
|
9
|
+
test("consumer packages resolve beside the consumer, including ESM-only packages", async () => {
|
|
10
|
+
const root = mkdtempSync(join(tmpdir(), "qc-consumer-"));
|
|
11
|
+
try {
|
|
12
|
+
for (const name of ["yaml", "playwright", "pngjs", "pixelmatch"]) {
|
|
13
|
+
const directory = join(root, "node_modules", name);
|
|
14
|
+
mkdirSync(directory, { recursive: true });
|
|
15
|
+
writeFileSync(join(directory, "package.json"), JSON.stringify({ type: "module", exports: { import: "./entry.mjs" } }));
|
|
16
|
+
writeFileSync(join(directory, "entry.mjs"), "export const value = 178;");
|
|
17
|
+
assert.equal((await importConsumerPackage(name, root)).value, 178);
|
|
18
|
+
}
|
|
19
|
+
} finally {
|
|
20
|
+
rmSync(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("an installed peer with a missing require entry keeps the resolution error", async (t) => {
|
|
25
|
+
const root = mkdtempSync(join(tmpdir(), "qc-broken-peer-"));
|
|
26
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 }));
|
|
27
|
+
const directory = join(root, "node_modules", "yaml");
|
|
28
|
+
mkdirSync(directory, { recursive: true });
|
|
29
|
+
writeFileSync(join(directory, "package.json"), JSON.stringify({ exports: { require: "./missing.cjs" } }));
|
|
30
|
+
const loader = join(root, "consumer-package.mjs");
|
|
31
|
+
cpSync(new URL("./consumer-package.mjs", import.meta.url), loader);
|
|
32
|
+
const { importConsumerPackage: loadPeer } = await import(pathToFileURL(loader).href);
|
|
33
|
+
await assert.rejects(loadPeer("yaml", root), (error) => {
|
|
34
|
+
assert.equal(error.code, "MODULE_NOT_FOUND");
|
|
35
|
+
assert.match(error.message, /missing\.cjs/);
|
|
36
|
+
assert.doesNotMatch(error.message, /Cannot find package 'yaml'/);
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("consumer package loader rejects names outside the optional peer allowlist", async () => {
|
|
42
|
+
const root = mkdtempSync(join(tmpdir(), "qc-unknown-peer-"));
|
|
43
|
+
try {
|
|
44
|
+
const directory = join(root, "node_modules", "consumer-peer");
|
|
45
|
+
mkdirSync(directory, { recursive: true });
|
|
46
|
+
writeFileSync(join(directory, "package.json"), JSON.stringify({ main: "index.cjs" }));
|
|
47
|
+
writeFileSync(join(directory, "index.cjs"), "throw new Error('unknown package executed');");
|
|
48
|
+
for (const name of ["consumer-peer", "missing-peer-178", "node:fs", "yaml/subpath"]) {
|
|
49
|
+
await assert.rejects(importConsumerPackage(name, root), { message: `Unsupported optional peer '${name}'` });
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
rmSync(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
53
|
+
}
|
|
54
|
+
});
|
package/src/descriptions.mjs
CHANGED
|
@@ -23,10 +23,12 @@ export const gateDescriptions = Object.freeze({
|
|
|
23
23
|
"enforcement-map": "Every rule names a check, and every check the kit runs is named",
|
|
24
24
|
"config-floor": "A check the kit ships on is switched off only by naming the decision that says why",
|
|
25
25
|
"english-source": "Comments, docs and rules are English; another language is data, declared beside its English variant",
|
|
26
|
+
"plain-language": "Prose is Simplified Technical English: one idea per sentence, the active voice, the approved word",
|
|
26
27
|
"adr-format": "Every decision record carries its cost and the alternatives it rejected, not just its claim",
|
|
27
28
|
"comment-style": "A comment under infra/ is one line of why, never a paragraph, a banner or code",
|
|
28
29
|
parity: "Every server slice has a client slice of its name and the reverse, a divergence is registered, and no slice is a no-op",
|
|
29
30
|
"integration-imports": "An integration test imports the product it integrates with",
|
|
31
|
+
"feature-switches": "An unwire constant lives in the feature's switch file, never beside the code that reads it",
|
|
30
32
|
"closed-set-writers": "Every key of a closed set has a writer, and every writer writes a key of the set",
|
|
31
33
|
"tenant-isolation-test": "A feature that owns a tenant table has a test in its folder that calls the two-tenant helper",
|
|
32
34
|
"doc-claims": "A state-claim block in a document still matches the file it counts",
|
package/src/eslint/index.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import durableIdempotencyKey from "./rules/durable-idempotency-key.mjs";
|
|
2
2
|
import externalServiceOnlyInAdapter from "./rules/external-service-only-in-adapter.mjs";
|
|
3
3
|
import imeSafeKey from "./rules/ime-safe-key.mjs";
|
|
4
|
+
import oneComponentPerFile from "./rules/one-component-per-file.mjs";
|
|
5
|
+
import rawElementInPrimitive from "./rules/raw-element-in-primitive.mjs";
|
|
6
|
+
import noArbitraryClassValue from "./rules/no-arbitrary-class-value.mjs";
|
|
7
|
+
import noLiteralColor from "./rules/no-literal-color.mjs";
|
|
8
|
+
import noStaticInlineStyle from "./rules/no-static-inline-style.mjs";
|
|
4
9
|
import mutationControlPending from "./rules/mutation-control-pending.mjs";
|
|
5
10
|
import noCrossFeatureInternals from "./rules/no-cross-feature-internals.mjs";
|
|
6
11
|
import registryLiteral from "./rules/registry-literal.mjs";
|
|
@@ -18,11 +23,17 @@ import scopedRepository from "./rules/scoped-repository.mjs";
|
|
|
18
23
|
import signalLastParam from "./rules/signal-last-param.mjs";
|
|
19
24
|
import storageOnlyInResource from "./rules/storage-only-in-resource.mjs";
|
|
20
25
|
import tenantScopedTable from "./rules/tenant-scoped-table.mjs";
|
|
26
|
+
import timelessComment from "./rules/timeless-comment.mjs";
|
|
21
27
|
|
|
22
28
|
export const rules = {
|
|
23
29
|
"durable-idempotency-key": durableIdempotencyKey,
|
|
24
30
|
"external-service-only-in-adapter": externalServiceOnlyInAdapter,
|
|
25
31
|
"ime-safe-key": imeSafeKey,
|
|
32
|
+
"one-component-per-file": oneComponentPerFile,
|
|
33
|
+
"raw-element-in-primitive": rawElementInPrimitive,
|
|
34
|
+
"no-arbitrary-class-value": noArbitraryClassValue,
|
|
35
|
+
"no-literal-color": noLiteralColor,
|
|
36
|
+
"no-static-inline-style": noStaticInlineStyle,
|
|
26
37
|
"mutation-control-pending": mutationControlPending,
|
|
27
38
|
"no-cross-feature-internals": noCrossFeatureInternals,
|
|
28
39
|
"registry-literal": registryLiteral,
|
|
@@ -40,6 +51,7 @@ export const rules = {
|
|
|
40
51
|
"signal-last-param": signalLastParam,
|
|
41
52
|
"storage-only-in-resource": storageOnlyInResource,
|
|
42
53
|
"tenant-scoped-table": tenantScopedTable,
|
|
54
|
+
"timeless-comment": timelessComment,
|
|
43
55
|
};
|
|
44
56
|
|
|
45
57
|
export default { rules };
|
package/src/eslint/jsx.mjs
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
// What the JSX rules share: reading an element, and resolving an attribute to the function it runs.
|
|
2
2
|
|
|
3
|
+
import { classTokensOf } from "../ui/class-sites.mjs";
|
|
4
|
+
import { loadTypeScript } from "../ui/typescript.mjs";
|
|
5
|
+
|
|
6
|
+
const classFiles = new WeakMap();
|
|
7
|
+
|
|
8
|
+
/** Fragment: reads class tokens through the shared UI parser. */
|
|
9
|
+
export function classTokens(sourceCode, filename, callees) {
|
|
10
|
+
// The compiler loads on first use, so the plugin runtime keeps no bare import.
|
|
11
|
+
const ts = loadTypeScript();
|
|
12
|
+
if (!ts) throw new Error("the class-value rules need the `typescript` package, which neither the repository nor the kit resolves");
|
|
13
|
+
let file = classFiles.get(sourceCode);
|
|
14
|
+
if (!file) {
|
|
15
|
+
const kind = /\.[cm]?ts$/.test(filename) ? ts.ScriptKind.TS : ts.ScriptKind.TSX;
|
|
16
|
+
const parserFilename = /\.[cm]?tsx?$/.test(filename) ? filename : `${filename}.tsx`;
|
|
17
|
+
file = ts.createSourceFile(parserFilename, sourceCode.text, ts.ScriptTarget.Latest, true, kind);
|
|
18
|
+
classFiles.set(sourceCode, file);
|
|
19
|
+
}
|
|
20
|
+
return classTokensOf(ts, file, callees);
|
|
21
|
+
}
|
|
22
|
+
|
|
3
23
|
export const FUNCTIONS = new Set(["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"]);
|
|
4
24
|
|
|
5
25
|
export function tagName(name) {
|
package/src/eslint/preset.mjs
CHANGED
|
@@ -29,6 +29,9 @@ function ruleOptions(config) {
|
|
|
29
29
|
return {
|
|
30
30
|
"no-sql-raw": { allow: config.sqlRaw.allow },
|
|
31
31
|
"ime-safe-key": { components: config.ime.components, guards: config.ime.guards },
|
|
32
|
+
"raw-element-in-primitive": { primitive: config.ui.layers.primitive },
|
|
33
|
+
"no-arbitrary-class-value": { classCallees: config.ui.classCallees },
|
|
34
|
+
"no-literal-color": { classCallees: config.ui.classCallees },
|
|
32
35
|
"mutation-control-pending": {
|
|
33
36
|
button: config.mutationControl.button,
|
|
34
37
|
prop: config.mutationControl.prop,
|
|
@@ -71,6 +74,7 @@ function ruleOptions(config) {
|
|
|
71
74
|
format: config.idempotency.format,
|
|
72
75
|
},
|
|
73
76
|
"no-supersession-trail": {},
|
|
77
|
+
"timeless-comment": timelessVocabulary(config),
|
|
74
78
|
"signal-last-param": {},
|
|
75
79
|
"no-offset-pagination": {},
|
|
76
80
|
"no-status-literal": {},
|
|
@@ -78,7 +82,16 @@ function ruleOptions(config) {
|
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
// Rules on the style of a comment: a finding is advice, so it prints and never fails a change.
|
|
81
|
-
const ADVICE = new Set(["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail"]);
|
|
85
|
+
const ADVICE = new Set(["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail", "timeless-comment"]);
|
|
86
|
+
/** A list a repository states replaces the rule's own; an empty one leaves the rule's defaults. */
|
|
87
|
+
function timelessVocabulary(config) {
|
|
88
|
+
const stated = config.comments?.timeless ?? {};
|
|
89
|
+
const out = {};
|
|
90
|
+
for (const key of ["promises", "moments"]) {
|
|
91
|
+
if (Array.isArray(stated[key]) && stated[key].length > 0) out[key] = stated[key];
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
82
95
|
|
|
83
96
|
function entries(config, names) {
|
|
84
97
|
const options = ruleOptions(config);
|
|
@@ -96,6 +109,7 @@ function entries(config, names) {
|
|
|
96
109
|
const UNIVERSAL = [
|
|
97
110
|
"durable-idempotency-key",
|
|
98
111
|
"no-supersession-trail",
|
|
112
|
+
"timeless-comment",
|
|
99
113
|
"no-comment-paragraph",
|
|
100
114
|
"name-the-pattern",
|
|
101
115
|
"no-number-in-comment",
|
|
@@ -117,7 +131,17 @@ const UNIVERSAL = [
|
|
|
117
131
|
const SERVER = ["storage-only-in-resource", "tenant-scoped-table", "signal-last-param"];
|
|
118
132
|
|
|
119
133
|
/** Rules that only make sense in the browser. */
|
|
120
|
-
const CLIENT = [
|
|
134
|
+
const CLIENT = [
|
|
135
|
+
"no-raw-fetch",
|
|
136
|
+
"storage-only-in-resource",
|
|
137
|
+
"ime-safe-key",
|
|
138
|
+
"mutation-control-pending",
|
|
139
|
+
"one-component-per-file",
|
|
140
|
+
"raw-element-in-primitive",
|
|
141
|
+
"no-arbitrary-class-value",
|
|
142
|
+
"no-literal-color",
|
|
143
|
+
"no-static-inline-style",
|
|
144
|
+
];
|
|
121
145
|
|
|
122
146
|
/**
|
|
123
147
|
* The architecture as a flat config. Spread it, then append your own blocks.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import test from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
7
|
import { tmpdir } from "node:os";
|
|
5
8
|
import path from "node:path";
|
|
6
9
|
import { Linter } from "eslint";
|
|
@@ -175,6 +178,105 @@ test("the mutationControl config reaches qc/mutation-control-pending", () => {
|
|
|
175
178
|
assert.deepEqual(setting[1], { button: "Action", prop: "busy", handlers: ["onClick", "onSelect", "onConfirm"] });
|
|
176
179
|
});
|
|
177
180
|
|
|
181
|
+
test("the UI rules reach only clientFiles and use the configured primitive folders and class callees", () => {
|
|
182
|
+
const names = ["one-component-per-file", "raw-element-in-primitive", "no-arbitrary-class-value", "no-literal-color", "no-static-inline-style"];
|
|
183
|
+
const clientFiles = ["app/**/*.tsx"];
|
|
184
|
+
const blocks = preset({
|
|
185
|
+
config: config({ clientFiles, rules: Object.fromEntries(names.map((name) => [name, true])), ui: { layers: { primitive: ["app/primitives", "app/controls"] }, classCallees: ["classes", "cva"] } }),
|
|
186
|
+
languageOptions: { parser: tsparser },
|
|
187
|
+
});
|
|
188
|
+
const client = blocks.find((block) => block.files === clientFiles);
|
|
189
|
+
for (const name of names) {
|
|
190
|
+
assert.ok(client.rules[`qc/${name}`]);
|
|
191
|
+
assert.equal(emitted(preset({ config: config() })).has(`qc/${name}`), false);
|
|
192
|
+
assert.equal(emitted(blocks.filter((block) => block !== client)).has(`qc/${name}`), false);
|
|
193
|
+
}
|
|
194
|
+
assert.deepEqual(client.rules["qc/raw-element-in-primitive"][1], { primitive: ["app/primitives", "app/controls"] });
|
|
195
|
+
for (const name of names.slice(2, 4)) assert.deepEqual(client.rules[`qc/${name}`][1], { classCallees: ["classes", "cva"] });
|
|
196
|
+
const linter = new Linter({ configType: "flat" });
|
|
197
|
+
const messages = (code, filename, name) => byRule(linter.verify(code, blocks, filename), `qc/${name}`);
|
|
198
|
+
const pair = "const First = () => <div />; const Second = () => <span />;";
|
|
199
|
+
assert.equal(messages(pair, "app/view.tsx", names[0]).length, 2);
|
|
200
|
+
assert.equal(messages(pair, "elsewhere/view.tsx", names[0]).length, 0);
|
|
201
|
+
assert.equal(messages("<input />;", "app/view.tsx", names[1]).length, 1);
|
|
202
|
+
assert.equal(messages("<input />;", "app/controls/input.tsx", names[1]).length, 0);
|
|
203
|
+
assert.equal(messages('classes("text-[11px]");', "app/view.tsx", names[2]).length, 1);
|
|
204
|
+
assert.equal(messages('classes("bg-[#abc]");', "app/view.tsx", names[3]).length, 1);
|
|
205
|
+
for (const name of names.slice(2, 4)) {
|
|
206
|
+
assert.equal(messages('cn("bg-[#abc]");', "app/view.tsx", name).length, 0);
|
|
207
|
+
assert.equal(messages('classes("bg-[#abc]");', "elsewhere/view.tsx", name).length, 0);
|
|
208
|
+
assert.equal(messages('cva("p-2", { variants: { tone: { custom: "bg-[#abc]" } } });', "app/view.tsx", name).length, 1);
|
|
209
|
+
}
|
|
210
|
+
assert.equal(messages('<div style={{ width: 12 }} />;', "app/view.tsx", names[4]).length, 1);
|
|
211
|
+
assert.equal(messages('<div style={{ width: size }} />;', "app/view.tsx", names[4]).length, 0);
|
|
212
|
+
assert.equal(messages('<div style={{ width: 12 }} />;', "elsewhere/view.tsx", names[4]).length, 0);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
for (const source of ["hand-written", "ESLint-generated"]) {
|
|
216
|
+
test(`qc lint applies the ${source} UI baseline and fails on a stale entry`, () => {
|
|
217
|
+
const root = mkdtempSync(path.join(tmpdir(), "qc-ui-suppressions-"));
|
|
218
|
+
const require = createRequire(import.meta.url);
|
|
219
|
+
const cli = fileURLToPath(new URL("../cli/qc.mjs", import.meta.url));
|
|
220
|
+
const parser = pathToFileURL(require.resolve("@typescript-eslint/parser")).href;
|
|
221
|
+
const presetUrl = new URL("./preset.mjs", import.meta.url).href;
|
|
222
|
+
const configUrl = new URL("../config.mjs", import.meta.url).href;
|
|
223
|
+
const switches = Object.fromEntries(Object.keys(allRules).map((name) => [name, name === "no-static-inline-style"]));
|
|
224
|
+
const run = (...args) => {
|
|
225
|
+
const result = spawnSync(process.execPath, [cli, "lint", ...args], { cwd: root, encoding: "utf8", timeout: 30_000 });
|
|
226
|
+
assert.ifError(result.error);
|
|
227
|
+
return { status: result.status, output: `${result.stdout}\n${result.stderr}` };
|
|
228
|
+
};
|
|
229
|
+
try {
|
|
230
|
+
const init = spawnSync("git", ["init", "-q"], { cwd: root, encoding: "utf8" });
|
|
231
|
+
assert.equal(init.status, 0, init.stderr);
|
|
232
|
+
mkdirSync(path.join(root, "node_modules"));
|
|
233
|
+
symlinkSync(path.dirname(require.resolve("eslint/package.json")), path.join(root, "node_modules", "eslint"), "junction");
|
|
234
|
+
writeFileSync(path.join(root, ".gitignore"), "node_modules/\n");
|
|
235
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify({ featureRoots: [] }));
|
|
236
|
+
writeFileSync(path.join(root, "eslint.config.mjs"), `
|
|
237
|
+
import parser from ${JSON.stringify(parser)};
|
|
238
|
+
import { preset } from ${JSON.stringify(presetUrl)};
|
|
239
|
+
import { defaults, merge } from ${JSON.stringify(configUrl)};
|
|
240
|
+
export default preset({
|
|
241
|
+
config: { ...merge(defaults, ${JSON.stringify({ clientFiles: ["**/*.tsx"], rules: switches })}), root: process.cwd() },
|
|
242
|
+
languageOptions: { parser },
|
|
243
|
+
});
|
|
244
|
+
`);
|
|
245
|
+
const relativeFixture = source === "ESLint-generated" ? "src/view.tsx" : "view.tsx";
|
|
246
|
+
const fixture = path.join(root, relativeFixture);
|
|
247
|
+
mkdirSync(path.dirname(fixture), { recursive: true });
|
|
248
|
+
writeFileSync(fixture, '<div style={{ width: 12 }} />;\n');
|
|
249
|
+
const unsuppressed = run();
|
|
250
|
+
assert.equal(unsuppressed.status, 1, unsuppressed.output);
|
|
251
|
+
assert.match(unsuppressed.output, /qc\/no-static-inline-style/);
|
|
252
|
+
if (source === "ESLint-generated") {
|
|
253
|
+
const eslint = path.join(path.dirname(require.resolve("eslint/package.json")), "bin", "eslint.js");
|
|
254
|
+
const result = spawnSync(process.execPath, [eslint, relativeFixture, "--suppress-rule", "qc/no-static-inline-style"], { cwd: root, encoding: "utf8", timeout: 30_000 });
|
|
255
|
+
assert.ifError(result.error);
|
|
256
|
+
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
257
|
+
} else {
|
|
258
|
+
writeFileSync(path.join(root, "eslint-suppressions.json"), JSON.stringify({ "view.tsx": { "qc/no-static-inline-style": { count: 1 } } }));
|
|
259
|
+
}
|
|
260
|
+
const generated = run();
|
|
261
|
+
assert.equal(generated.status, 0, generated.output);
|
|
262
|
+
const baseline = JSON.parse(readFileSync(path.join(root, "eslint-suppressions.json"), "utf8"));
|
|
263
|
+
assert.equal(baseline[relativeFixture]["qc/no-static-inline-style"].count, 1);
|
|
264
|
+
const existing = run();
|
|
265
|
+
assert.equal(existing.status, 0, existing.output);
|
|
266
|
+
writeFileSync(fixture, '<><div style={{ width: 12 }} /><div style={{ height: 8 }} /></>;\n');
|
|
267
|
+
const increased = run();
|
|
268
|
+
assert.equal(increased.status, 1, increased.output);
|
|
269
|
+
assert.match(increased.output, /qc\/no-static-inline-style/);
|
|
270
|
+
writeFileSync(fixture, '<div style={{ width: size }} />;\n');
|
|
271
|
+
const stale = run();
|
|
272
|
+
assert.equal(stale.status, 2, stale.output);
|
|
273
|
+
assert.match(stale.output, /suppressions left that do not occur anymore/i);
|
|
274
|
+
} finally {
|
|
275
|
+
rmSync(root, { recursive: true, force: true });
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
178
280
|
test("the preset reports an unused disable comment in every file", () => {
|
|
179
281
|
const block = preset({ config: config() }).find((b) => b.linterOptions);
|
|
180
282
|
assert.ok(block, "no linterOptions block emitted");
|
|
@@ -191,7 +293,7 @@ test("a disable comment silences its rule, and one that silences nothing is an e
|
|
|
191
293
|
|
|
192
294
|
test("a comment-style rule warns, and a rule of the reference stack is off until a repository turns it on", () => {
|
|
193
295
|
const rules = emitted(preset({ config: config() }));
|
|
194
|
-
for (const name of ["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail"]) assert.equal([rules.get(`qc/${name}`)].flat()[0], "warn", name);
|
|
296
|
+
for (const name of ["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail", "timeless-comment"]) assert.equal([rules.get(`qc/${name}`)].flat()[0], "warn", name);
|
|
195
297
|
for (const name of ["no-offset-pagination", "no-status-literal", "no-promise-then", "signal-last-param", "ime-safe-key"]) assert.equal(rules.get(`qc/${name}`), undefined, name);
|
|
196
298
|
assert.equal([emitted(preset({ config: config({ rules: { "no-offset-pagination": true } }) })).get("qc/no-offset-pagination")].flat()[0], "error");
|
|
197
299
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Branch: class values come from the theme tokens.
|
|
2
|
+
|
|
3
|
+
import { defaults } from "../../config.mjs";
|
|
4
|
+
import { classTokens } from "../jsx.mjs";
|
|
5
|
+
import { optionsOf, schemaOf } from "../options.mjs";
|
|
6
|
+
|
|
7
|
+
const ARBITRARY = /(?:^|:)!?-?[\w-]+-\[.+\](?:\/(?:\[[^\]]+\]|[\w.]+))?!?$|(?:^|:)!?\[[^\]]+\]!?$|\/\[[^\]]+\]!?$/;
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
meta: {
|
|
11
|
+
type: "suggestion",
|
|
12
|
+
docs: { description: "Use theme tokens instead of arbitrary class values." },
|
|
13
|
+
schema: schemaOf({ classCallees: { type: "array", items: { type: "string" } } }),
|
|
14
|
+
messages: { arbitrary: "Class {{token}} uses an arbitrary value. Use a theme token." },
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
const callees = optionsOf(context).classCallees ?? defaults.ui.classCallees;
|
|
18
|
+
const sourceCode = context.sourceCode;
|
|
19
|
+
return {
|
|
20
|
+
"Program:exit"() {
|
|
21
|
+
for (const token of classTokens(sourceCode, context.filename, callees)) {
|
|
22
|
+
if (!ARBITRARY.test(token.text)) continue;
|
|
23
|
+
context.report({
|
|
24
|
+
loc: { start: sourceCode.getLocFromIndex(token.start), end: sourceCode.getLocFromIndex(token.end) },
|
|
25
|
+
messageId: "arbitrary",
|
|
26
|
+
data: { token: token.text },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Branch: presentation values use color tokens.
|
|
2
|
+
|
|
3
|
+
import { defaults } from "../../config.mjs";
|
|
4
|
+
import { classTokens, lookup } from "../jsx.mjs";
|
|
5
|
+
import { optionsOf, schemaOf } from "../options.mjs";
|
|
6
|
+
|
|
7
|
+
const COLOR = /#(?:[\da-f]{8}|[\da-f]{6}|[\da-f]{4}|[\da-f]{3})(?![\w-])|(?:^|[^a-z])(?:rgba?|hsla?)\(\s*[+-]?(?:\d|\.)/i;
|
|
8
|
+
const PRESENTATION = new Set(["color", "fill", "stroke", "stopColor", "stop-color", "floodColor", "flood-color", "lightingColor", "lighting-color", "bgColor", "bgcolor", "backgroundColor", "borderColor", "outlineColor", "textDecorationColor", "caretColor", "accentColor"]);
|
|
9
|
+
const STYLE_COLOR = /color$|^(?:background|border(?:Top|Right|Bottom|Left)?|outline|boxShadow|textShadow|fill|stroke|columnRule|textDecoration)$/i;
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "suggestion",
|
|
14
|
+
docs: { description: "Use color tokens instead of literal colors in presentation values." },
|
|
15
|
+
schema: schemaOf({ classCallees: { type: "array", items: { type: "string" } } }),
|
|
16
|
+
messages: { color: "Use a color token instead of a hex, rgb(), rgba(), hsl(), or hsla() literal." },
|
|
17
|
+
},
|
|
18
|
+
create(context) {
|
|
19
|
+
const sourceCode = context.sourceCode;
|
|
20
|
+
const callees = optionsOf(context).classCallees ?? defaults.ui.classCallees;
|
|
21
|
+
const reported = new Set();
|
|
22
|
+
|
|
23
|
+
function reportBranch(node, text) {
|
|
24
|
+
if (!COLOR.test(text) || reported.has(node)) return;
|
|
25
|
+
reported.add(node);
|
|
26
|
+
context.report({ node, messageId: "color" });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function inspectBranch(node, seen = new Set()) {
|
|
30
|
+
if (!node || seen.has(node)) return;
|
|
31
|
+
seen.add(node);
|
|
32
|
+
if (node.type === "Literal" && typeof node.value === "string") reportBranch(node, node.value);
|
|
33
|
+
else if (node.type === "TemplateLiteral") {
|
|
34
|
+
for (const part of node.quasis) reportBranch(part, part.value.cooked ?? part.value.raw);
|
|
35
|
+
for (const expression of node.expressions) inspectBranch(expression, seen);
|
|
36
|
+
} else if (node.type === "Identifier") {
|
|
37
|
+
const definition = lookup(sourceCode, node)?.defs[0];
|
|
38
|
+
if (definition?.type === "Variable" && definition.parent.kind === "const") inspectBranch(definition.node.init, seen);
|
|
39
|
+
} else if (node.type === "ConditionalExpression") {
|
|
40
|
+
inspectBranch(node.consequent, seen);
|
|
41
|
+
inspectBranch(node.alternate, seen);
|
|
42
|
+
} else if (node.type === "LogicalExpression") {
|
|
43
|
+
if (node.operator !== "&&") inspectBranch(node.left, seen);
|
|
44
|
+
inspectBranch(node.right, seen);
|
|
45
|
+
}
|
|
46
|
+
else if (node.type === "ObjectExpression") {
|
|
47
|
+
for (const property of node.properties) inspectBranch(property.type === "SpreadElement" ? property.argument : property.value, seen);
|
|
48
|
+
} else if (node.type === "ArrayExpression") {
|
|
49
|
+
for (const element of node.elements) inspectBranch(element, seen);
|
|
50
|
+
} else if (["JSXExpressionContainer", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"].includes(node.type)) {
|
|
51
|
+
inspectBranch(node.expression, seen);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function inspectStyle(node, seen = new Set()) {
|
|
56
|
+
if (!node || seen.has(node)) return;
|
|
57
|
+
seen.add(node);
|
|
58
|
+
if (node.type === "ObjectExpression") {
|
|
59
|
+
for (const property of node.properties) {
|
|
60
|
+
if (property.type === "SpreadElement") inspectStyle(property.argument, seen);
|
|
61
|
+
else if (!property.computed && property.kind === "init" && STYLE_COLOR.test(property.key.name ?? property.key.value)) inspectBranch(property.value);
|
|
62
|
+
}
|
|
63
|
+
} else if (node.type === "Identifier") {
|
|
64
|
+
const definition = lookup(sourceCode, node)?.defs[0];
|
|
65
|
+
if (definition?.type === "Variable" && definition.parent.kind === "const") inspectStyle(definition.node.init, seen);
|
|
66
|
+
} else if (node.type === "ConditionalExpression") {
|
|
67
|
+
inspectStyle(node.consequent, seen);
|
|
68
|
+
inspectStyle(node.alternate, seen);
|
|
69
|
+
} else if (node.type === "LogicalExpression") {
|
|
70
|
+
if (node.operator !== "&&") inspectStyle(node.left, seen);
|
|
71
|
+
inspectStyle(node.right, seen);
|
|
72
|
+
} else if (["JSXExpressionContainer", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"].includes(node.type)) {
|
|
73
|
+
inspectStyle(node.expression, seen);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
JSXAttribute(node) {
|
|
79
|
+
const name = node.name.name;
|
|
80
|
+
if (name === "style") inspectStyle(node.value);
|
|
81
|
+
else if (PRESENTATION.has(name)) inspectBranch(node.value);
|
|
82
|
+
},
|
|
83
|
+
"Program:exit"() {
|
|
84
|
+
for (const token of classTokens(sourceCode, context.filename, callees)) {
|
|
85
|
+
if (!COLOR.test(token.text)) continue;
|
|
86
|
+
context.report({
|
|
87
|
+
loc: { start: sourceCode.getLocFromIndex(token.start), end: sourceCode.getLocFromIndex(token.end) },
|
|
88
|
+
messageId: "color",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { tagName } from "../jsx.mjs";
|
|
2
|
+
import { schemaOf } from "../options.mjs";
|
|
3
|
+
|
|
4
|
+
/** Branch: unwraps type assertions before classifying the style expression. */
|
|
5
|
+
function expressionOf(node) {
|
|
6
|
+
while (["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression"].includes(node?.type)) {
|
|
7
|
+
node = node.expression;
|
|
8
|
+
}
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Branch: recognizes literal values without evaluating runtime expressions. */
|
|
13
|
+
function isLiteral(node) {
|
|
14
|
+
node = expressionOf(node);
|
|
15
|
+
if (node.type === "Literal") return true;
|
|
16
|
+
if (node.type === "TemplateLiteral") return node.expressions.length === 0;
|
|
17
|
+
return node.type === "UnaryExpression" && ["-", "+"].includes(node.operator) &&
|
|
18
|
+
node.argument.type === "Literal" && typeof node.argument.value === "number";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
meta: {
|
|
23
|
+
type: "problem",
|
|
24
|
+
docs: { description: "Use classes for static presentation and inline styles for runtime values" },
|
|
25
|
+
schema: schemaOf({}),
|
|
26
|
+
messages: { static: "Move static inline styles to a class or theme token; reserve style for runtime values." },
|
|
27
|
+
},
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
JSXAttribute(node) {
|
|
31
|
+
if (tagName(node.name) !== "style" || node.value?.type !== "JSXExpressionContainer") return;
|
|
32
|
+
const object = expressionOf(node.value.expression);
|
|
33
|
+
if (object?.type !== "ObjectExpression" || object.properties.length === 0) return;
|
|
34
|
+
const literal = object.properties.every((property) =>
|
|
35
|
+
property.type === "Property" && property.kind === "init" && !property.method &&
|
|
36
|
+
(!property.computed || isLiteral(property.key)) && isLiteral(property.value));
|
|
37
|
+
if (literal) context.report({ node, messageId: "static" });
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Branch: each TSX file owns one component declaration.
|
|
2
|
+
|
|
3
|
+
import { FUNCTIONS, lookup, propertyName, walk } from "../jsx.mjs";
|
|
4
|
+
import { filenameOf, schemaOf } from "../options.mjs";
|
|
5
|
+
|
|
6
|
+
function returnsJsxBranch(node) {
|
|
7
|
+
if (!node) return false;
|
|
8
|
+
if (node.type === "JSXElement" || node.type === "JSXFragment") return true;
|
|
9
|
+
if (node.type === "ConditionalExpression") return returnsJsxBranch(node.consequent) || returnsJsxBranch(node.alternate);
|
|
10
|
+
if (node.type === "LogicalExpression") return returnsJsxBranch(node.left) || returnsJsxBranch(node.right);
|
|
11
|
+
if (node.type === "SequenceExpression") return returnsJsxBranch(node.expressions.at(-1));
|
|
12
|
+
if (["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"].includes(node.type)) {
|
|
13
|
+
return returnsJsxBranch(node.expression);
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function componentBranch(node, keys) {
|
|
19
|
+
if (!node) return false;
|
|
20
|
+
if (node.type === "CallExpression") return ["forwardRef", "memo"].includes(node.callee.name ?? propertyName(node.callee));
|
|
21
|
+
if (["TSAsExpression", "TSSatisfiesExpression"].includes(node.type)) return componentBranch(node.expression, keys);
|
|
22
|
+
if (!FUNCTIONS.has(node.type)) return false;
|
|
23
|
+
if (node.body.type !== "BlockStatement") return returnsJsxBranch(node.body);
|
|
24
|
+
let found = false;
|
|
25
|
+
walk(node.body, keys, (child) => {
|
|
26
|
+
if (child.type === "ReturnStatement" && returnsJsxBranch(child.argument)) found = true;
|
|
27
|
+
});
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
meta: {
|
|
33
|
+
type: "suggestion",
|
|
34
|
+
docs: { description: "Declare at most one React component per TSX file." },
|
|
35
|
+
schema: schemaOf({}),
|
|
36
|
+
messages: { multiple: "Components {{first}} and {{second}} share a file. Move each component into its own file." },
|
|
37
|
+
},
|
|
38
|
+
create(context) {
|
|
39
|
+
if (!filenameOf(context).endsWith(".tsx")) return {};
|
|
40
|
+
const components = [];
|
|
41
|
+
const keys = context.sourceCode.visitorKeys;
|
|
42
|
+
function collectBranch(node, name, value) {
|
|
43
|
+
if (/^[A-Z]/.test(name ?? "") && componentBranch(value, keys)) components.push({ node, name, value });
|
|
44
|
+
}
|
|
45
|
+
function wrappedDeclaration(value) {
|
|
46
|
+
if (!value) return null;
|
|
47
|
+
if (["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"].includes(value.type)) return wrappedDeclaration(value.expression);
|
|
48
|
+
if (value.type === "CallExpression" && ["forwardRef", "memo"].includes(value.callee.name ?? propertyName(value.callee))) return wrappedDeclaration(value.arguments[0]);
|
|
49
|
+
return value.type === "Identifier" ? lookup(context.sourceCode, value)?.defs[0]?.node : null;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
FunctionDeclaration(node) {
|
|
53
|
+
collectBranch(node, node.id?.name, node);
|
|
54
|
+
},
|
|
55
|
+
VariableDeclarator(node) {
|
|
56
|
+
if (node.id.type === "Identifier") collectBranch(node, node.id.name, node.init);
|
|
57
|
+
},
|
|
58
|
+
"Program:exit"() {
|
|
59
|
+
const declarations = new Set(components.map((component) => component.node));
|
|
60
|
+
const distinct = components.filter((component) => !declarations.has(wrappedDeclaration(component.value)));
|
|
61
|
+
distinct.sort((left, right) => left.node.range[0] - right.node.range[0]);
|
|
62
|
+
if (distinct.length < 2) return;
|
|
63
|
+
for (const component of distinct) {
|
|
64
|
+
const other = component === distinct[0] ? distinct[1] : component;
|
|
65
|
+
context.report({ node: component.node, messageId: "multiple", data: { first: distinct[0].name, second: other.name } });
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Branch: primitive folders own raw form controls and dialogs.
|
|
2
|
+
|
|
3
|
+
import { tagName } from "../jsx.mjs";
|
|
4
|
+
import { filenameOf, optionsOf, pathPrefix, schemaOf } from "../options.mjs";
|
|
5
|
+
|
|
6
|
+
const ELEMENTS = ["form", "dialog", "input", "select", "textarea", "button"];
|
|
7
|
+
const PRIMITIVE = "frontend/src/platform/ui/primitives";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
meta: {
|
|
11
|
+
type: "suggestion",
|
|
12
|
+
docs: { description: "Use raw form elements only in primitive folders." },
|
|
13
|
+
schema: schemaOf({
|
|
14
|
+
elements: { type: "array", items: { type: "string" } },
|
|
15
|
+
primitive: { anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }] },
|
|
16
|
+
}),
|
|
17
|
+
messages: { raw: "Raw <{{element}}> belongs in a primitive folder. Use a primitive component here." },
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const options = optionsOf(context);
|
|
21
|
+
const folders = [options.primitive ?? PRIMITIVE].flat().map((folder) => pathPrefix(folder.replaceAll("\\", "/")));
|
|
22
|
+
if (folders.some((folder) => folder.test(filenameOf(context)))) return {};
|
|
23
|
+
const elements = new Set(options.elements ?? ELEMENTS);
|
|
24
|
+
return {
|
|
25
|
+
JSXOpeningElement(node) {
|
|
26
|
+
const element = tagName(node.name);
|
|
27
|
+
if (elements.has(element)) context.report({ node, messageId: "raw", data: { element } });
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|