@behavioral-agentic-design-system/core 0.36.0 → 0.38.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 +8 -4
- package/scripts/a11y-lint.cjs +8 -2
- package/scripts/a11y-ratchet.mjs +172 -0
- package/scripts/accent-as-text.mjs +274 -0
- package/scripts/bads-doctor.mjs +2 -1
- package/scripts/check-stories.mjs +265 -52
- package/scripts/contrast.mjs +44 -0
- package/scripts/health-report.mjs +211 -122
- package/scripts/lint-slop.mjs +46 -64
- package/scripts/oklch-to-hex.cjs +7 -1
- package/scripts/ratchet.mjs +326 -0
- package/scripts/slop-rules.mjs +233 -0
- package/scripts/token-nearest.mjs +333 -0
- package/scripts/wcag-audit.cjs +59 -8
- package/src/app/preview/components/page.tsx +1 -0
- package/src/components/ui/combobox.tsx +8 -0
- package/src/components/ui/multi-select.tsx +16 -1
- package/src/data/docs-index.ts +5 -0
- package/src/lib/theme-editor.ts +7 -1
- package/src/stories/Combobox.stories.tsx +48 -0
- package/src/stories/MultiSelect.stories.tsx +36 -0
|
@@ -20,139 +20,228 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import fs from "node:fs";
|
|
22
22
|
import path from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a package-owned path. This script ships inside the @core package
|
|
27
|
+
* itself -- packages/core/scripts/ in upstream's own checkout, and again
|
|
28
|
+
* inside node_modules/@behavioral-agentic-design-system/core/scripts/ once a
|
|
29
|
+
* fork installs it -- so package-owned content always sits at a fixed
|
|
30
|
+
* position relative to wherever THIS module's own file actually resolved
|
|
31
|
+
* to. import.meta.url follows any symlink Node used to reach this file, so
|
|
32
|
+
* this is exact regardless of pnpm's store layout, hoisting, or a package
|
|
33
|
+
* rename.
|
|
34
|
+
*
|
|
35
|
+
* This used to check the consumer's own root first and only fall back to
|
|
36
|
+
* the installed package. But a fork's packages/core/src/** is a stub by the
|
|
37
|
+
* premise of this whole branch (see BADS_SYNC.md): an empty stub directory
|
|
38
|
+
* or a placeholder page.tsx satisfies existsSync and silently masked the
|
|
39
|
+
* real, installed copy, producing full-weight penalties instead of an
|
|
40
|
+
* unavailable marker. Resolving off import.meta.url removes that fork-local
|
|
41
|
+
* guess entirely. In upstream's own checkout this lands on the exact same
|
|
42
|
+
* file the old root-relative path always did, so it is a simplification,
|
|
43
|
+
* not a special case.
|
|
44
|
+
*
|
|
45
|
+
* Returns null when the resolved path does not exist, so callers degrade
|
|
46
|
+
* rather than throw.
|
|
47
|
+
*/
|
|
48
|
+
function resolvePackageOwned(relPath) {
|
|
49
|
+
const resolved = fileURLToPath(new URL(`../${relPath}`, import.meta.url));
|
|
50
|
+
return fs.existsSync(resolved) ? resolved : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function main() {
|
|
54
|
+
// Repo-root resolution is cwd-based (not file-relative) so this works both in
|
|
55
|
+
// upstream BADS (scripts/ -> repo root) and after shipping as a package bin
|
|
56
|
+
// into a client fork, invoked as `npx bads-health-report` from the fork's own
|
|
57
|
+
// repo root.
|
|
58
|
+
const ROOT = process.cwd();
|
|
59
|
+
const argv = process.argv.slice(2);
|
|
60
|
+
const DATE = argv.find((a) => a.startsWith("--date="))?.split("=")[1] || new Date().toISOString().slice(0, 10);
|
|
61
|
+
const DRIFT = argv.includes("--drift");
|
|
62
|
+
|
|
63
|
+
const read = (p) => fs.readFileSync(path.join(ROOT, p), "utf8");
|
|
64
|
+
const readJsonl = (p) => {
|
|
65
|
+
const full = path.join(ROOT, p);
|
|
66
|
+
if (!fs.existsSync(full)) return [];
|
|
67
|
+
return read(p).split("\n").filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
68
|
+
};
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const registry = JSON.parse(read("layer-5-component-registry/component-registry.json"));
|
|
71
|
+
const uxRows = readJsonl("ledgers/ux-tests.jsonl");
|
|
72
|
+
const buildRows = readJsonl("ledgers/component-builds.jsonl");
|
|
73
|
+
const corrections = fs.existsSync(path.join(ROOT, "corrections.md")) ? read("corrections.md") : "";
|
|
74
|
+
|
|
75
|
+
// Package-owned inputs: resolved off this script's own location (see
|
|
76
|
+
// resolvePackageOwned), never off the consumer's ROOT, because a fork's
|
|
77
|
+
// own packages/core/src/** is a stub. Degrade with a clear log line rather
|
|
78
|
+
// than throw when the package copy is missing. Callers treat the
|
|
79
|
+
// resulting null/empty state as "signal unavailable", never as a passing
|
|
80
|
+
// (or artificially failing) score.
|
|
81
|
+
const showcasePath = resolvePackageOwned("src/app/preview/components/page.tsx");
|
|
82
|
+
let showcase = null;
|
|
83
|
+
if (showcasePath) {
|
|
84
|
+
showcase = fs.readFileSync(showcasePath, "utf8");
|
|
85
|
+
} else {
|
|
86
|
+
console.error(
|
|
87
|
+
"health-report: showcase page not found locally or in the installed package (packages/core/src/app/preview/components/page.tsx); showcase-presence signal unavailable."
|
|
88
|
+
);
|
|
71
89
|
}
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
const storiesDirPath = resolvePackageOwned("src/stories");
|
|
92
|
+
let storyFiles = null;
|
|
93
|
+
if (storiesDirPath) {
|
|
94
|
+
// case-insensitive: the QrCode/QRCode story case-collision fix means registry
|
|
95
|
+
// name casing and story filename casing can legitimately differ
|
|
96
|
+
storyFiles = new Set(fs.readdirSync(storiesDirPath).map((f) => f.toLowerCase()));
|
|
97
|
+
} else {
|
|
98
|
+
console.error(
|
|
99
|
+
"health-report: stories directory not found locally or in the installed package (packages/core/src/stories); story-presence signal unavailable."
|
|
100
|
+
);
|
|
79
101
|
}
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else if (e.costModel.lastReviewedAt && daysBetween(DATE, e.costModel.lastReviewedAt) > 180)
|
|
87
|
-
penalties.push({ source: "registry", points: 5, why: `costModel last reviewed ${e.costModel.lastReviewedAt}` });
|
|
88
|
-
|
|
89
|
-
// structure: story + showcase presence — REQUIRED only for components whose
|
|
90
|
-
// source ships inside @core (the Storybook rule's scope). Repo-root
|
|
91
|
-
// compositions (bucket C) live in feature tabs, not the components page.
|
|
92
|
-
const inCore = fs.existsSync(path.join(ROOT, "packages/core/src/components/ui", `${kebab(name)}.tsx`));
|
|
93
|
-
if (inCore) {
|
|
94
|
-
if (!storyFiles.has(`${name.toLowerCase()}.stories.tsx`)) penalties.push({ source: "stories", points: 10, why: "no story file (STORYBOOK_RULE violation)" });
|
|
95
|
-
if (!showcase.includes(`<${name}`) && !showcase.includes(`${name}Showcase`) && !showcase.includes(`title="${name}"`))
|
|
96
|
-
penalties.push({ source: "showcase", points: 5, why: "not demonstrated in the components showcase" });
|
|
103
|
+
const uiDirPath = resolvePackageOwned("src/components/ui");
|
|
104
|
+
if (!uiDirPath) {
|
|
105
|
+
console.error(
|
|
106
|
+
"health-report: components/ui directory not found locally or in the installed package (packages/core/src/components/ui); story/showcase presence signals unavailable for every component."
|
|
107
|
+
);
|
|
97
108
|
}
|
|
98
109
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
const kebab = (s) => s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
111
|
+
const daysBetween = (a, b) => Math.round((new Date(a) - new Date(b)) / 86400000);
|
|
112
|
+
|
|
113
|
+
const UX_PENALTY = { BLOCKER: 25, HIGH: 15, MEDIUM: 8, LOW: 3, none: 0 };
|
|
114
|
+
|
|
115
|
+
const components = Object.keys(registry).sort().map((name) => {
|
|
116
|
+
const e = registry[name];
|
|
117
|
+
const penalties = [];
|
|
118
|
+
let dataPoints = 0;
|
|
119
|
+
|
|
120
|
+
// signal: ux-test findings (rows match on the component field)
|
|
121
|
+
for (const r of uxRows.filter((r) => r.component === name)) {
|
|
122
|
+
dataPoints++;
|
|
123
|
+
const p = UX_PENALTY[r.severity] ?? 0;
|
|
124
|
+
if (p) penalties.push({ source: "ux-test", points: p, why: `${r.severity}: ${String(r.finding || "").slice(0, 100)}` });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// signal: corrections recurrences (word-boundary name mentions, capped)
|
|
128
|
+
const mentions = (corrections.match(new RegExp(`\\b${name}\\b`, "g")) || []).length;
|
|
129
|
+
if (mentions) {
|
|
130
|
+
dataPoints += mentions;
|
|
131
|
+
penalties.push({ source: "corrections", points: Math.min(mentions * 5, 15), why: `${mentions} mention(s) in corrections.md` });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// signal: build-ledger outcome (latest row for this component)
|
|
135
|
+
const builds = buildRows.filter((r) => (r.candidate || "").split(" ")[0] === name);
|
|
136
|
+
if (builds.length) {
|
|
137
|
+
dataPoints += builds.length;
|
|
138
|
+
const last = builds[builds.length - 1];
|
|
139
|
+
if (last.status === "rejected") penalties.push({ source: "build-ledger", points: 10, why: "last build attempt rejected by gates" });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// structure: registry completeness (these are hygiene, not incidents)
|
|
143
|
+
if (!e.a11yContract) penalties.push({ source: "registry", points: 10, why: "no a11yContract" });
|
|
144
|
+
if (!e.antiPatterns?.length) penalties.push({ source: "registry", points: 5, why: "no antiPatterns" });
|
|
145
|
+
if (!e.examples?.length) penalties.push({ source: "registry", points: 5, why: "no examples" });
|
|
146
|
+
if (!e.costModel) penalties.push({ source: "registry", points: 5, why: "no costModel" });
|
|
147
|
+
else if (e.costModel.lastReviewedAt && daysBetween(DATE, e.costModel.lastReviewedAt) > 180)
|
|
148
|
+
penalties.push({ source: "registry", points: 5, why: `costModel last reviewed ${e.costModel.lastReviewedAt}` });
|
|
149
|
+
|
|
150
|
+
// structure: story + showcase presence: REQUIRED only for components whose
|
|
151
|
+
// source ships inside @core (the Storybook rule's scope). Repo-root
|
|
152
|
+
// compositions (bucket C) live in feature tabs, not the components page.
|
|
153
|
+
const inCore = uiDirPath !== null && fs.existsSync(path.join(uiDirPath, `${kebab(name)}.tsx`));
|
|
154
|
+
if (inCore) {
|
|
155
|
+
if (storyFiles === null) {
|
|
156
|
+
penalties.push({ source: "stories", points: 0, why: "story-presence signal unavailable (stories directory not found locally or in the package)" });
|
|
157
|
+
} else if (!storyFiles.has(`${name.toLowerCase()}.stories.tsx`)) {
|
|
158
|
+
penalties.push({ source: "stories", points: 10, why: "no story file (STORYBOOK_RULE violation)" });
|
|
159
|
+
}
|
|
160
|
+
if (showcase === null) {
|
|
161
|
+
penalties.push({ source: "showcase", points: 0, why: "showcase-presence signal unavailable (showcase page not found locally or in the package)" });
|
|
162
|
+
} else if (!showcase.includes(`<${name}`) && !showcase.includes(`${name}Showcase`) && !showcase.includes(`title="${name}"`)) {
|
|
163
|
+
penalties.push({ source: "showcase", points: 5, why: "not demonstrated in the components showcase" });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const score = Math.max(0, 100 - penalties.reduce((s, p) => s + p.points, 0));
|
|
168
|
+
return {
|
|
169
|
+
name,
|
|
170
|
+
score,
|
|
171
|
+
band: score >= 90 ? "healthy" : score >= 70 ? "watch" : "attention",
|
|
172
|
+
insufficientData: dataPoints === 0,
|
|
173
|
+
dataPoints,
|
|
174
|
+
penalties: penalties.sort((a, b) => b.points - a.points),
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const known = components.filter((c) => !c.insufficientData);
|
|
179
|
+
const summary = {
|
|
180
|
+
components: components.length,
|
|
181
|
+
scored: known.length,
|
|
182
|
+
insufficientData: components.length - known.length,
|
|
183
|
+
avgScore: known.length ? Math.round(known.reduce((s, c) => s + c.score, 0) / known.length) : null,
|
|
184
|
+
bands: {
|
|
185
|
+
healthy: components.filter((c) => c.band === "healthy").length,
|
|
186
|
+
watch: components.filter((c) => c.band === "watch").length,
|
|
187
|
+
attention: components.filter((c) => c.band === "attention").length,
|
|
188
|
+
},
|
|
107
189
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (prior) {
|
|
134
|
-
const prev = JSON.parse(read(path.join("ledgers", "reports", prior)));
|
|
135
|
-
const prevScores = Object.fromEntries(prev.components.map((c) => [c.name, c.score]));
|
|
136
|
-
const drops = components.filter((c) => prevScores[c.name] != null && prevScores[c.name] - c.score > 10);
|
|
137
|
-
if (drops.length) {
|
|
138
|
-
const rows = drops.map((c) => JSON.stringify({
|
|
139
|
-
schemaVersion: "1", date: DATE, source: "health", rule: "score-drop",
|
|
140
|
-
target: c.name, severity: c.band === "attention" ? "high" : "medium",
|
|
141
|
-
signal: `health ${prevScores[c.name]} → ${c.score} since ${prior.slice(7, 14)}`,
|
|
142
|
-
evidence: c.penalties[0]?.why || "", status: "open",
|
|
143
|
-
}));
|
|
144
|
-
fs.appendFileSync(path.join(ROOT, "ledgers", "drift.jsonl"), rows.join("\n") + "\n");
|
|
145
|
-
console.log(`drift: logged ${rows.length} score drop(s) to ledgers/drift.jsonl`);
|
|
190
|
+
|
|
191
|
+
const month = DATE.slice(0, 7);
|
|
192
|
+
const outPath = path.join(ROOT, "ledgers", "reports", `health-${month}.json`);
|
|
193
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
194
|
+
|
|
195
|
+
// --drift: compare against the most recent PRIOR report before overwriting
|
|
196
|
+
if (DRIFT) {
|
|
197
|
+
const prior = fs.readdirSync(path.dirname(outPath))
|
|
198
|
+
.filter((f) => /^health-\d{4}-\d{2}\.json$/.test(f) && f < `health-${month}.json`)
|
|
199
|
+
.sort()
|
|
200
|
+
.pop();
|
|
201
|
+
if (prior) {
|
|
202
|
+
const prev = JSON.parse(read(path.join("ledgers", "reports", prior)));
|
|
203
|
+
const prevScores = Object.fromEntries(prev.components.map((c) => [c.name, c.score]));
|
|
204
|
+
const drops = components.filter((c) => prevScores[c.name] != null && prevScores[c.name] - c.score > 10);
|
|
205
|
+
if (drops.length) {
|
|
206
|
+
const rows = drops.map((c) => JSON.stringify({
|
|
207
|
+
schemaVersion: "1", date: DATE, source: "health", rule: "score-drop",
|
|
208
|
+
target: c.name, severity: c.band === "attention" ? "high" : "medium",
|
|
209
|
+
signal: `health ${prevScores[c.name]} → ${c.score} since ${prior.slice(7, 14)}`,
|
|
210
|
+
evidence: c.penalties[0]?.why || "", status: "open",
|
|
211
|
+
}));
|
|
212
|
+
fs.appendFileSync(path.join(ROOT, "ledgers", "drift.jsonl"), rows.join("\n") + "\n");
|
|
213
|
+
console.log(`drift: logged ${rows.length} score drop(s) to ledgers/drift.jsonl`);
|
|
214
|
+
}
|
|
146
215
|
}
|
|
147
216
|
}
|
|
148
|
-
}
|
|
149
217
|
|
|
150
|
-
fs.writeFileSync(outPath, JSON.stringify({ schemaVersion: "1", generatedFor: DATE, summary, components }, null, 2) + "\n");
|
|
218
|
+
fs.writeFileSync(outPath, JSON.stringify({ schemaVersion: "1", generatedFor: DATE, summary, components }, null, 2) + "\n");
|
|
151
219
|
|
|
152
|
-
console.log(`✓ health-report: ${summary.scored} scored, ${summary.insufficientData} insufficient-data, avg ${summary.avgScore} → ledgers/reports/health-${month}.json`);
|
|
153
|
-
const worst = known.filter((c) => c.band !== "healthy").slice(0, 8);
|
|
154
|
-
if (worst.length) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
220
|
+
console.log(`✓ health-report: ${summary.scored} scored, ${summary.insufficientData} insufficient-data, avg ${summary.avgScore} → ledgers/reports/health-${month}.json`);
|
|
221
|
+
const worst = known.filter((c) => c.band !== "healthy").slice(0, 8);
|
|
222
|
+
if (worst.length) {
|
|
223
|
+
console.log("\nLowest bands:");
|
|
224
|
+
for (const c of worst.sort((a, b) => a.score - b.score).slice(0, 8))
|
|
225
|
+
console.log(` ${String(c.score).padStart(3)} ${c.band.padEnd(9)} ${c.name}: ${c.penalties[0]?.why || ""}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Node resolves import.meta.url through any symlink in the module's own
|
|
230
|
+
// path, but process.argv[1] is left exactly as invoked. The shipped bin
|
|
231
|
+
// (bads-health-report, run as `npx bads-health-report` in a fork) is a
|
|
232
|
+
// symlink into node_modules/.bin, so a naive
|
|
233
|
+
// `import.meta.url === file://${process.argv[1]}` check never matches
|
|
234
|
+
// there and main() silently never runs. Resolve both sides to the same
|
|
235
|
+
// real, absolute path before comparing.
|
|
236
|
+
function isMainModule() {
|
|
237
|
+
if (!process.argv[1]) return false;
|
|
238
|
+
try {
|
|
239
|
+
return import.meta.url === `file://${fs.realpathSync(process.argv[1])}`;
|
|
240
|
+
} catch {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
158
243
|
}
|
|
244
|
+
|
|
245
|
+
if (isMainModule()) main();
|
|
246
|
+
|
|
247
|
+
export { resolvePackageOwned, isMainModule, main };
|
package/scripts/lint-slop.mjs
CHANGED
|
@@ -33,6 +33,20 @@
|
|
|
33
33
|
* BADS-SLOP-5 emoji-in-ui decorative emoji (🚀✨⚡🎉🔥💡🎯🌟🚨💪) in rendered UI copy
|
|
34
34
|
* BADS-SLOP-6 fake-stat-cliche invented-metric marketing tokens hardcoded as copy
|
|
35
35
|
* (99.9%/99.99% uptime, 10k+/1M+ vanity counts, ★★★★★)
|
|
36
|
+
* BADS-SLOP-7 system-font-primary system-ui / -apple-system as the FIRST face
|
|
37
|
+
* BADS-SLOP-8 accent-left-border border-left: Npx solid <accent> as card semantics
|
|
38
|
+
* BADS-SLOP-9 icon-in-colored-circle icon centered in a saturated disc, size-8 and up
|
|
39
|
+
* BADS-SLOP-10 decorative-blob absolute + rounded-full + blur-2xl/3xl
|
|
40
|
+
* BADS-SLOP-11 three-up-feature-grid grid-cols-3 + text-center on one element
|
|
41
|
+
* BADS-SLOP-12 wave-divider full-bleed wavy SVG section divider
|
|
42
|
+
*
|
|
43
|
+
* File-scope detectors (the signal IS the repetition, so one line cannot show it):
|
|
44
|
+
* BADS-SLOP-13 center-everything text-center on 6+ blocks in one file
|
|
45
|
+
* BADS-SLOP-14 uniform-bubbly-radius rounded-2xl/3xl on 5+ blocks, no smaller step used
|
|
46
|
+
*
|
|
47
|
+
* Rules 7 to 14 came from ClosedLoop's design pack (2026-09-03, used with
|
|
48
|
+
* permission); see docs/roadmap-closedloop-import.md item 5 for the three
|
|
49
|
+
* blacklist entries deliberately left unported.
|
|
36
50
|
*
|
|
37
51
|
* Rule 6 is adapted from Nutlope's Hallmark slop-test gate 46 (invented
|
|
38
52
|
* metrics), matched to BADS's own "fake stat trio" anti-default. Real metrics
|
|
@@ -64,6 +78,8 @@ import path from "node:path";
|
|
|
64
78
|
// into a client fork, invoked as `npx bads-lint-slop` from the fork's own
|
|
65
79
|
// repo root.
|
|
66
80
|
const ROOT = process.cwd();
|
|
81
|
+
import { RULES, FILE_RULES } from "./slop-rules.mjs";
|
|
82
|
+
|
|
67
83
|
const advisory = process.argv.includes("--warn");
|
|
68
84
|
const explicitPaths = process.argv.slice(2).filter((a) => !a.startsWith("--"));
|
|
69
85
|
|
|
@@ -77,70 +93,8 @@ const SCAN_ROOTS = [
|
|
|
77
93
|
// Decorative-emoji set — the classic AI-product sprinkle. Excludes ✓/✗/→ and
|
|
78
94
|
// other functional glyphs; excludes the crescent-moon etc. used in Slack briefs
|
|
79
95
|
// (those live in scripts/, out of scan scope).
|
|
80
|
-
const SLOP_EMOJI = /[\u{1F680}\u{2728}\u{26A1}\u{1F389}\u{1F525}\u{1F4A1}\u{1F3AF}\u{1F31F}\u{1F6A8}\u{1F4AA}\u{1F44B}\u{1F984}\u{1F4A5}\u{1F60D}]/u;
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
code: "BADS-SLOP-1",
|
|
85
|
-
name: "gradient-text",
|
|
86
|
-
why: "Rainbow gradient headline (bg-clip-text). Carries no information; the classic 'look premium' move. Use a solid foreground token.",
|
|
87
|
-
test: (line) =>
|
|
88
|
-
(/\bbg-clip-text\b/.test(line) && /\btext-transparent\b/.test(line)) ||
|
|
89
|
-
/background-clip:\s*text/.test(line) ||
|
|
90
|
-
/-webkit-background-clip:\s*text/.test(line),
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
code: "BADS-SLOP-2",
|
|
94
|
-
name: "indigo-violet-gradient",
|
|
95
|
-
why: "Indigo→purple diagonal blend — the single most recognizable AI-default gradient. Use a flat brand or semantic surface.",
|
|
96
|
-
// Only the Tailwind gradient-direction stops — a bare violet hex (e.g. a
|
|
97
|
-
// ColorPicker swatch value) is a color, not a gradient, and must not flag.
|
|
98
|
-
// A raw slop-hex only counts when it sits in an actual gradient function.
|
|
99
|
-
test: (line) =>
|
|
100
|
-
/\b(from|via|to)-(indigo|violet|purple|fuchsia)-\d/.test(line) ||
|
|
101
|
-
(/(linear|radial|conic)-gradient|bg-gradient-to-/.test(line) &&
|
|
102
|
-
/#6366f1|#a855f7|#8b5cf6|#7c3aed/i.test(line)),
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
code: "BADS-SLOP-3",
|
|
106
|
-
name: "springy-hover",
|
|
107
|
-
why: "hover:scale-105/110 — the bouncy 'pop' every AI card gets. BADS uses token-driven color/elevation shifts on hover, not scale jumps.",
|
|
108
|
-
test: (line) => /\bhover:scale-1(05|10)\b/.test(line),
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
code: "BADS-SLOP-4",
|
|
112
|
-
name: "oversized-shadow",
|
|
113
|
-
why: "Shadow blur ≥ 40px — the soft 'glow' that bleeds far past the element. BADS uses the --shadow token scale.",
|
|
114
|
-
test: (line) => {
|
|
115
|
-
// arbitrary Tailwind shadow: shadow-[...40px...]
|
|
116
|
-
const arb = line.match(/shadow-\[[^\]]*?\b(\d{2,})px/);
|
|
117
|
-
if (arb && Number(arb[1]) >= 40) return true;
|
|
118
|
-
// inline box-shadow with a blur radius ≥ 40px (3rd length in the list)
|
|
119
|
-
const inline = line.match(/box-?[Ss]hadow[^;"'`]*?\b(\d{2,})px/);
|
|
120
|
-
if (inline && Number(inline[1]) >= 40) return true;
|
|
121
|
-
return false;
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
code: "BADS-SLOP-5",
|
|
126
|
-
name: "emoji-in-ui",
|
|
127
|
-
why: "Decorative emoji in rendered UI copy — 🚀/✨/🔥 on headings and buttons. BADS carries meaning in words, not emoji sprinkle.",
|
|
128
|
-
test: (line, { isComment }) => !isComment && SLOP_EMOJI.test(line),
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
code: "BADS-SLOP-6",
|
|
132
|
-
name: "fake-stat-cliche",
|
|
133
|
-
why: "Invented-metric marketing cliché hardcoded as copy (99.9% uptime, 10k+/1M+ counts, ★★★★★). Real metrics come from data, not string literals — a hardcoded one manufactures trust. Use real content from the personas pool, or escape-hatch a genuine, sourced claim.",
|
|
134
|
-
test: (line, { isComment }) => {
|
|
135
|
-
if (isComment) return false;
|
|
136
|
-
return (
|
|
137
|
-
/\b99\.9{1,2}\s*%/.test(line) || // 99.9% / 99.99% uptime cliché
|
|
138
|
-
/\b\d{1,3}[kKmMbB]\+/.test(line) || // 10k+ / 100k+ / 1M+ vanity counts
|
|
139
|
-
/★{3,}/.test(line) // ★★★★★ rating-star cliché row (filled-star glyph)
|
|
140
|
-
);
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
];
|
|
97
|
+
|
|
144
98
|
|
|
145
99
|
function walk(dir, out = []) {
|
|
146
100
|
if (!fs.existsSync(dir)) return out;
|
|
@@ -177,7 +131,7 @@ for (const file of fileList()) {
|
|
|
177
131
|
for (const rule of RULES) {
|
|
178
132
|
if (!rule.test(line, { isComment })) continue;
|
|
179
133
|
// escape hatch on the line above: // allow-slop:CODE <reason>
|
|
180
|
-
const esc = prev.match(/\/\/\s*allow-slop:(BADS-SLOP-\d)\b(.*)$/);
|
|
134
|
+
const esc = prev.match(/\/\/\s*allow-slop:(BADS-SLOP-\d+)\b(.*)$/);
|
|
181
135
|
if (esc && esc[1] === rule.code) {
|
|
182
136
|
if (!esc[2].trim()) {
|
|
183
137
|
findings.push({
|
|
@@ -199,6 +153,34 @@ for (const file of fileList()) {
|
|
|
199
153
|
});
|
|
200
154
|
}
|
|
201
155
|
}
|
|
156
|
+
|
|
157
|
+
// File-scope pass. The escape hatch for these is file-wide (the finding has
|
|
158
|
+
// no single owning line to sit above), so it may appear on any line.
|
|
159
|
+
for (const rule of FILE_RULES) {
|
|
160
|
+
const hit = rule.test(src, { lines });
|
|
161
|
+
if (!hit) continue;
|
|
162
|
+
const esc = src.match(
|
|
163
|
+
new RegExp(`//\\s*allow-slop:${rule.code}\\b(.*)`),
|
|
164
|
+
);
|
|
165
|
+
if (esc) {
|
|
166
|
+
if (esc[1].trim()) continue; // escaped with a reason — allowed
|
|
167
|
+
findings.push({
|
|
168
|
+
file: path.relative(ROOT, file),
|
|
169
|
+
line: hit.line,
|
|
170
|
+
code: rule.code,
|
|
171
|
+
name: rule.name,
|
|
172
|
+
why: "allow-slop escape hatch requires a one-sentence reason.",
|
|
173
|
+
});
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
findings.push({
|
|
177
|
+
file: path.relative(ROOT, file),
|
|
178
|
+
line: hit.line,
|
|
179
|
+
code: rule.code,
|
|
180
|
+
name: rule.name,
|
|
181
|
+
why: `${rule.why} (${hit.detail})`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
202
184
|
}
|
|
203
185
|
|
|
204
186
|
if (findings.length === 0) {
|
package/scripts/oklch-to-hex.cjs
CHANGED
|
@@ -153,4 +153,10 @@ function main() {
|
|
|
153
153
|
console.log(hex);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
// Exported so token-nearest.mjs resolves oklch the same way this CLI does.
|
|
157
|
+
// One copy of the colour math, or the two would drift and the drift would be
|
|
158
|
+
// invisible: a token would resolve to one hex in the audit and another in the
|
|
159
|
+
// nearest-token report, and nothing would say which was right.
|
|
160
|
+
module.exports = { colorToHex, oklchToHex, hslToHex, rgbToHex, srgbToHex };
|
|
161
|
+
|
|
162
|
+
if (require.main === module) main();
|