@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
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ratchet — the third mode every BADS check was missing.
|
|
4
|
+
*
|
|
5
|
+
* Until now a check was warn (prints, never fails, gets ignored) or strict
|
|
6
|
+
* (fails). On a fresh project strict is right. On an existing codebase with
|
|
7
|
+
* hundreds of violations, strict is unadoptable and warn is theatre, so the
|
|
8
|
+
* rule never lands at all. That is not a hypothetical: a client fork mirroring
|
|
9
|
+
* a dense product runs 10 and 11px text across most of its surfaces against a
|
|
10
|
+
* 14px AAA floor, and the whole adoption question stalled on a yes/no that only
|
|
11
|
+
* had one honest answer.
|
|
12
|
+
*
|
|
13
|
+
* A ratchet gives the third answer. Today's violations are recorded in a
|
|
14
|
+
* baseline. Listed files may stay in violation, and two rules hold:
|
|
15
|
+
*
|
|
16
|
+
* 1. A listed file may not get WORSE.
|
|
17
|
+
* 2. No file may JOIN the list.
|
|
18
|
+
*
|
|
19
|
+
* So the old mess is frozen and new work has to be clean. As people fix things
|
|
20
|
+
* the list shrinks, and it can only shrink. The adoption question changes from
|
|
21
|
+
* "do we fix 300 screens" to "may new screens be legal", which answers itself.
|
|
22
|
+
*
|
|
23
|
+
* The pattern, and every anti-dodge below, is from ClosedLoop's
|
|
24
|
+
* `check-grandfather-line-growth.ts` (audited 2026-09-03, used with
|
|
25
|
+
* permission; see docs/roadmap-closedloop-import.md item 3). A naive ratchet is
|
|
26
|
+
* trivially defeated by adding your file to the baseline, so:
|
|
27
|
+
*
|
|
28
|
+
* - The baseline is diffed against the same file at the BASE GIT REF. An
|
|
29
|
+
* entry that was not there at base is rejected. You cannot exempt your way
|
|
30
|
+
* past the gate.
|
|
31
|
+
* - Renames are resolved. Moving a file that WAS listed keeps it listed
|
|
32
|
+
* (reorganising must stay possible). Renaming an unlisted file INTO the
|
|
33
|
+
* list is the same dodge wearing a hat, and is rejected.
|
|
34
|
+
* - A stale entry (a listed path whose file was deleted) cannot be reused for
|
|
35
|
+
* a different file. Path membership alone does not prove the same file was
|
|
36
|
+
* grandfathered.
|
|
37
|
+
* - When the base baseline cannot be read at all, membership is UNKNOWN.
|
|
38
|
+
* Nothing is rejected and the run SAYS so, because a quiet pass would read
|
|
39
|
+
* as "no entry was added" when the gate never looked.
|
|
40
|
+
* - Every run reports its own coverage, pass or fail. A listed entry the gate
|
|
41
|
+
* could not measure is named, never silently skipped. A gate that measures
|
|
42
|
+
* nothing and exits 0 is worse than no gate, because now you think you are
|
|
43
|
+
* covered.
|
|
44
|
+
*
|
|
45
|
+
* This module is the pure half: no git, no filesystem, no process exit, so the
|
|
46
|
+
* whole decision table is testable. `readBaseAt`, `detectRenames` and
|
|
47
|
+
* `renderReport` are the thin impure helpers around it.
|
|
48
|
+
*
|
|
49
|
+
* A consumer (see scripts/type-floor-ratchet.mjs) measures violations per file
|
|
50
|
+
* and hands in a `{ path: count }` map.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
import fs from "node:fs";
|
|
54
|
+
import path from "node:path";
|
|
55
|
+
import { execFileSync } from "node:child_process";
|
|
56
|
+
|
|
57
|
+
export const BASELINE_FILE = ".bads-ratchet.json";
|
|
58
|
+
export const SCHEMA_VERSION = 1;
|
|
59
|
+
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Baseline I/O
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
export function emptyBaseline() {
|
|
65
|
+
return { version: SCHEMA_VERSION, rules: {} };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function readBaseline(root = process.cwd(), file = BASELINE_FILE) {
|
|
69
|
+
const full = path.join(root, file);
|
|
70
|
+
if (!fs.existsSync(full)) return emptyBaseline();
|
|
71
|
+
return JSON.parse(fs.readFileSync(full, "utf8"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function writeBaseline(baseline, root = process.cwd(), file = BASELINE_FILE) {
|
|
75
|
+
fs.writeFileSync(path.join(root, file), `${JSON.stringify(baseline, null, 2)}\n`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function ruleEntry(baseline, ruleId) {
|
|
79
|
+
return baseline?.rules?.[ruleId] ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The baseline as it existed at `ref`, or null when it cannot be read.
|
|
84
|
+
*
|
|
85
|
+
* Null is meaningfully different from an empty baseline: empty means "nothing
|
|
86
|
+
* was listed at base", null means "we could not look". Only the second one
|
|
87
|
+
* suppresses the membership rules.
|
|
88
|
+
*/
|
|
89
|
+
export function readBaseAt(ref, root = process.cwd(), file = BASELINE_FILE) {
|
|
90
|
+
try {
|
|
91
|
+
const out = execFileSync("git", ["show", `${ref}:${file}`], {
|
|
92
|
+
cwd: root,
|
|
93
|
+
encoding: "utf8",
|
|
94
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
95
|
+
});
|
|
96
|
+
return JSON.parse(out);
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `{ newPath: oldPath }` for files git considers renamed between ref and HEAD. */
|
|
103
|
+
export function detectRenames(ref, root = process.cwd()) {
|
|
104
|
+
try {
|
|
105
|
+
const out = execFileSync("git", ["diff", "--name-status", "-M", `${ref}...HEAD`], {
|
|
106
|
+
cwd: root,
|
|
107
|
+
encoding: "utf8",
|
|
108
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
109
|
+
});
|
|
110
|
+
const map = {};
|
|
111
|
+
for (const line of out.split("\n")) {
|
|
112
|
+
const parts = line.split("\t");
|
|
113
|
+
if (!parts[0]?.startsWith("R")) continue;
|
|
114
|
+
const [, oldPath, newPath] = parts;
|
|
115
|
+
if (oldPath && newPath) map[newPath] = oldPath;
|
|
116
|
+
}
|
|
117
|
+
return map;
|
|
118
|
+
} catch {
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Did `p` exist at `ref`? Used to tell a live entry from a stale one. */
|
|
124
|
+
export function existedAt(ref, p, root = process.cwd()) {
|
|
125
|
+
try {
|
|
126
|
+
execFileSync("git", ["cat-file", "-e", `${ref}:${p}`], {
|
|
127
|
+
cwd: root,
|
|
128
|
+
stdio: "ignore",
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// The decision table
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {object} input
|
|
142
|
+
* @param {string} input.ruleId
|
|
143
|
+
* @param {Record<string, number>} input.listed baseline counts in the working tree
|
|
144
|
+
* @param {Record<string, number>|null} input.base baseline counts at the base ref, or null when unreadable
|
|
145
|
+
* @param {Record<string, number>} input.current counts measured right now
|
|
146
|
+
* @param {Record<string, string>} [input.renames] newPath -> oldPath
|
|
147
|
+
* @param {(p: string) => boolean} [input.exists] does this path exist in the working tree
|
|
148
|
+
* @param {(p: string) => boolean} [input.existedAtBase] did this path exist at the base ref
|
|
149
|
+
*/
|
|
150
|
+
export function checkRatchet({
|
|
151
|
+
ruleId,
|
|
152
|
+
listed,
|
|
153
|
+
base,
|
|
154
|
+
current,
|
|
155
|
+
renames = {},
|
|
156
|
+
exists = () => true,
|
|
157
|
+
existedAtBase = () => true,
|
|
158
|
+
}) {
|
|
159
|
+
const violations = [];
|
|
160
|
+
const unmeasured = [];
|
|
161
|
+
const resolved = [];
|
|
162
|
+
let checked = 0;
|
|
163
|
+
|
|
164
|
+
const membershipChecked = base !== null && base !== undefined;
|
|
165
|
+
const listedPaths = Object.keys(listed);
|
|
166
|
+
|
|
167
|
+
// Rule 1: a listed file may not get worse.
|
|
168
|
+
for (const p of listedPaths) {
|
|
169
|
+
const allowed = listed[p];
|
|
170
|
+
const now = current[p];
|
|
171
|
+
|
|
172
|
+
if (now === undefined) {
|
|
173
|
+
if (!exists(p)) {
|
|
174
|
+
resolved.push({ path: p, reason: "file no longer exists" });
|
|
175
|
+
} else {
|
|
176
|
+
// The file is there and the measurement produced nothing for it. That
|
|
177
|
+
// is not the same as "clean" — it is "we did not look" — and it must be
|
|
178
|
+
// named, or the coverage number lies.
|
|
179
|
+
unmeasured.push({ path: p, reason: "no count produced for a file that exists" });
|
|
180
|
+
}
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
checked += 1;
|
|
185
|
+
if (now > allowed) {
|
|
186
|
+
violations.push({
|
|
187
|
+
kind: "growth",
|
|
188
|
+
path: p,
|
|
189
|
+
allowed,
|
|
190
|
+
found: now,
|
|
191
|
+
detail: `${p} is grandfathered at ${allowed} and now has ${now}. A listed file may not get worse.`,
|
|
192
|
+
});
|
|
193
|
+
} else if (now === 0) {
|
|
194
|
+
resolved.push({ path: p, reason: "no violations left" });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Rule 2: no file may join the list.
|
|
199
|
+
if (membershipChecked) {
|
|
200
|
+
for (const p of listedPaths) {
|
|
201
|
+
if (p in base) {
|
|
202
|
+
// A listed path whose file did not exist at base is a stale entry. It
|
|
203
|
+
// cannot be reused: path membership alone does not prove that THIS file
|
|
204
|
+
// was ever grandfathered.
|
|
205
|
+
if (!existedAtBase(p) && exists(p)) {
|
|
206
|
+
violations.push({
|
|
207
|
+
kind: "stale-entry-reuse",
|
|
208
|
+
path: p,
|
|
209
|
+
detail: `${p} is in the base baseline but no file existed there. A stale entry cannot be reused for a different file.`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const from = renames[p];
|
|
215
|
+
if (from && from in base) continue; // a listed file that moved stays listed
|
|
216
|
+
violations.push({
|
|
217
|
+
kind: "new-entry",
|
|
218
|
+
path: p,
|
|
219
|
+
detail: from
|
|
220
|
+
? `${p} was renamed from ${from}, which was not grandfathered. Renaming a file into the baseline is not a way in.`
|
|
221
|
+
: `${p} is new to the baseline. The list is shrink-only; fix the violation instead of listing the file.`,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Rule 3: an unlisted file with violations fails outright. This is the half
|
|
227
|
+
// that makes new work clean; without it the ratchet only guards the old mess.
|
|
228
|
+
for (const [p, count] of Object.entries(current)) {
|
|
229
|
+
if (count === 0 || p in listed) continue;
|
|
230
|
+
violations.push({
|
|
231
|
+
kind: "unlisted-violation",
|
|
232
|
+
path: p,
|
|
233
|
+
found: count,
|
|
234
|
+
detail: `${p} has ${count} violation(s) and is not grandfathered. New work has to be clean.`,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
ruleId,
|
|
240
|
+
ok: violations.length === 0,
|
|
241
|
+
membershipChecked,
|
|
242
|
+
coverage: { checked, listed: listedPaths.length, unmeasured },
|
|
243
|
+
resolved,
|
|
244
|
+
violations,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// Report
|
|
250
|
+
// ---------------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Render a result. Coverage is stated on EVERY run, pass or fail, so a run that
|
|
254
|
+
* measured nothing can never be mistaken for a run that found nothing.
|
|
255
|
+
*/
|
|
256
|
+
export function renderReport(result, { baseRef } = {}) {
|
|
257
|
+
const out = [];
|
|
258
|
+
const { coverage, ruleId } = result;
|
|
259
|
+
|
|
260
|
+
out.push(
|
|
261
|
+
`ratchet [${ruleId}]: growth-checked ${coverage.checked} of ${coverage.listed} listed file(s)`,
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
if (!result.membershipChecked) {
|
|
265
|
+
out.push(
|
|
266
|
+
` ! baseline membership NOT checked${baseRef ? ` (could not read ${BASELINE_FILE} at ${baseRef})` : ""}.`,
|
|
267
|
+
" Nothing was rejected for joining the list, because the gate could not look.",
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
for (const u of coverage.unmeasured) {
|
|
272
|
+
out.push(` ! unmeasured ${u.path} (${u.reason})`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
for (const v of result.violations) {
|
|
276
|
+
out.push(` x ${v.kind.padEnd(20)} ${v.detail}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (result.resolved.length) {
|
|
280
|
+
out.push(
|
|
281
|
+
"",
|
|
282
|
+
` ${result.resolved.length} entr${result.resolved.length === 1 ? "y is" : "ies are"} now clean and can be removed from the baseline:`,
|
|
283
|
+
);
|
|
284
|
+
for (const r of result.resolved.slice(0, 10)) out.push(` - ${r.path} (${r.reason})`);
|
|
285
|
+
if (result.resolved.length > 10) out.push(` ... and ${result.resolved.length - 10} more`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
out.push("", result.ok ? "✓ ratchet: no growth, no new entries." : "✗ ratchet: see above.");
|
|
289
|
+
return out.join("\n");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The whole flow for a consumer that has already measured `current`.
|
|
294
|
+
* Returns `{ result, report, exitCode }`; the caller decides what to do with it.
|
|
295
|
+
*/
|
|
296
|
+
export function runRatchet({
|
|
297
|
+
ruleId,
|
|
298
|
+
current,
|
|
299
|
+
root = process.cwd(),
|
|
300
|
+
baseRef = "origin/main",
|
|
301
|
+
baselineFile = BASELINE_FILE,
|
|
302
|
+
advisory = false,
|
|
303
|
+
}) {
|
|
304
|
+
const baseline = readBaseline(root, baselineFile);
|
|
305
|
+
const entry = ruleEntry(baseline, ruleId);
|
|
306
|
+
const listed = entry?.files ?? {};
|
|
307
|
+
|
|
308
|
+
const baseBaseline = readBaseAt(baseRef, root, baselineFile);
|
|
309
|
+
const base = baseBaseline ? (ruleEntry(baseBaseline, ruleId)?.files ?? {}) : null;
|
|
310
|
+
|
|
311
|
+
const result = checkRatchet({
|
|
312
|
+
ruleId,
|
|
313
|
+
listed,
|
|
314
|
+
base,
|
|
315
|
+
current,
|
|
316
|
+
renames: detectRenames(baseRef, root),
|
|
317
|
+
exists: (p) => fs.existsSync(path.join(root, p)),
|
|
318
|
+
existedAtBase: (p) => existedAt(baseRef, p, root),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
result,
|
|
323
|
+
report: renderReport(result, { baseRef }),
|
|
324
|
+
exitCode: advisory || result.ok ? 0 : 1,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AI-slop signal set — the single definition shared by the lint that
|
|
3
|
+
* enforces it and the eval rubric that scores it.
|
|
4
|
+
*
|
|
5
|
+
* Two exports, because two rules need to see more than one line:
|
|
6
|
+
* RULES per-line detectors. `test(line, { isComment })`.
|
|
7
|
+
* FILE_RULES whole-file detectors. `test(src, { lines })`. Only lint-slop
|
|
8
|
+
* consumes these; the MCP rubric scores per-line rules only, so
|
|
9
|
+
* adding a file rule can never change a rubric score.
|
|
10
|
+
*
|
|
11
|
+
* Rules 7 to 14 were added 2026-09-03 from the AI design-pattern blacklist in
|
|
12
|
+
* ClosedLoop's design pack (used with permission). They are the subset of that
|
|
13
|
+
* list with an objective, low-false-positive detector. Three items from it were
|
|
14
|
+
* deliberately NOT ported — cookie-cutter section rhythm, badge-where-a-string-
|
|
15
|
+
* would-do, and border-on-everything — because each needs a layout or density
|
|
16
|
+
* model rather than a text scan. See docs/roadmap-closedloop-import.md item 5.
|
|
17
|
+
*
|
|
18
|
+
* These lived inside lint-slop.mjs as a private const, so the eval had no way
|
|
19
|
+
* to score them without keeping a second copy. Two copies of "what slop is"
|
|
20
|
+
* would drift, which is the failure this whole rule set exists to prevent one
|
|
21
|
+
* level down. Extracted 2026-09-01 so both sides read the same array.
|
|
22
|
+
*
|
|
23
|
+
* Each rule: { code, name, why, test: (line: string) => boolean }.
|
|
24
|
+
* `test` is per-line, so a caller splits source on newlines and applies it.
|
|
25
|
+
*/
|
|
26
|
+
// Decorative-emoji set (BADS-SLOP-5). Lives here because only the rules use it.
|
|
27
|
+
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;
|
|
28
|
+
|
|
29
|
+
export const RULES = [
|
|
30
|
+
{
|
|
31
|
+
code: "BADS-SLOP-1",
|
|
32
|
+
name: "gradient-text",
|
|
33
|
+
why: "Rainbow gradient headline (bg-clip-text). Carries no information; the classic 'look premium' move. Use a solid foreground token.",
|
|
34
|
+
test: (line) =>
|
|
35
|
+
(/\bbg-clip-text\b/.test(line) && /\btext-transparent\b/.test(line)) ||
|
|
36
|
+
/background-clip:\s*text/.test(line) ||
|
|
37
|
+
/-webkit-background-clip:\s*text/.test(line),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
code: "BADS-SLOP-2",
|
|
41
|
+
name: "indigo-violet-gradient",
|
|
42
|
+
why: "Indigo→purple diagonal blend — the single most recognizable AI-default gradient. Use a flat brand or semantic surface.",
|
|
43
|
+
// Only the Tailwind gradient-direction stops — a bare violet hex (e.g. a
|
|
44
|
+
// ColorPicker swatch value) is a color, not a gradient, and must not flag.
|
|
45
|
+
// A raw slop-hex only counts when it sits in an actual gradient function.
|
|
46
|
+
test: (line) =>
|
|
47
|
+
/\b(from|via|to)-(indigo|violet|purple|fuchsia)-\d/.test(line) ||
|
|
48
|
+
(/(linear|radial|conic)-gradient|bg-gradient-to-/.test(line) &&
|
|
49
|
+
/#6366f1|#a855f7|#8b5cf6|#7c3aed/i.test(line)),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: "BADS-SLOP-3",
|
|
53
|
+
name: "springy-hover",
|
|
54
|
+
why: "hover:scale-105/110 — the bouncy 'pop' every AI card gets. BADS uses token-driven color/elevation shifts on hover, not scale jumps.",
|
|
55
|
+
test: (line) => /\bhover:scale-1(05|10)\b/.test(line),
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
code: "BADS-SLOP-4",
|
|
59
|
+
name: "oversized-shadow",
|
|
60
|
+
why: "Shadow blur ≥ 40px — the soft 'glow' that bleeds far past the element. BADS uses the --shadow token scale.",
|
|
61
|
+
test: (line) => {
|
|
62
|
+
// arbitrary Tailwind shadow: shadow-[...40px...]
|
|
63
|
+
const arb = line.match(/shadow-\[[^\]]*?\b(\d{2,})px/);
|
|
64
|
+
if (arb && Number(arb[1]) >= 40) return true;
|
|
65
|
+
// inline box-shadow with a blur radius ≥ 40px (3rd length in the list)
|
|
66
|
+
const inline = line.match(/box-?[Ss]hadow[^;"'`]*?\b(\d{2,})px/);
|
|
67
|
+
if (inline && Number(inline[1]) >= 40) return true;
|
|
68
|
+
return false;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
code: "BADS-SLOP-5",
|
|
73
|
+
name: "emoji-in-ui",
|
|
74
|
+
why: "Decorative emoji in rendered UI copy — 🚀/✨/🔥 on headings and buttons. BADS carries meaning in words, not emoji sprinkle.",
|
|
75
|
+
test: (line, { isComment }) => !isComment && SLOP_EMOJI.test(line),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
code: "BADS-SLOP-6",
|
|
79
|
+
name: "fake-stat-cliche",
|
|
80
|
+
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.",
|
|
81
|
+
test: (line, { isComment }) => {
|
|
82
|
+
if (isComment) return false;
|
|
83
|
+
return (
|
|
84
|
+
/\b99\.9{1,2}\s*%/.test(line) || // 99.9% / 99.99% uptime cliché
|
|
85
|
+
/\b\d{1,3}[kKmMbB]\+/.test(line) || // 10k+ / 100k+ / 1M+ vanity counts
|
|
86
|
+
/★{3,}/.test(line) // ★★★★★ rating-star cliché row (filled-star glyph)
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
code: "BADS-SLOP-7",
|
|
92
|
+
name: "system-font-primary",
|
|
93
|
+
why: "system-ui / -apple-system as the FIRST face in the stack — the 'gave up on typography' signal. A stack that names a real face first and falls back to system-ui is fine; this only fires when the system font IS the choice. Pick a typeface from layer 1.",
|
|
94
|
+
test: (line, { isComment }) => {
|
|
95
|
+
if (isComment) return false;
|
|
96
|
+
// Tailwind arbitrary family: font-[system-ui] / font-[-apple-system]
|
|
97
|
+
if (/\bfont-\[\s*(system-ui|-apple-system|BlinkMacSystemFont)/i.test(line)) return true;
|
|
98
|
+
// CSS or inline style: the first face in the declared stack
|
|
99
|
+
const decl = line.match(/font-?[Ff]amily\s*[:=]\s*["'`]?\s*([^;"'`,}]+)/);
|
|
100
|
+
if (!decl) return false;
|
|
101
|
+
return /^\s*(system-ui|-apple-system|BlinkMacSystemFont)\b/i.test(decl[1]);
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
code: "BADS-SLOP-8",
|
|
106
|
+
name: "accent-left-border",
|
|
107
|
+
why: "A colored left border on a CARD (border-left: 3px solid <accent>). It reads as a status stripe nobody defined. If it IS a status, use Alert; if it is emphasis, use Blockquote; otherwise use the semantic surface tokens.",
|
|
108
|
+
// Deliberately scoped to cards. Two BADS registers own a colored left bar
|
|
109
|
+
// and must never fire: Alert's status stripe and Blockquote's editorial
|
|
110
|
+
// accent. Both are named, both are the sanctioned answer this rule points
|
|
111
|
+
// at, so the Tailwind branch requires a card signal on the same element.
|
|
112
|
+
test: (line, { isComment }) => {
|
|
113
|
+
if (isComment) return false;
|
|
114
|
+
const cardish = /\bbg-card\b|<Card\b|\brounded-(lg|xl|2xl|3xl)\b/.test(line);
|
|
115
|
+
if (/\bborder-l-(2|4|8)\b/.test(line) && SATURATED_BG_OR_BORDER.test(line) && cardish)
|
|
116
|
+
return true;
|
|
117
|
+
// CSS / inline: border-left: 3px solid <anything but transparent>
|
|
118
|
+
const css = line.match(/border-?[Ll]eft\s*[:=]\s*["'`]?\s*(\d+)px\s+solid\s+([^;"'`}]+)/);
|
|
119
|
+
if (css && Number(css[1]) >= 2 && !/transparent/i.test(css[2])) return true;
|
|
120
|
+
return false;
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
code: "BADS-SLOP-9",
|
|
125
|
+
name: "icon-in-colored-circle",
|
|
126
|
+
why: "An icon centered in a saturated colored disc — the SaaS-starter-template look. BADS carries status in the icon's own token color, not in a decorative puck behind it. Status dots (size-2/3) and neutral avatars deliberately do not fire.",
|
|
127
|
+
test: (line, { isComment }) => {
|
|
128
|
+
if (isComment) return false;
|
|
129
|
+
if (!/\brounded-full\b/.test(line)) return false;
|
|
130
|
+
if (!SATURATED_BG.test(line)) return false;
|
|
131
|
+
// icon scale only: size-8 and up, or a matched h-N w-N at that scale.
|
|
132
|
+
const sized = /\bsize-(8|9|10|11|12|14|16|20)\b/.test(line);
|
|
133
|
+
const hw = line.match(/\bh-(\d{1,2})\b/) && line.match(/\bw-(\d{1,2})\b/);
|
|
134
|
+
const hwBig =
|
|
135
|
+
hw &&
|
|
136
|
+
Number(line.match(/\bh-(\d{1,2})\b/)[1]) >= 8 &&
|
|
137
|
+
Number(line.match(/\bw-(\d{1,2})\b/)[1]) >= 8;
|
|
138
|
+
return sized || Boolean(hwBig);
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
code: "BADS-SLOP-10",
|
|
143
|
+
name: "decorative-blob",
|
|
144
|
+
why: "A blurred colored disc floated behind the content (absolute + rounded-full + blur-2xl/3xl). A section that feels empty needs better content, not a background blob.",
|
|
145
|
+
test: (line, { isComment }) => {
|
|
146
|
+
if (isComment) return false;
|
|
147
|
+
return (
|
|
148
|
+
/\babsolute\b/.test(line) &&
|
|
149
|
+
/\brounded-full\b/.test(line) &&
|
|
150
|
+
/\bblur-(2xl|3xl)\b/.test(line)
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
code: "BADS-SLOP-11",
|
|
156
|
+
name: "three-up-feature-grid",
|
|
157
|
+
why: "The symmetric three-column feature grid with centered cards — the single most recognizable AI layout. Three real things in a row is fine; three centered cards because three looks balanced is the tell. Vary the weights, or use a Section with plain rows.",
|
|
158
|
+
test: (line, { isComment }) => {
|
|
159
|
+
if (isComment) return false;
|
|
160
|
+
return /\bgrid-cols-3\b/.test(line) && /\btext-center\b/.test(line);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
code: "BADS-SLOP-12",
|
|
165
|
+
name: "wave-divider",
|
|
166
|
+
why: "A full-bleed wavy SVG divider between sections. Decoration standing in for hierarchy. Let spacing and type do the separating.",
|
|
167
|
+
test: (line, { isComment }) => {
|
|
168
|
+
if (isComment) return false;
|
|
169
|
+
if (!/<svg/i.test(line)) return false;
|
|
170
|
+
return (
|
|
171
|
+
/viewBox=["'`]0 0 (1440|1920|2880)\b/.test(line) ||
|
|
172
|
+
/preserveAspectRatio=["'`]none/.test(line)
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
// Saturated fills only. BADS's neutral surfaces (muted, secondary, accent,
|
|
179
|
+
// card, background) are deliberately excluded: an avatar fallback or a
|
|
180
|
+
// neutral chip is not the pattern these rules are looking for.
|
|
181
|
+
const SATURATED_NAMES =
|
|
182
|
+
"primary|destructive|success|warning|info|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose";
|
|
183
|
+
// The trailing (?![\w-]) matters: a bare \b would let `bg-primary` match
|
|
184
|
+
// inside `bg-primary-foreground`, which is a TEXT color token and the exact
|
|
185
|
+
// opposite of a decorative fill. That false-positived the Switch thumb.
|
|
186
|
+
const SATURATED_BG = new RegExp(`\\bbg-(${SATURATED_NAMES})(-\\d{2,3})?(?![\\w-])`);
|
|
187
|
+
const SATURATED_BG_OR_BORDER = new RegExp(
|
|
188
|
+
`\\b(bg|border)-(${SATURATED_NAMES})(-\\d{2,3})?(?![\\w-])`,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whole-file detectors. A file rule sees the full source because the signal IS
|
|
193
|
+
* the repetition — one centered heading is a choice, eight is a template.
|
|
194
|
+
*
|
|
195
|
+
* Contract: `test(src, { lines })` returns null for a pass, or
|
|
196
|
+
* `{ line, detail }` for a finding, where `line` is 1-indexed and points at
|
|
197
|
+
* the first occurrence so the report can cite something real.
|
|
198
|
+
*/
|
|
199
|
+
export const FILE_RULES = [
|
|
200
|
+
{
|
|
201
|
+
code: "BADS-SLOP-13",
|
|
202
|
+
name: "center-everything",
|
|
203
|
+
why: "text-center on nearly every block in the file. Centering is for the rare focal moment; centering everything removes the left edge the eye reads down and flattens hierarchy to nothing.",
|
|
204
|
+
threshold: 6,
|
|
205
|
+
test: (src, { lines }) => {
|
|
206
|
+
const hits = [];
|
|
207
|
+
lines.forEach((l, i) => {
|
|
208
|
+
if (/\btext-center\b/.test(l)) hits.push(i + 1);
|
|
209
|
+
});
|
|
210
|
+
if (hits.length < 6) return null;
|
|
211
|
+
return { line: hits[0], detail: `${hits.length} elements use text-center in this file` };
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
code: "BADS-SLOP-14",
|
|
216
|
+
name: "uniform-bubbly-radius",
|
|
217
|
+
why: "One large radius on every element and nothing else. A radius scale communicates surface tier — a card, a popover, and a button should not all read as the same pill. Use the --radius scale.",
|
|
218
|
+
threshold: 5,
|
|
219
|
+
test: (src, { lines }) => {
|
|
220
|
+
const big = [];
|
|
221
|
+
let other = 0;
|
|
222
|
+
lines.forEach((l, i) => {
|
|
223
|
+
if (/\brounded-(2xl|3xl)\b/.test(l)) big.push(i + 1);
|
|
224
|
+
if (/\brounded-(sm|md|lg|none)\b/.test(l)) other += 1;
|
|
225
|
+
});
|
|
226
|
+
if (big.length < 5 || other > 0) return null;
|
|
227
|
+
return {
|
|
228
|
+
line: big[0],
|
|
229
|
+
detail: `${big.length} elements use rounded-2xl/3xl and nothing uses the smaller steps`,
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
];
|