@se-studio/site-check 2.16.4 → 2.19.1
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/CHANGELOG.md +30 -0
- package/README.md +24 -0
- package/check-class-gaps.mjs +284 -0
- package/dist/site-type-audit/adapter.d.ts +17 -0
- package/dist/site-type-audit/adapter.d.ts.map +1 -0
- package/dist/site-type-audit/adapter.js +2 -0
- package/dist/site-type-audit/adapter.js.map +1 -0
- package/dist/site-type-audit/checks.d.ts +24 -0
- package/dist/site-type-audit/checks.d.ts.map +1 -0
- package/dist/site-type-audit/checks.js +730 -0
- package/dist/site-type-audit/checks.js.map +1 -0
- package/dist/site-type-audit/cli.d.ts +3 -0
- package/dist/site-type-audit/cli.d.ts.map +1 -0
- package/dist/site-type-audit/cli.js +84 -0
- package/dist/site-type-audit/cli.js.map +1 -0
- package/dist/site-type-audit/config.d.ts +5 -0
- package/dist/site-type-audit/config.d.ts.map +1 -0
- package/dist/site-type-audit/config.js +55 -0
- package/dist/site-type-audit/config.js.map +1 -0
- package/dist/site-type-audit/crawl.d.ts +40 -0
- package/dist/site-type-audit/crawl.d.ts.map +1 -0
- package/dist/site-type-audit/crawl.js +290 -0
- package/dist/site-type-audit/crawl.js.map +1 -0
- package/dist/site-type-audit/dead-links.d.ts +5 -0
- package/dist/site-type-audit/dead-links.d.ts.map +1 -0
- package/dist/site-type-audit/dead-links.js +35 -0
- package/dist/site-type-audit/dead-links.js.map +1 -0
- package/dist/site-type-audit/dom.d.ts +23 -0
- package/dist/site-type-audit/dom.d.ts.map +1 -0
- package/dist/site-type-audit/dom.js +155 -0
- package/dist/site-type-audit/dom.js.map +1 -0
- package/dist/site-type-audit/fetcher.d.ts +20 -0
- package/dist/site-type-audit/fetcher.d.ts.map +1 -0
- package/dist/site-type-audit/fetcher.js +81 -0
- package/dist/site-type-audit/fetcher.js.map +1 -0
- package/dist/site-type-audit/handoff.d.ts +19 -0
- package/dist/site-type-audit/handoff.d.ts.map +1 -0
- package/dist/site-type-audit/handoff.js +168 -0
- package/dist/site-type-audit/handoff.js.map +1 -0
- package/dist/site-type-audit/html-adapter.d.ts +18 -0
- package/dist/site-type-audit/html-adapter.d.ts.map +1 -0
- package/dist/site-type-audit/html-adapter.js +418 -0
- package/dist/site-type-audit/html-adapter.js.map +1 -0
- package/dist/site-type-audit/index.d.ts +15 -0
- package/dist/site-type-audit/index.d.ts.map +1 -0
- package/dist/site-type-audit/index.js +13 -0
- package/dist/site-type-audit/index.js.map +1 -0
- package/dist/site-type-audit/report.d.ts +6 -0
- package/dist/site-type-audit/report.d.ts.map +1 -0
- package/dist/site-type-audit/report.js +132 -0
- package/dist/site-type-audit/report.js.map +1 -0
- package/dist/site-type-audit/roles.d.ts +13 -0
- package/dist/site-type-audit/roles.d.ts.map +1 -0
- package/dist/site-type-audit/roles.js +135 -0
- package/dist/site-type-audit/roles.js.map +1 -0
- package/dist/site-type-audit/runner.d.ts +11 -0
- package/dist/site-type-audit/runner.d.ts.map +1 -0
- package/dist/site-type-audit/runner.js +113 -0
- package/dist/site-type-audit/runner.js.map +1 -0
- package/dist/site-type-audit/score.d.ts +24 -0
- package/dist/site-type-audit/score.d.ts.map +1 -0
- package/dist/site-type-audit/score.js +239 -0
- package/dist/site-type-audit/score.js.map +1 -0
- package/dist/site-type-audit/site-checks.d.ts +19 -0
- package/dist/site-type-audit/site-checks.d.ts.map +1 -0
- package/dist/site-type-audit/site-checks.js +192 -0
- package/dist/site-type-audit/site-checks.js.map +1 -0
- package/dist/site-type-audit/types.d.ts +248 -0
- package/dist/site-type-audit/types.d.ts.map +1 -0
- package/dist/site-type-audit/types.js +20 -0
- package/dist/site-type-audit/types.js.map +1 -0
- package/docs/site-type-audit-checklists.md +200 -0
- package/docs/site-type-audit.md +117 -0
- package/package.json +11 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.19.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ade58a3: site-type-audit: a 401 or 403 on a hand-off link still passes `site.handoff.resolves`, but the check message, evidence and report now list it as "protected, not verified" instead of a plain pass. 2xx and 3xx are unchanged, and the pass/fail rule is unchanged.
|
|
8
|
+
|
|
9
|
+
## 2.19.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- cc3cb59: site-type-audit: optional `handoff` site config (hosts and/or path pattern) scores a funnel site up to its app or sign-up hand-off (link present, resolves, not a 404 or soft-404, coverage) without auditing the app. The run output now stores the full dead-internal-link list (`deadLinks`: URL, status, every live referrer) and the report renders it in full.
|
|
14
|
+
|
|
15
|
+
## 2.18.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 210a08e: site-type-audit: a site-level `<nav>` counts as the page header when the page has no `<header>` element, so `base.chrome` no longer fails every page of sites that omit the element.
|
|
20
|
+
|
|
21
|
+
## 2.18.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- b293b8c: Add the site-type audit: a read-only runner (`site-type-audit`) that audits every page of a site (sitemap plus bounded crawl) against its kind, credibility or funnel, with per-role checklists, severity by kind, per-page and site scores, JSON and markdown output. Checks read an input-agnostic `PageModel`; an HTML adapter ships now and `PageModelAdapter` is the seam for a later Figma adapter (not built). New skill `site-type-audit`.
|
|
26
|
+
|
|
27
|
+
## 2.17.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- cf49ff2: Add `check-class-gaps` bin: flags class-string template literals (className, cn/clsx arguments, *ClassName) where a class token runs straight into `${` or a `}` runs straight into a class token with no space. Opt-in `run_class_gaps` job on the reusable `site-ci.yml`.
|
|
32
|
+
|
|
3
33
|
## 2.16.4
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -421,6 +421,30 @@ Allowed: `biome-ignore`, `@ts-expect-error`, `@ts-ignore`; `se-exception: <reaso
|
|
|
421
421
|
|
|
422
422
|
`--diff` needs the base ref. Locally a missing base prints a warning and skips; with `CI` set it fails, so check out with `fetch-depth: 0` (or `git fetch origin develop`).
|
|
423
423
|
|
|
424
|
+
## Class string gaps (`check-class-gaps`)
|
|
425
|
+
|
|
426
|
+
Fails when a class token in a class-string template literal runs straight into a `${` or a `}` runs straight into a class token with no space between. The separating space then lives (or not) inside the expression, and an edit to the expression glues two classes into one.
|
|
427
|
+
|
|
428
|
+
```tsx
|
|
429
|
+
<div className={`foo-bar${x}`} /> // flagged
|
|
430
|
+
<div className={`${x}foo-bar`} /> // flagged
|
|
431
|
+
<div className={`a b-1${c ? '' : ' d'}`} /> // flagged: padding hidden in the expression
|
|
432
|
+
<div className={`foo-bar ${x}`} /> // fine
|
|
433
|
+
<div className={`a ${c ? 'd' : ''}`} /> // fine
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
A template is a class string when it sits in `className`, `class`, a `*ClassName` / `*Classes` / `*Class` name, or an argument to `cn`, `clsx`, `cx`, `twMerge`, `twJoin`, `classNames`, `cva` or `tw`. Not flagged: names built from fragments (`grid-cols-${n}`, `md:${x}`, `${prefix}-title`), the inside of an arbitrary value (`w-[${n}px]`), a CSS unit straight after a hole (`w-${n}px`, `h-${n}rem`, `${n}%`; `px-4` after a hole is still flagged), two holes side by side, and templates that are not class strings (`href`, messages). The expression is not analysed. Regex literals are skipped, so a backtick inside one does not open a template. Exit code `1` when any gap is found, `0` otherwise. Source files only: `src/generated`, `node_modules`, `.next` and `.d.ts` are skipped. A string that contains a lone apostrophe in JSX text can hide a template on the same line from the scan (a miss, never a false hit).
|
|
437
|
+
|
|
438
|
+
Run it from the **app root**:
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
pnpm exec check-class-gaps # scans src
|
|
442
|
+
pnpm exec check-class-gaps src other # files or directories
|
|
443
|
+
pnpm exec check-class-gaps --json # hits as JSON: file, line, col, kind, snippet
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Escape hatch: a comment `se-exception: <reason>` on the line or the line above. CI: set `run_class_gaps: true` on the reusable `site-ci.yml` (monorepo: override `class_gaps_command`). Opt in per repo; fix the hits first.
|
|
447
|
+
|
|
424
448
|
## Exit codes
|
|
425
449
|
|
|
426
450
|
- `0` — Validation passed (sitemap.xml required; llms.txt and sitemap-unindexed.xml optional). If `--check-rewrites` was set, no unexpected rewrites. Every sitemap page returned 200 for its `.md` URL and files were saved (or in compare mode: all production sitemap pages exist on development and, if `--check-rewrites`, no unexpected rewrites).
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Guard: a class token must not run straight into a template `${...}` hole.
|
|
8
|
+
*
|
|
9
|
+
* In a class-string template literal (className, class, *ClassName, *Classes, or an argument
|
|
10
|
+
* to cn, clsx, cx, twMerge, twJoin, classNames, cva, tw) a class token directly before `${`
|
|
11
|
+
* or directly after `}` depends on whatever the expression returns to keep the tokens apart.
|
|
12
|
+
* The padding hides inside the expression, so a later edit glues two classes into one.
|
|
13
|
+
*
|
|
14
|
+
* flagged: `foo-bar${x}` `${x}foo-bar` `a b-1${c ? '' : ' d'}`
|
|
15
|
+
* fine: `foo-bar ${x}` `${x} foo-bar` `a ${c ? 'd' : ''}`
|
|
16
|
+
*
|
|
17
|
+
* Not flagged on purpose: a name built from fragments (the token ends in - _ : / [ ( . # ! @
|
|
18
|
+
* before `${`, or starts with - _ : / ] ) % . , after `}`), the inside of an arbitrary value
|
|
19
|
+
* (`w-[${n}px]`), a CSS unit straight after a hole (`w-${n}px`), and two holes side by side. The expression itself is not analysed.
|
|
20
|
+
*
|
|
21
|
+
* Escape hatch: a comment `se-exception: <reason>` on the line or the line above.
|
|
22
|
+
*
|
|
23
|
+
* Run from the app root:
|
|
24
|
+
* check-class-gaps scans src
|
|
25
|
+
* check-class-gaps src packages/x scans the given files or directories
|
|
26
|
+
* check-class-gaps --json machine-readable hits
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const CODE_FILE = /\.(?:[cm]?[jt]sx?)$/;
|
|
30
|
+
const SKIP_FILE = /\.d\.ts$/;
|
|
31
|
+
const SKIP_DIR = new Set(['node_modules', '.next', '.turbo', 'dist', 'build', 'out', 'generated']);
|
|
32
|
+
const CLASS_FNS = /(?:^|[^\w$.])(?:cn|clsx|cx|twMerge|twJoin|classNames|cva|tw)\s*$/;
|
|
33
|
+
const CLASS_NAME_ASSIGN =
|
|
34
|
+
/(?:^|[^\w$])(?:class|className|[A-Za-z]\w*(?:ClassName|ClassNames|Classes|Class))\s*[:=]\s*$/;
|
|
35
|
+
const CLASS_NAME_DIRECT =
|
|
36
|
+
/(?:^|[^\w$])(?:class|className|[A-Za-z]\w*(?:ClassName|ClassNames|Classes|Class))\s*[:=]\s*(?:[^;{}()[\]]*?(?:\?|:|&&|\|\||\?\?)\s*)?$/;
|
|
37
|
+
const JOIN_BEFORE = /[-_:/[(.#!@]/;
|
|
38
|
+
const JOIN_AFTER = /[-_:/\])%.,]/;
|
|
39
|
+
const WHITESPACE = /\s/;
|
|
40
|
+
// A CSS unit straight after a hole (`w-${n}px`, `h-${n}rem`, `${n}%`) is a suffix of the same token.
|
|
41
|
+
// `px-4` is a real class, so the unit must not be followed by a word character or `-`.
|
|
42
|
+
const UNIT_SUFFIX = /^(?:px|r?em|v[hw]|vmin|vmax|[dsl]v[hw]|ch|ex|cq[wh]|ms|%|fr|deg)(?![\w-])/;
|
|
43
|
+
// A `/` after one of these keywords starts a regex literal, not a division.
|
|
44
|
+
const REGEX_KEYWORDS =
|
|
45
|
+
/(?:^|[^\w$.])(?:return|typeof|case|in|of|delete|void|throw|new|else|do|yield|await)$/;
|
|
46
|
+
const REGEX_PRECEDERS = new Set(['(', ',', '=', ':', '[', '!', '&', '|', '?', '{', ';']);
|
|
47
|
+
|
|
48
|
+
/** Every class-context template literal with `${}` holes, with offsets for each text part and hole. */
|
|
49
|
+
export function findTemplates(text) {
|
|
50
|
+
const templates = [];
|
|
51
|
+
|
|
52
|
+
function skipString(i, quote) {
|
|
53
|
+
for (let j = i + 1; j < text.length; j++) {
|
|
54
|
+
const ch = text[j];
|
|
55
|
+
if (ch === '\\') j++;
|
|
56
|
+
else if (ch === quote) return j + 1;
|
|
57
|
+
else if (ch === '\n') return i + 1;
|
|
58
|
+
}
|
|
59
|
+
return i + 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function scanTemplate(start, classy) {
|
|
63
|
+
const quasis = [];
|
|
64
|
+
const holes = [];
|
|
65
|
+
let partStart = start + 1;
|
|
66
|
+
let i = start + 1;
|
|
67
|
+
while (i < text.length) {
|
|
68
|
+
const ch = text[i];
|
|
69
|
+
if (ch === '\\') {
|
|
70
|
+
i += 2;
|
|
71
|
+
} else if (ch === '`') {
|
|
72
|
+
quasis.push({ text: text.slice(partStart, i), start: partStart });
|
|
73
|
+
if (classy && holes.length > 0) templates.push({ start, end: i + 1, quasis, holes });
|
|
74
|
+
return i + 1;
|
|
75
|
+
} else if (ch === '$' && text[i + 1] === '{') {
|
|
76
|
+
quasis.push({ text: text.slice(partStart, i), start: partStart });
|
|
77
|
+
const closed = scanCode(i + 2, classy, true);
|
|
78
|
+
holes.push({ start: i, end: closed });
|
|
79
|
+
i = closed + 1;
|
|
80
|
+
partStart = i;
|
|
81
|
+
} else {
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return text.length;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Index just past a regex literal that starts at `i` (a `/`), or `i + 1` when it is not one. */
|
|
89
|
+
function skipRegex(i) {
|
|
90
|
+
let inClass = false;
|
|
91
|
+
for (let j = i + 1; j < text.length; j++) {
|
|
92
|
+
const ch = text[j];
|
|
93
|
+
if (ch === '\n') return i + 1;
|
|
94
|
+
if (ch === '\\') j++;
|
|
95
|
+
else if (ch === '[') inClass = true;
|
|
96
|
+
else if (ch === ']') inClass = false;
|
|
97
|
+
else if (ch === '/' && !inClass) {
|
|
98
|
+
let end = j + 1;
|
|
99
|
+
while (/[a-z]/i.test(text[end] ?? '')) end++;
|
|
100
|
+
return end;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return i + 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** True when the `/` at `i` begins a regex literal (judged by the previous significant token). */
|
|
107
|
+
function startsRegex(i) {
|
|
108
|
+
let j = i - 1;
|
|
109
|
+
while (j >= 0 && /\s/.test(text[j])) j--;
|
|
110
|
+
if (j < 0) return true;
|
|
111
|
+
const prev = text[j];
|
|
112
|
+
if (prev === '>') return text[j - 1] === '=';
|
|
113
|
+
if (REGEX_PRECEDERS.has(prev)) return true;
|
|
114
|
+
return REGEX_KEYWORDS.test(text.slice(Math.max(0, j - 12), j + 1));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function opensClassy(i, ch, inherited) {
|
|
118
|
+
if (inherited) return true;
|
|
119
|
+
const before = text.slice(Math.max(0, i - 120), i);
|
|
120
|
+
if (ch === '(') return CLASS_FNS.test(before);
|
|
121
|
+
return CLASS_NAME_ASSIGN.test(before);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function scanCode(from, inherited, untilCloseBrace) {
|
|
125
|
+
const frames = [];
|
|
126
|
+
let i = from;
|
|
127
|
+
while (i < text.length) {
|
|
128
|
+
const ch = text[i];
|
|
129
|
+
const next = text[i + 1];
|
|
130
|
+
const classy = inherited || frames.some(Boolean);
|
|
131
|
+
if (ch === '/' && next === '/') {
|
|
132
|
+
while (i < text.length && text[i] !== '\n') i++;
|
|
133
|
+
} else if (ch === '/' && next === '*') {
|
|
134
|
+
const end = text.indexOf('*/', i + 2);
|
|
135
|
+
i = end === -1 ? text.length : end + 2;
|
|
136
|
+
} else if (ch === '/' && startsRegex(i)) {
|
|
137
|
+
i = skipRegex(i);
|
|
138
|
+
} else if (ch === "'" || ch === '"') {
|
|
139
|
+
i = skipString(i, ch);
|
|
140
|
+
} else if (ch === '`') {
|
|
141
|
+
const direct = classy || CLASS_NAME_DIRECT.test(text.slice(Math.max(0, i - 160), i));
|
|
142
|
+
i = scanTemplate(i, direct);
|
|
143
|
+
} else if (ch === '{' || ch === '(' || ch === '[') {
|
|
144
|
+
frames.push(opensClassy(i, ch, classy));
|
|
145
|
+
i++;
|
|
146
|
+
} else if (ch === '}' || ch === ')' || ch === ']') {
|
|
147
|
+
if (frames.length === 0 && ch === '}' && untilCloseBrace) return i;
|
|
148
|
+
frames.pop();
|
|
149
|
+
i++;
|
|
150
|
+
} else {
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return text.length;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
scanCode(0, false, false);
|
|
158
|
+
return templates;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const lastToken = (s) => s.split(/\s/).pop() ?? '';
|
|
162
|
+
const inArbitraryValue = (token) => token.split('[').length > token.split(']').length;
|
|
163
|
+
|
|
164
|
+
/** The boundaries of one template where a class token touches a `${` or `}`. */
|
|
165
|
+
export function findGaps(template) {
|
|
166
|
+
const gaps = [];
|
|
167
|
+
const { quasis, holes } = template;
|
|
168
|
+
for (let i = 0; i < holes.length; i++) {
|
|
169
|
+
const before = quasis[i].text;
|
|
170
|
+
const after = quasis[i + 1].text;
|
|
171
|
+
if (inArbitraryValue(lastToken(before))) continue;
|
|
172
|
+
if (before !== '' && !WHITESPACE.test(before.at(-1)) && !JOIN_BEFORE.test(before.at(-1))) {
|
|
173
|
+
gaps.push({ kind: 'before', offset: holes[i].start });
|
|
174
|
+
}
|
|
175
|
+
if (
|
|
176
|
+
after !== '' &&
|
|
177
|
+
!WHITESPACE.test(after[0]) &&
|
|
178
|
+
!JOIN_AFTER.test(after[0]) &&
|
|
179
|
+
!UNIT_SUFFIX.test(after)
|
|
180
|
+
) {
|
|
181
|
+
gaps.push({ kind: 'after', offset: holes[i].end });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return gaps;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const MESSAGES = {
|
|
188
|
+
before: 'class token runs straight into `${`: add a space before it',
|
|
189
|
+
after: 'class token follows `}` with no space: add a space after it',
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** Hits for one file's text: { file, line, col, kind, message, snippet }. */
|
|
193
|
+
export function checkText(file, text) {
|
|
194
|
+
if (!text.includes('`')) return [];
|
|
195
|
+
const lines = text.split('\n');
|
|
196
|
+
const lineStarts = [];
|
|
197
|
+
let pos = 0;
|
|
198
|
+
for (const line of lines) {
|
|
199
|
+
lineStarts.push(pos);
|
|
200
|
+
pos += line.length + 1;
|
|
201
|
+
}
|
|
202
|
+
const lineOf = (offset) => {
|
|
203
|
+
let lo = 0;
|
|
204
|
+
let hi = lineStarts.length - 1;
|
|
205
|
+
while (lo < hi) {
|
|
206
|
+
const mid = (lo + hi + 1) >> 1;
|
|
207
|
+
if (lineStarts[mid] <= offset) lo = mid;
|
|
208
|
+
else hi = mid - 1;
|
|
209
|
+
}
|
|
210
|
+
return lo;
|
|
211
|
+
};
|
|
212
|
+
const excepted = (index) =>
|
|
213
|
+
[lines[index], lines[index - 1]].some((l) => l !== undefined && /se-exception:\s*\S/.test(l));
|
|
214
|
+
|
|
215
|
+
const hits = [];
|
|
216
|
+
for (const template of findTemplates(text)) {
|
|
217
|
+
for (const gap of findGaps(template)) {
|
|
218
|
+
const index = lineOf(gap.offset);
|
|
219
|
+
if (excepted(index)) continue;
|
|
220
|
+
hits.push({
|
|
221
|
+
file,
|
|
222
|
+
line: index + 1,
|
|
223
|
+
col: gap.offset - lineStarts[index] + 1,
|
|
224
|
+
kind: gap.kind,
|
|
225
|
+
message: MESSAGES[gap.kind],
|
|
226
|
+
snippet: lines[index].trim().slice(0, 160),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return hits.sort((a, b) => a.line - b.line || a.col - b.col);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function listFiles(target, out) {
|
|
234
|
+
const stat = statSync(target, { throwIfNoEntry: false });
|
|
235
|
+
if (!stat) return;
|
|
236
|
+
if (stat.isFile()) {
|
|
237
|
+
if (CODE_FILE.test(target) && !SKIP_FILE.test(target)) out.push(target);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
for (const entry of readdirSync(target, { withFileTypes: true })) {
|
|
241
|
+
if (entry.isDirectory() && SKIP_DIR.has(entry.name)) continue;
|
|
242
|
+
listFiles(join(target, entry.name), out);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function checkPaths(targets, cwd = process.cwd()) {
|
|
247
|
+
const files = [];
|
|
248
|
+
for (const target of targets) listFiles(join(cwd, target), files);
|
|
249
|
+
const hits = [];
|
|
250
|
+
for (const file of files.sort()) {
|
|
251
|
+
hits.push(...checkText(relative(cwd, file).split('\\').join('/'), readFileSync(file, 'utf8')));
|
|
252
|
+
}
|
|
253
|
+
return hits;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function main() {
|
|
257
|
+
const args = process.argv.slice(2);
|
|
258
|
+
const json = args.includes('--json');
|
|
259
|
+
const targets = args.filter((a) => !a.startsWith('--'));
|
|
260
|
+
const hits = checkPaths(targets.length > 0 ? targets : ['src']);
|
|
261
|
+
if (json) {
|
|
262
|
+
console.log(JSON.stringify(hits, null, 2));
|
|
263
|
+
} else {
|
|
264
|
+
for (const h of hits)
|
|
265
|
+
console.log(`${h.file}:${h.line}:${h.col} ${h.message}\n ${h.snippet}`);
|
|
266
|
+
console.log(
|
|
267
|
+
hits.length === 0
|
|
268
|
+
? 'check-class-gaps: no class token runs into a template hole'
|
|
269
|
+
: `check-class-gaps: ${hits.length} gap(s). Put a space between the token and the \`\${}\` (or add \`se-exception: <reason>\`).`,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
if (hits.length > 0) process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function isEntrypoint() {
|
|
276
|
+
if (!process.argv[1]) return false;
|
|
277
|
+
try {
|
|
278
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
279
|
+
} catch {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (isEntrypoint()) main();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PageModel } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The seam between "where a page comes from" and "what a page needs".
|
|
4
|
+
*
|
|
5
|
+
* Checks (checks.ts) are pure functions of a {@link PageModel}. An adapter turns one kind of input into
|
|
6
|
+
* that model. Today there is one adapter: {@link htmlPageAdapter} (html-adapter.ts).
|
|
7
|
+
*
|
|
8
|
+
* A later phase can run the same checks on Figma frames before build by adding a second adapter that
|
|
9
|
+
* maps a frame to a PageModel (frame name -> role, text nodes -> headings, button-like components -> CTAs,
|
|
10
|
+
* input components -> forms, node y-position vs the first viewport -> `aboveFold`). No check changes
|
|
11
|
+
* are needed. That adapter is deliberately NOT built here.
|
|
12
|
+
*/
|
|
13
|
+
export interface PageModelAdapter<TInput> {
|
|
14
|
+
readonly source: PageModel['source'];
|
|
15
|
+
toPageModel(input: TInput): PageModel;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/site-type-audit/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,WAAW,gBAAgB,CAAC,MAAM;IACtC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/site-type-audit/adapter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CheckResult, CheckStatus, PageModel, PageRole, Severity, SiteKind } from './types.js';
|
|
2
|
+
export interface CheckOutcome {
|
|
3
|
+
status: Exclude<CheckStatus, 'na'> | 'na';
|
|
4
|
+
message: string;
|
|
5
|
+
evidence?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CheckDef {
|
|
8
|
+
id: string;
|
|
9
|
+
roles: readonly PageRole[] | 'all';
|
|
10
|
+
except?: readonly PageRole[];
|
|
11
|
+
description: string;
|
|
12
|
+
severity: Record<SiteKind, Severity>;
|
|
13
|
+
run(m: PageModel): CheckOutcome;
|
|
14
|
+
}
|
|
15
|
+
export declare const analyticsTrackers: (m: PageModel) => import("./types.js").PageTracker[];
|
|
16
|
+
export declare const consentGated: (m: PageModel) => boolean;
|
|
17
|
+
export declare const CHECKS: CheckDef[];
|
|
18
|
+
export declare function checksForRole(role: PageRole): CheckDef[];
|
|
19
|
+
export declare function runPageChecks(model: PageModel, role: PageRole, kind: SiteKind): CheckResult[];
|
|
20
|
+
export declare function describeRoleChecklists(): {
|
|
21
|
+
role: string;
|
|
22
|
+
checks: CheckDef[];
|
|
23
|
+
}[];
|
|
24
|
+
//# sourceMappingURL=checks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../src/site-type-audit/checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpG,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;CACjC;AAqBD,eAAO,MAAM,iBAAiB,MAAO,SAAS,uCACU,CAAC;AAEzD,eAAO,MAAM,YAAY,MAAO,SAAS,YACkD,CAAC;AAyC5F,eAAO,MAAM,MAAM,EAAE,QAAQ,EAy5B5B,CAAC;AA8BF,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAIxD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,EAAE,CAa7F;AAED,wBAAgB,sBAAsB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;CAAE,EAAE,CA2B/E"}
|