basalt-ui 1.1.0 → 1.2.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/AGENTS.md +2 -2
- package/CHANGELOG.md +37 -0
- package/README.md +47 -5
- package/agent/rules/basalt-app.md +126 -0
- package/agent/rules/basalt-content.md +3 -1
- package/agent/skills/basalt-app/SKILL.md +32 -10
- package/configs/check.yml +3 -1
- package/configs/oxlint.json +1 -1
- package/dist/agent/part-list.d.ts.map +1 -1
- package/dist/agent/part-list.js +17 -7
- package/dist/agent/stick-to-bottom.js +2 -2
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
- package/dist/agent-chat/thread-detail-panel.js +37 -33
- package/dist/agent-chat/thread-message.d.ts.map +1 -1
- package/dist/agent-chat/thread-message.js +8 -5
- package/dist/agent-chat/thread-outcome-card.js +3 -3
- package/dist/agent-chat/thread-workspace.js +1 -1
- package/dist/charts/primitives/ChartLegend.js +2 -0
- package/dist/charts/primitives/ChartTooltip.js +2 -1
- package/dist/cli/index.d.ts +21 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +50 -12
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
- package/dist/connectivity/connectivity-indicator.js +3 -3
- package/dist/content/article-card.module.css +7 -5
- package/dist/content/article-layout.module.css +16 -12
- package/dist/content/callout.module.css +4 -4
- package/dist/content/code-block.module.css +8 -7
- package/dist/content/guide.module.css +3 -3
- package/dist/content/mermaid.module.css +2 -2
- package/dist/content/prose.module.css +59 -29
- package/dist/content/reading-progress.module.css +2 -0
- package/dist/content/toc.module.css +6 -3
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +10 -2
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +3 -16
- package/dist/dashboard/settings-section.js +2 -2
- package/dist/dashboard/settings-section.module.css +2 -2
- package/dist/dashboard/stat-card.js +2 -1
- package/dist/data/virtual-list.d.ts.map +1 -1
- package/dist/data/virtual-list.js +12 -2
- package/dist/forms/FormErrorSummary.js +2 -2
- package/dist/guard/index.d.ts +20 -4
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +250 -37
- package/dist/guard/types.d.ts +24 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/provider/index.d.ts +30 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +32 -7
- package/dist/provider/lab-theme.d.ts +39 -0
- package/dist/provider/lab-theme.d.ts.map +1 -0
- package/dist/provider/lab-theme.js +52 -0
- package/dist/shell/app-header.module.css +2 -2
- package/dist/shell/app-mobile-nav.module.css +1 -1
- package/dist/shell/app-sidebar-account.d.ts.map +1 -1
- package/dist/shell/app-sidebar-account.js +4 -2
- package/dist/shell/app-sidebar.d.ts.map +1 -1
- package/dist/shell/app-sidebar.js +4 -2
- package/dist/shell/app-sidebar.module.css +36 -26
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +11 -4
- package/dist/shell/sidebar-search.module.css +16 -4
- package/dist/styles.css +1 -1
- package/dist/surfaces.d.ts +16 -12
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +12 -4
- package/dist/theme/controls.module.css +1 -1
- package/dist/theme/floating.module.css +1 -1
- package/dist/theme/index.d.ts +116 -11
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +703 -566
- package/dist/theme/nav-link.module.css +1 -1
- package/dist/theme/use-basalt-spacing.d.ts +3 -0
- package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
- package/dist/theme/use-basalt-spacing.js +8 -0
- package/dist/theme-lab/derive-controls.d.ts +13 -0
- package/dist/theme-lab/derive-controls.d.ts.map +1 -0
- package/dist/theme-lab/derive-controls.js +137 -0
- package/dist/theme-lab/derive-state.d.ts +55 -0
- package/dist/theme-lab/derive-state.d.ts.map +1 -0
- package/dist/theme-lab/derive-state.js +81 -0
- package/dist/theme-lab/index.d.ts +12 -2
- package/dist/theme-lab/index.d.ts.map +1 -1
- package/dist/theme-lab/index.js +13 -62
- package/dist/theme-toggle/index.d.ts.map +1 -1
- package/dist/theme-toggle/index.js +3 -2
- package/dist/tokens/derive.d.ts +89 -0
- package/dist/tokens/derive.d.ts.map +1 -0
- package/dist/tokens/derive.js +250 -0
- package/dist/tokens/hct.d.ts +34 -0
- package/dist/tokens/hct.d.ts.map +1 -0
- package/dist/tokens/hct.js +159 -0
- package/dist/tokens/index.d.ts +71 -7
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +284 -46
- package/dist/tokens/palette.d.ts +984 -167
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +617 -119
- package/dist/vite-color-mix.d.ts +30 -0
- package/dist/vite-color-mix.d.ts.map +1 -0
- package/dist/vite-color-mix.js +80 -0
- package/dist/vite.d.ts +82 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +312 -0
- package/llms.txt +5 -4
- package/package.json +24 -9
- package/src/agent/part-list.tsx +13 -7
- package/src/agent/stick-to-bottom.tsx +2 -2
- package/src/agent-chat/thread-detail-panel.tsx +13 -10
- package/src/agent-chat/thread-message.tsx +8 -5
- package/src/agent-chat/thread-outcome-card.tsx +2 -2
- package/src/agent-chat/thread-workspace.tsx +2 -2
- package/src/charts/primitives/ChartLegend.tsx +2 -2
- package/src/charts/primitives/ChartTooltip.tsx +2 -2
- package/src/cli/check-theme.test.ts +18 -0
- package/src/cli/index.ts +112 -20
- package/src/cli/init-sync.test.ts +68 -0
- package/src/connectivity/connectivity-indicator.tsx +8 -2
- package/src/content/article-card.module.css +7 -5
- package/src/content/article-layout.module.css +16 -12
- package/src/content/callout.module.css +4 -4
- package/src/content/code-block.module.css +8 -7
- package/src/content/guide.module.css +3 -3
- package/src/content/mermaid.module.css +2 -2
- package/src/content/prose.module.css +59 -29
- package/src/content/prose.module.css.test.ts +55 -0
- package/src/content/reading-progress.module.css +2 -0
- package/src/content/toc.module.css +6 -3
- package/src/dashboard/delta-badge.tsx +10 -4
- package/src/dashboard/empty-state.tsx +3 -16
- package/src/dashboard/settings-section.module.css +2 -2
- package/src/dashboard/settings-section.tsx +2 -2
- package/src/dashboard/stat-card.tsx +2 -2
- package/src/data/virtual-list.tsx +12 -2
- package/src/forms/FormErrorSummary.tsx +1 -1
- package/src/guard/check-source.test.ts +416 -5
- package/src/guard/index.ts +367 -45
- package/src/guard/types.ts +24 -2
- package/src/index.ts +1 -0
- package/src/provider/index.test.tsx +100 -0
- package/src/provider/index.tsx +79 -7
- package/src/provider/lab-theme.test.ts +147 -0
- package/src/provider/lab-theme.ts +166 -0
- package/src/shell/app-header.module.css +2 -2
- package/src/shell/app-mobile-nav.module.css +1 -1
- package/src/shell/app-sidebar-account.tsx +9 -2
- package/src/shell/app-sidebar.module.css +36 -26
- package/src/shell/app-sidebar.tsx +12 -2
- package/src/shell/index.tsx +14 -3
- package/src/shell/sidebar-search.module.css +16 -4
- package/src/styles.css +1 -1
- package/src/surfaces.ts +25 -11
- package/src/theme/contrast.test.ts +19 -3
- package/src/theme/controls.module.css +1 -1
- package/src/theme/density-option.test.ts +96 -0
- package/src/theme/density-relations.test.ts +428 -0
- package/src/theme/derive-theme.test.ts +101 -0
- package/src/theme/floating.module.css +1 -1
- package/src/theme/fonts-option.test.ts +69 -0
- package/src/theme/index.ts +930 -563
- package/src/theme/nav-link.module.css +1 -1
- package/src/theme/radius-option.test.ts +86 -0
- package/src/theme/radius.test.ts +132 -0
- package/src/theme/spacing.test.ts +432 -0
- package/src/theme/use-basalt-spacing.test.tsx +51 -0
- package/src/theme/use-basalt-spacing.ts +38 -0
- package/src/theme-lab/derive-controls.test.ts +94 -0
- package/src/theme-lab/derive-controls.tsx +227 -0
- package/src/theme-lab/derive-state.test.ts +71 -0
- package/src/theme-lab/derive-state.ts +163 -0
- package/src/theme-lab/index.tsx +29 -68
- package/src/theme-lab/theme-lab.test.ts +4 -18
- package/src/theme-toggle/index.tsx +9 -4
- package/src/tokens/build-fonts-css.test.ts +51 -0
- package/src/tokens/build-radius-css.test.ts +25 -0
- package/src/tokens/density.test.ts +274 -0
- package/src/tokens/derive-radius.test.ts +62 -0
- package/src/tokens/derive.test.ts +30 -0
- package/src/tokens/derive.ts +481 -0
- package/src/tokens/hct.ts +231 -0
- package/src/tokens/index.ts +395 -45
- package/src/tokens/palette.test.ts +114 -0
- package/src/tokens/palette.ts +1118 -180
- package/src/vite-color-mix.test.ts +46 -0
- package/src/vite-color-mix.ts +137 -0
- package/src/vite.test.ts +192 -0
- package/src/vite.ts +502 -1
package/src/guard/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ./guard — headless policy core. Mantine-free, dependency-free.
|
|
3
3
|
*
|
|
4
|
-
* GUARD_RULES: the closed registry of all
|
|
4
|
+
* GUARD_RULES: the closed registry of all 19 violation kinds.
|
|
5
5
|
* checkSource: pure (text, relPath, cfg) → Finding[]. No FS, no walk, no console.
|
|
6
6
|
*/
|
|
7
7
|
import type { Finding, GuardConfig, GuardKind } from './types'
|
|
@@ -14,12 +14,32 @@ const HEX = /#[0-9a-fA-F]{3,8}\b/g
|
|
|
14
14
|
const FUNC = /\b(?:rgba?|hsla?)\(/g
|
|
15
15
|
const LOCALSTORAGE_THEME = /localStorage\s*\.\s*getItem\s*\(\s*['"]theme['"]\s*\)/g
|
|
16
16
|
|
|
17
|
+
// A hardcoded fontFamily/font-family literal — camelCase (JSX prop / object property, quoted
|
|
18
|
+
// value) or kebab-case (CSS text in a template literal, quoted OR bare value — kebab-case is never
|
|
19
|
+
// a valid unquoted JS identifier, so a bare `font-family: Inter` can only be literal CSS text).
|
|
20
|
+
// The escape is a `var(...)` reference restricted to the two entry-point prefixes
|
|
21
|
+
// (`--basalt-font-*` / `--mantine-font-family-*`) — any OTHER var() reference still flags, so the
|
|
22
|
+
// single-entry-point invariant holds. A CSS-wide keyword (inherit/initial/unset/revert) never
|
|
23
|
+
// flags either: it defers to the cascade rather than hardcoding a font.
|
|
24
|
+
const RAW_FONT_FAMILY_VAR_ESCAPE = /var\(\s*--(?:basalt-font-|mantine-font-family-)/.source
|
|
25
|
+
const RAW_FONT_FAMILY_KEYWORD = /(?:inherit|initial|unset|revert)\b/.source
|
|
26
|
+
const RAW_FONT_FAMILY = new RegExp(
|
|
27
|
+
`\\bfontFamily\\s*[:=]\\s*\\{?(?!['"\`]?\\s*${RAW_FONT_FAMILY_VAR_ESCAPE})(?!['"\`]?\\s*${RAW_FONT_FAMILY_KEYWORD})['"\`][^'"\`]+['"\`]` +
|
|
28
|
+
`|\\bfont-family\\s*:\\s*(?!['"\`]?\\s*${RAW_FONT_FAMILY_VAR_ESCAPE})(?!['"\`]?\\s*${RAW_FONT_FAMILY_KEYWORD})(?:['"\`][^'"\`]+['"\`]|[A-Za-z][\\w-]*)`,
|
|
29
|
+
'g',
|
|
30
|
+
)
|
|
31
|
+
|
|
17
32
|
// Ad-hoc inline surface styling — border* / borderRadius / boxShadow with literal values.
|
|
18
|
-
//
|
|
33
|
+
// Three escapes pass (the value is already system-routed, not a hardcoded surface literal):
|
|
34
|
+
// • a `var(--…)` reference — the CSS-var system itself;
|
|
35
|
+
// • a `${…}` template-literal interpolation — the value is JS-composed, typically from `VX.*`
|
|
36
|
+
// tokens; any raw color inside it is separately caught by raw-hex / raw-color-fn;
|
|
37
|
+
// • for `border*` only, a bare `none`/`transparent`/`inherit`/`unset`/`revert` keyword — a reset,
|
|
38
|
+
// not a surface definition.
|
|
19
39
|
const SURFACE_BORDER =
|
|
20
|
-
/\bborder(?:Top|Bottom|Left|Right)?\s*:\s*(?!['"`]?[^'"`]*var\()['"`][^'"`]+['"`]/g
|
|
40
|
+
/\bborder(?:Top|Bottom|Left|Right)?\s*:\s*(?!['"`]?[^'"`]*(?:var\(|\$\{))(?!['"`]?(?:none|transparent|inherit|unset|revert)\b)['"`][^'"`]+['"`]/g
|
|
21
41
|
const SURFACE_RADIUS = /\bborderRadius\s*:\s*(?:[0-9]+|['"`](?!\s*var\()[^'"`]*[0-9])/g
|
|
22
|
-
const SURFACE_SHADOW = /\bboxShadow\s*:\s*(?!['"`]?[^'"`]*var\()['"`][^'"`]+['"`]/g
|
|
42
|
+
const SURFACE_SHADOW = /\bboxShadow\s*:\s*(?!['"`]?[^'"`]*(?:var\(|\$\{))['"`][^'"`]+['"`]/g
|
|
23
43
|
|
|
24
44
|
// A `Card` / `Paper` opening tag carrying `withBorder`. Card depth is `--vx-shadow-card`, whose 1px
|
|
25
45
|
// ring lives INSIDE the shadow value; `withBorder` therefore adds a SECOND, real `border` property
|
|
@@ -132,6 +152,7 @@ export const DEFAULT_GUARD_CONFIG: GuardConfig = {
|
|
|
132
152
|
rawFormControl: true,
|
|
133
153
|
sub16InputFont: true,
|
|
134
154
|
allowComment: 'theme-allow',
|
|
155
|
+
exemptRules: {},
|
|
135
156
|
}
|
|
136
157
|
|
|
137
158
|
// ── Path predicate ────────────────────────────────────────────────────────────────────────────────
|
|
@@ -141,14 +162,247 @@ function isChartFile(relPath: string): boolean {
|
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
165
|
+
* Whether `kind` is exempted at `relPath` via `cfg.exemptRules` — the config-driven, per-rule
|
|
166
|
+
* counterpart to `isChartFile`'s hardcoded path scoping. A pattern matches when `relPath` split on
|
|
167
|
+
* `/` includes it as a WHOLE segment (a trailing `/` is stripped first, so `'agent'` and `'agent/'`
|
|
168
|
+
* are equivalent); a substring match against one longer segment (e.g. `'age'` against `agent`)
|
|
169
|
+
* never counts.
|
|
170
|
+
*/
|
|
171
|
+
function isRuleExempt(
|
|
172
|
+
kind: GuardKind,
|
|
173
|
+
relPath: string,
|
|
174
|
+
exemptRules: GuardConfig['exemptRules'],
|
|
175
|
+
): boolean {
|
|
176
|
+
const patterns = exemptRules?.[kind]
|
|
177
|
+
if (patterns === undefined || patterns.length === 0) return false
|
|
178
|
+
const segments = relPath.split('/')
|
|
179
|
+
return patterns.some((pattern) => segments.includes(pattern.replace(/\/$/, '')))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The allow-comment skip the full-text tag-scoped scans re-apply on their own resolved report
|
|
184
|
+
* line: a line carrying the allow-comment is never a violation. Pure-comment lines need no
|
|
185
|
+
* special case here anymore — they are handled upstream by `stripComments` (matches simply can't
|
|
186
|
+
* land on blanked-out comment text), so this only ever runs against the ORIGINAL (unstripped)
|
|
187
|
+
* line, since the allow-comment annotation itself lives inside a comment.
|
|
147
188
|
*/
|
|
148
189
|
function isSkippedLine(line: string, cfg: GuardConfig): boolean {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
190
|
+
return line.includes(cfg.allowComment)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The 2 comment/regex dialects the stripper understands, resolved from the file's own extension. */
|
|
194
|
+
type GuardSyntax = 'ts' | 'css'
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* CSS (including `.module.css`) has no `//` line-comment syntax at all — an unquoted `//`, e.g.
|
|
198
|
+
* inside `url(https://…)`, is real CSS text, never a comment opener. Match on the `.css` suffix
|
|
199
|
+
* (not a naive `split('.')`) so `foo.module.css` resolves the same as `foo.css`.
|
|
200
|
+
*/
|
|
201
|
+
function guardSyntaxFor(relPath: string): GuardSyntax {
|
|
202
|
+
return relPath.endsWith('.css') ? 'css' : 'ts'
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// A `/` opens a regex literal (not division) when the previous significant token is one of these
|
|
206
|
+
// punctuation marks, or one of the REGEX_PRECEDING_KEYWORDS below, or nothing has been scanned yet
|
|
207
|
+
// (start of input) — the standard JS lexer disambiguation. `ts`-syntax only; CSS has no regexes.
|
|
208
|
+
const REGEX_PRECEDING_PUNCT = new Set([
|
|
209
|
+
'=',
|
|
210
|
+
'(',
|
|
211
|
+
',',
|
|
212
|
+
'[',
|
|
213
|
+
':',
|
|
214
|
+
'!',
|
|
215
|
+
'&',
|
|
216
|
+
'|',
|
|
217
|
+
'?',
|
|
218
|
+
'{',
|
|
219
|
+
'}',
|
|
220
|
+
';',
|
|
221
|
+
'+',
|
|
222
|
+
'-',
|
|
223
|
+
'*',
|
|
224
|
+
'%',
|
|
225
|
+
'~',
|
|
226
|
+
'^',
|
|
227
|
+
'<',
|
|
228
|
+
])
|
|
229
|
+
const REGEX_PRECEDING_KEYWORDS = new Set([
|
|
230
|
+
'return',
|
|
231
|
+
'typeof',
|
|
232
|
+
'case',
|
|
233
|
+
'in',
|
|
234
|
+
'of',
|
|
235
|
+
'delete',
|
|
236
|
+
'void',
|
|
237
|
+
'throw',
|
|
238
|
+
'do',
|
|
239
|
+
'else',
|
|
240
|
+
])
|
|
241
|
+
const WORD_CHAR = /[A-Za-z0-9_$]/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Strip comments out of source text, leaving real comment-awareness in place of the old per-line
|
|
245
|
+
* prefix heuristic (which only caught a comment when ITS OWN line happened to start with `//` /
|
|
246
|
+
* `*` / `/*` — a block-comment continuation line that didn't start with `*` slipped straight
|
|
247
|
+
* through as if it were code).
|
|
248
|
+
*
|
|
249
|
+
* Stripped characters are replaced 1:1 with a space (newlines are preserved verbatim), so the
|
|
250
|
+
* output is the SAME LENGTH as the input and every remaining token keeps its exact original line
|
|
251
|
+
* number and character offset — callers can keep using `text.slice(0, i).split('\n').length` for
|
|
252
|
+
* line numbers exactly as before.
|
|
253
|
+
*
|
|
254
|
+
* Deliberately does NOT touch string literals (`'`, `"`, backtick, backslash-escaped): a raw hex
|
|
255
|
+
* or a `//` inside a string is real source text, not a comment, and must still be scanned as-is
|
|
256
|
+
* (e.g. a URL like `'https://x.com/#abc'` must not have its `//` treated as a line comment).
|
|
257
|
+
*
|
|
258
|
+
* `syntax === 'css'` disables `//` line-comment handling entirely (CSS only has `/* *\/`) — an
|
|
259
|
+
* unquoted `url(https://…)` must never have its rest-of-line blanked (that was the BUG 2 false
|
|
260
|
+
* negative: a real violation on the same line silently disappearing behind a bogus "comment").
|
|
261
|
+
*
|
|
262
|
+
* `syntax === 'ts'` additionally recognizes regex literals (`/…/flags`) via
|
|
263
|
+
* `REGEX_PRECEDING_PUNCT` / `REGEX_PRECEDING_KEYWORDS` and consumes them VERBATIM — a `/*` or `//`
|
|
264
|
+
* shaped sequence inside a regex body (e.g. a character class `/[/*]/`) is real regex source, not
|
|
265
|
+
* a comment opener, and must not open a block comment that then runs away to EOF eating every
|
|
266
|
+
* subsequent line unrecoverably (that was the BUG 1 false negative — total loss of guard coverage
|
|
267
|
+
* for the rest of the file). The heuristic is inherently imperfect (full disambiguation needs a
|
|
268
|
+
* real parser), so it is DELIBERATELY biased toward treating an ambiguous `/` as division, i.e.
|
|
269
|
+
* NOT a regex, i.e. NOT specially protected: an under-strip here just leaves a `/` as an ordinary
|
|
270
|
+
* character (worst case a spurious finding a human can `theme-allow`), whereas an over-eager
|
|
271
|
+
* regex-open would swallow real code as "protected regex content" and could hide a genuine
|
|
272
|
+
* violation — the failure mode BUG 1 already showed is unacceptable.
|
|
273
|
+
*/
|
|
274
|
+
function stripComments(text: string, syntax: GuardSyntax): string {
|
|
275
|
+
const out: string[] = Array.from<string>({ length: text.length })
|
|
276
|
+
let inLineComment = false
|
|
277
|
+
let inBlockComment = false
|
|
278
|
+
let stringQuote: string | null = null
|
|
279
|
+
let currentWord = ''
|
|
280
|
+
let lastUnitType: 'word' | 'punct' | 'none' = 'none'
|
|
281
|
+
let lastWord = ''
|
|
282
|
+
let lastPunct = ''
|
|
283
|
+
let i = 0
|
|
284
|
+
|
|
285
|
+
function flushWord(): void {
|
|
286
|
+
if (currentWord === '') return
|
|
287
|
+
lastUnitType = 'word'
|
|
288
|
+
lastWord = currentWord
|
|
289
|
+
currentWord = ''
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function canPrecedeRegex(): boolean {
|
|
293
|
+
if (lastUnitType === 'none') return true
|
|
294
|
+
if (lastUnitType === 'word') return REGEX_PRECEDING_KEYWORDS.has(lastWord)
|
|
295
|
+
return REGEX_PRECEDING_PUNCT.has(lastPunct)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
while (i < text.length) {
|
|
299
|
+
const ch = text[i] ?? ''
|
|
300
|
+
|
|
301
|
+
if (inLineComment) {
|
|
302
|
+
out[i] = ch === '\n' ? '\n' : ' '
|
|
303
|
+
if (ch === '\n') inLineComment = false
|
|
304
|
+
i++
|
|
305
|
+
continue
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (inBlockComment) {
|
|
309
|
+
if (ch === '*' && text[i + 1] === '/') {
|
|
310
|
+
out[i] = ' '
|
|
311
|
+
out[i + 1] = ' '
|
|
312
|
+
i += 2
|
|
313
|
+
inBlockComment = false
|
|
314
|
+
continue
|
|
315
|
+
}
|
|
316
|
+
out[i] = ch === '\n' ? '\n' : ' '
|
|
317
|
+
i++
|
|
318
|
+
continue
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (stringQuote !== null) {
|
|
322
|
+
out[i] = ch
|
|
323
|
+
if (ch === '\\' && i + 1 < text.length) {
|
|
324
|
+
out[i + 1] = text[i + 1] ?? ''
|
|
325
|
+
i += 2
|
|
326
|
+
continue
|
|
327
|
+
}
|
|
328
|
+
if (ch === stringQuote) stringQuote = null
|
|
329
|
+
i++
|
|
330
|
+
continue
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (WORD_CHAR.test(ch)) {
|
|
334
|
+
currentWord += ch
|
|
335
|
+
out[i] = ch
|
|
336
|
+
i++
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
339
|
+
flushWord()
|
|
340
|
+
|
|
341
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
342
|
+
stringQuote = ch
|
|
343
|
+
out[i] = ch
|
|
344
|
+
lastUnitType = 'punct'
|
|
345
|
+
lastPunct = ch
|
|
346
|
+
i++
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (ch === '/' && text[i + 1] === '*') {
|
|
351
|
+
inBlockComment = true
|
|
352
|
+
out[i] = ' '
|
|
353
|
+
i++
|
|
354
|
+
continue
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (syntax === 'ts' && ch === '/' && text[i + 1] === '/') {
|
|
358
|
+
inLineComment = true
|
|
359
|
+
out[i] = ' '
|
|
360
|
+
i++
|
|
361
|
+
continue
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (syntax === 'ts' && ch === '/' && canPrecedeRegex()) {
|
|
365
|
+
// Consume the regex literal VERBATIM: backslash escapes and `[...]` character classes never
|
|
366
|
+
// close it early. A raw newline before the closing `/` means this was never a valid regex
|
|
367
|
+
// (JS disallows a literal line terminator inside one) — bail out of regex mode right there;
|
|
368
|
+
// every character up to the newline was already copied through unchanged either way, so
|
|
369
|
+
// bailing loses nothing.
|
|
370
|
+
out[i] = ch
|
|
371
|
+
let j = i + 1
|
|
372
|
+
let inClass = false
|
|
373
|
+
while (j < text.length) {
|
|
374
|
+
const rc = text[j] ?? ''
|
|
375
|
+
if (rc === '\n') break
|
|
376
|
+
out[j] = rc
|
|
377
|
+
if (rc === '\\' && j + 1 < text.length) {
|
|
378
|
+
out[j + 1] = text[j + 1] ?? ''
|
|
379
|
+
j += 2
|
|
380
|
+
continue
|
|
381
|
+
}
|
|
382
|
+
if (rc === '[') inClass = true
|
|
383
|
+
else if (rc === ']') inClass = false
|
|
384
|
+
else if (rc === '/' && !inClass) {
|
|
385
|
+
j++
|
|
386
|
+
break
|
|
387
|
+
}
|
|
388
|
+
j++
|
|
389
|
+
}
|
|
390
|
+
i = j
|
|
391
|
+
lastUnitType = 'punct'
|
|
392
|
+
lastPunct = '/'
|
|
393
|
+
continue
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Plain `/` (division, or any bare `/` in CSS syntax) — or any other punctuation/whitespace.
|
|
397
|
+
out[i] = ch
|
|
398
|
+
if (!/\s/.test(ch)) {
|
|
399
|
+
lastUnitType = 'punct'
|
|
400
|
+
lastPunct = ch
|
|
401
|
+
}
|
|
402
|
+
i++
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return out.join('')
|
|
152
406
|
}
|
|
153
407
|
|
|
154
408
|
// ── GUARD_RULES registry ─────────────────────────────────────────────────────────────────────────
|
|
@@ -166,7 +420,7 @@ type GuardRule = {
|
|
|
166
420
|
}
|
|
167
421
|
|
|
168
422
|
/**
|
|
169
|
-
* The closed registry of all
|
|
423
|
+
* The closed registry of all 19 guard kinds. The triad test asserts
|
|
170
424
|
* `surface.guardKinds ⊆ keyof GUARD_RULES` at runtime.
|
|
171
425
|
*
|
|
172
426
|
* raw-surface, raw-html-layout, and sub-16-input-font are handled inline in checkSource
|
|
@@ -194,8 +448,16 @@ export const GUARD_RULES = {
|
|
|
194
448
|
'localstorage-theme': {
|
|
195
449
|
kind: 'localstorage-theme',
|
|
196
450
|
pattern: LOCALSTORAGE_THEME,
|
|
451
|
+
// JS-call-shaped (`localStorage.getItem('theme')`) — never appears in CSS text.
|
|
452
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
197
453
|
message: 'Theme must resolve via the Mantine color scheme + --vx-* vars.',
|
|
198
454
|
},
|
|
455
|
+
'raw-font-family': {
|
|
456
|
+
kind: 'raw-font-family',
|
|
457
|
+
pattern: RAW_FONT_FAMILY,
|
|
458
|
+
message:
|
|
459
|
+
'Route the font stack through createBasaltTheme(overrides, { fonts }) / the shipped --basalt-font-sans|head|mono vars instead of a hardcoded fontFamily literal.',
|
|
460
|
+
},
|
|
199
461
|
'off-identity-accent': {
|
|
200
462
|
kind: 'off-identity-accent',
|
|
201
463
|
pattern: (cfg: GuardConfig) =>
|
|
@@ -203,6 +465,10 @@ export const GUARD_RULES = {
|
|
|
203
465
|
`\\b(?:color|c|bg|backgroundColor)\\s*=\\s*\\{?\\s*['"](${cfg.forbiddenAccents.join('|')})['"]`,
|
|
204
466
|
'g',
|
|
205
467
|
),
|
|
468
|
+
// JSX-prop-shaped (`color={"teal"}`) — CSS declares `color: teal;` with a bare keyword and
|
|
469
|
+
// `:`, which the pattern's `=` anchor can never match; gated off explicitly so a future regex
|
|
470
|
+
// tweak can't silently start false-positiving on consumer CSS.
|
|
471
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
206
472
|
message: 'For an off-identity accent use blue/gray or a status hue (red/green/orange/yellow).',
|
|
207
473
|
},
|
|
208
474
|
'raw-spacing': {
|
|
@@ -212,12 +478,17 @@ export const GUARD_RULES = {
|
|
|
212
478
|
`\\b(?:p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap)=\\{(?:${cfg.spacingSteps.join('|')})\\}`,
|
|
213
479
|
'g',
|
|
214
480
|
),
|
|
481
|
+
// JSX-prop-shaped (`p={16}`) — CSS has no `=`/`{}` prop syntax; gated off explicitly (see
|
|
482
|
+
// off-identity-accent above for why "never matches today" still gets an explicit gate).
|
|
483
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
215
484
|
message: 'Use the Mantine spacing prop/token (p/m/gap with xs..xl).',
|
|
216
485
|
},
|
|
217
486
|
'raw-radius': {
|
|
218
487
|
kind: 'raw-radius',
|
|
219
488
|
pattern: RADIUS_PROP_RE,
|
|
220
489
|
enabled: (cfg: GuardConfig) => cfg.rawRadius,
|
|
490
|
+
// JSX-prop-shaped (`radius={6}`) — CSS declares `border-radius: 6px;`, never `radius=`.
|
|
491
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
221
492
|
message: 'Use the radius token (radius="md") instead of a numeric literal.',
|
|
222
493
|
},
|
|
223
494
|
'raw-surface': {
|
|
@@ -231,6 +502,8 @@ export const GUARD_RULES = {
|
|
|
231
502
|
kind: 'card-with-border',
|
|
232
503
|
pattern: CARD_SURFACE_TAG, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
233
504
|
enabled: (cfg: GuardConfig) => cfg.cardWithBorder,
|
|
505
|
+
// JSX-tag-shaped (`<Card withBorder>`) — never appears in CSS text.
|
|
506
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
234
507
|
message:
|
|
235
508
|
'withBorder on a Card/Paper double-draws the edge — card depth is --vx-shadow-card, which already bakes a 1px ring into the shadow. Drop the prop (docs/DESIGN-SPEC.md doctrine inversion #1).',
|
|
236
509
|
},
|
|
@@ -245,6 +518,8 @@ export const GUARD_RULES = {
|
|
|
245
518
|
kind: 'raw-html-layout',
|
|
246
519
|
pattern: RAW_HTML_TAG, // handled inline (3-condition conjunction); entry keeps registry complete
|
|
247
520
|
enabled: (cfg: GuardConfig) => cfg.rawHtmlLayout,
|
|
521
|
+
// JSX-tag-shaped (`<div style={{...}}>`) — never appears in CSS text.
|
|
522
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
248
523
|
message:
|
|
249
524
|
'Raw HTML element with inline layout/surface styling — use a Mantine layout primitive (Box/Flex/Grid/Stack/Group).',
|
|
250
525
|
},
|
|
@@ -258,13 +533,18 @@ export const GUARD_RULES = {
|
|
|
258
533
|
kind: 'inline-display',
|
|
259
534
|
pattern: INLINE_DISPLAY,
|
|
260
535
|
enabled: (cfg: GuardConfig) => cfg.inlineDisplay,
|
|
536
|
+
// JSX-object-shaped (`display: 'flex'`, quoted value) — CSS never quotes a keyword value
|
|
537
|
+
// (`display: flex;` is bare), so the pattern's quote anchor can never match real CSS.
|
|
538
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
261
539
|
message: 'Use <Flex>/<Grid>/<Group> instead of an inline display:flex/grid.',
|
|
262
540
|
},
|
|
263
541
|
'raw-visx-axis': {
|
|
264
542
|
kind: 'raw-visx-axis',
|
|
265
543
|
pattern: RAW_VISX_AXIS,
|
|
266
544
|
enabled: (cfg: GuardConfig) => cfg.rawVisxAxis,
|
|
267
|
-
|
|
545
|
+
// Compose the existing chart-file scope with the CSS gate — a chart-file CSS module (none
|
|
546
|
+
// exist today, but the boundary should hold regardless) still can't carry a JSX axis tag.
|
|
547
|
+
appliesTo: (relPath) => isChartFile(relPath) && !relPath.endsWith('.css'),
|
|
268
548
|
message:
|
|
269
549
|
'Raw <AxisLeft>/<AxisBottom>/<AxisRight> in a chart file — use AxisLeftNumeric / AxisBottomDate / AxisRightNumeric.',
|
|
270
550
|
},
|
|
@@ -272,6 +552,9 @@ export const GUARD_RULES = {
|
|
|
272
552
|
kind: 'raw-motion-value',
|
|
273
553
|
pattern: MOTION_TRANSITION_NUMERIC, // handled inline (2-regex kind); entry keeps registry complete
|
|
274
554
|
enabled: (cfg: GuardConfig) => cfg.rawMotionValue,
|
|
555
|
+
// JSX-prop-shaped (`transition={{ duration: … }}`) — CSS's `transition:` property has no `=`
|
|
556
|
+
// or `{{`.
|
|
557
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
275
558
|
message:
|
|
276
559
|
'Route animation timing through MOTION_DURATION / MOTION_SPRING / MOTION_EASE_STANDARD (basalt-ui motion tokens) instead of a hardcoded duration/spring/ease.',
|
|
277
560
|
},
|
|
@@ -279,6 +562,8 @@ export const GUARD_RULES = {
|
|
|
279
562
|
kind: 'unframed-chart',
|
|
280
563
|
pattern: RAW_CHART_LEGEND_ARRAY, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
281
564
|
enabled: (cfg: GuardConfig) => cfg.unframedChart,
|
|
565
|
+
// JSX-tag-shaped (`<ChartLegend items={[…]}>`) — never appears in CSS text.
|
|
566
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
282
567
|
message:
|
|
283
568
|
'Hand-rolled ChartLegend built from an inline array literal — pass a derived legend (deriveLegend(series)), or compose ChartFrame, which derives it for you.',
|
|
284
569
|
},
|
|
@@ -286,6 +571,8 @@ export const GUARD_RULES = {
|
|
|
286
571
|
kind: 'chart-missing-aria-label',
|
|
287
572
|
pattern: CHART_ENTRY_POINT_TAG, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
288
573
|
enabled: (cfg: GuardConfig) => cfg.chartMissingAriaLabel,
|
|
574
|
+
// JSX-tag-shaped (`<MultiLine …>`) — never appears in CSS text.
|
|
575
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
289
576
|
message:
|
|
290
577
|
'Chart has no accessible text alternative — pass ariaLabel="…" so screen readers get more than an unlabeled graphic.',
|
|
291
578
|
},
|
|
@@ -293,6 +580,9 @@ export const GUARD_RULES = {
|
|
|
293
580
|
kind: 'raw-form-control',
|
|
294
581
|
pattern: RAW_FORM_CONTROL,
|
|
295
582
|
enabled: (cfg: GuardConfig) => cfg.rawFormControl,
|
|
583
|
+
// JSX-tag-shaped (`<input …>`) — a CSS element selector (`input, select {…}`) has no leading
|
|
584
|
+
// `<`, so the pattern's anchor can never match real CSS.
|
|
585
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
296
586
|
message:
|
|
297
587
|
'Raw <input>/<select>/<textarea> bypasses the ENTIRE theme, not just the font-size floor — no field surface, no shadow-card depth, no focus ring, no --input-* vars. Use TextInput / NumberInput / Select / Textarea from @mantine/core, or variant="unstyled" for a genuinely borderless/bespoke look.',
|
|
298
588
|
},
|
|
@@ -300,11 +590,20 @@ export const GUARD_RULES = {
|
|
|
300
590
|
kind: 'sub-16-input-font',
|
|
301
591
|
pattern: SUB_16_FONT_SIZE, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
302
592
|
enabled: (cfg: GuardConfig) => cfg.sub16InputFont,
|
|
593
|
+
// Only ever fires nested inside a raw-form-control JSX tag or a `styles={{ input: {…} }}`
|
|
594
|
+
// object literal — both JSX-shaped, neither appears in CSS text.
|
|
595
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
303
596
|
message:
|
|
304
597
|
'fontSize below 16 on a form control is dead code — the styles.css iOS floor is `!important` and always wins. Either drop the override, or be honest about 16px in the design.',
|
|
305
598
|
},
|
|
306
599
|
} as const satisfies Record<GuardKind, GuardRule>
|
|
307
600
|
|
|
601
|
+
/** Whether `kind`'s rule fires for `relPath` — `appliesTo` is opt-in; absent means always applies. */
|
|
602
|
+
function ruleApplies(kind: GuardKind, relPath: string): boolean {
|
|
603
|
+
const appliesTo = (GUARD_RULES[kind] as GuardRule).appliesTo
|
|
604
|
+
return appliesTo === undefined || appliesTo(relPath)
|
|
605
|
+
}
|
|
606
|
+
|
|
308
607
|
// ── checkSource ───────────────────────────────────────────────────────────────────────────────────
|
|
309
608
|
|
|
310
609
|
/**
|
|
@@ -331,14 +630,19 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
331
630
|
(GUARD_RULES['raw-radius'].pattern as RegExp).flags,
|
|
332
631
|
)
|
|
333
632
|
|
|
633
|
+
// Comment-stripped text drives every match below; `lines` (the ORIGINAL, unstripped split) is
|
|
634
|
+
// kept only to resolve the allow-comment escape, since that annotation lives inside a comment
|
|
635
|
+
// the stripped text has already blanked out. Same length / same newline positions as `text`, so
|
|
636
|
+
// line numbers computed off either one agree.
|
|
334
637
|
const lines = text.split('\n')
|
|
638
|
+
const codeText = stripComments(text, guardSyntaxFor(relPath))
|
|
639
|
+
const codeLines = codeText.split('\n')
|
|
640
|
+
|
|
335
641
|
for (let i = 0; i < lines.length; i++) {
|
|
336
|
-
const line =
|
|
642
|
+
const line = codeLines[i] ?? ''
|
|
337
643
|
|
|
338
|
-
// Skip lines with the allow-comment
|
|
339
|
-
if (
|
|
340
|
-
const trimmed = line.trimStart()
|
|
341
|
-
if (trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')) continue
|
|
644
|
+
// Skip lines with the allow-comment (checked against the ORIGINAL line text).
|
|
645
|
+
if ((lines[i] ?? '').includes(cfg.allowComment)) continue
|
|
342
646
|
|
|
343
647
|
// Always-on kinds (raw-hex, raw-color-fn, localstorage-theme) — patterns from GUARD_RULES.
|
|
344
648
|
for (const m of line.matchAll(GUARD_RULES['raw-hex'].pattern as RegExp)) {
|
|
@@ -347,18 +651,27 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
347
651
|
for (const m of line.matchAll(GUARD_RULES['raw-color-fn'].pattern as RegExp)) {
|
|
348
652
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-color-fn' })
|
|
349
653
|
}
|
|
350
|
-
|
|
351
|
-
|
|
654
|
+
if (ruleApplies('localstorage-theme', relPath)) {
|
|
655
|
+
for (const m of line.matchAll(GUARD_RULES['localstorage-theme'].pattern as RegExp)) {
|
|
656
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'localstorage-theme' })
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
for (const m of line.matchAll(GUARD_RULES['raw-font-family'].pattern as RegExp)) {
|
|
660
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-font-family' })
|
|
352
661
|
}
|
|
353
662
|
|
|
354
663
|
// Dynamic-regex kinds — patterns already resolved above.
|
|
355
|
-
|
|
356
|
-
|
|
664
|
+
if (ruleApplies('off-identity-accent', relPath)) {
|
|
665
|
+
for (const m of line.matchAll(forbiddenAccentRe)) {
|
|
666
|
+
findings.push({ relPath, line: i + 1, token: m[1] ?? '', kind: 'off-identity-accent' })
|
|
667
|
+
}
|
|
357
668
|
}
|
|
358
|
-
|
|
359
|
-
|
|
669
|
+
if (ruleApplies('raw-spacing', relPath)) {
|
|
670
|
+
for (const m of line.matchAll(spacingPropRe)) {
|
|
671
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-spacing' })
|
|
672
|
+
}
|
|
360
673
|
}
|
|
361
|
-
if (GUARD_RULES['raw-radius'].enabled!(cfg)) {
|
|
674
|
+
if (GUARD_RULES['raw-radius'].enabled!(cfg) && ruleApplies('raw-radius', relPath)) {
|
|
362
675
|
for (const m of line.matchAll(radiusPropRe)) {
|
|
363
676
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-radius' })
|
|
364
677
|
}
|
|
@@ -387,6 +700,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
387
700
|
// raw-html-layout: 3-condition conjunction on the same line — gated via GUARD_RULES entry.
|
|
388
701
|
if (
|
|
389
702
|
GUARD_RULES['raw-html-layout'].enabled!(cfg) &&
|
|
703
|
+
ruleApplies('raw-html-layout', relPath) &&
|
|
390
704
|
RAW_HTML_TAG.test(line) &&
|
|
391
705
|
INLINE_STYLE.test(line) &&
|
|
392
706
|
LAYOUT_SURFACE_PROP.test(line)
|
|
@@ -402,13 +716,14 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
402
716
|
}
|
|
403
717
|
|
|
404
718
|
// inline-display — pattern + gating from GUARD_RULES.
|
|
405
|
-
if (GUARD_RULES['inline-display'].enabled!(cfg)) {
|
|
719
|
+
if (GUARD_RULES['inline-display'].enabled!(cfg) && ruleApplies('inline-display', relPath)) {
|
|
406
720
|
for (const m of line.matchAll(GUARD_RULES['inline-display'].pattern as RegExp)) {
|
|
407
721
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'inline-display' })
|
|
408
722
|
}
|
|
409
723
|
}
|
|
410
724
|
|
|
411
|
-
// raw-visx-axis — pattern + gating + path applicability
|
|
725
|
+
// raw-visx-axis — pattern + gating + path applicability (chart-file scope AND CSS gate,
|
|
726
|
+
// composed on the registry's own appliesTo) from GUARD_RULES.
|
|
412
727
|
if (
|
|
413
728
|
GUARD_RULES['raw-visx-axis'].enabled!(cfg) &&
|
|
414
729
|
GUARD_RULES['raw-visx-axis'].appliesTo!(relPath)
|
|
@@ -419,7 +734,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
419
734
|
}
|
|
420
735
|
|
|
421
736
|
// raw-motion-value: 2 separate regex checks, one kind — gated via GUARD_RULES entry.
|
|
422
|
-
if (GUARD_RULES['raw-motion-value'].enabled!(cfg)) {
|
|
737
|
+
if (GUARD_RULES['raw-motion-value'].enabled!(cfg) && ruleApplies('raw-motion-value', relPath)) {
|
|
423
738
|
for (const m of line.matchAll(MOTION_TRANSITION_NUMERIC)) {
|
|
424
739
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-motion-value' })
|
|
425
740
|
}
|
|
@@ -429,7 +744,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
429
744
|
}
|
|
430
745
|
|
|
431
746
|
// raw-form-control — pattern + gating from GUARD_RULES.
|
|
432
|
-
if (GUARD_RULES['raw-form-control'].enabled!(cfg)) {
|
|
747
|
+
if (GUARD_RULES['raw-form-control'].enabled!(cfg) && ruleApplies('raw-form-control', relPath)) {
|
|
433
748
|
for (const m of line.matchAll(GUARD_RULES['raw-form-control'].pattern as RegExp)) {
|
|
434
749
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-form-control' })
|
|
435
750
|
}
|
|
@@ -437,11 +752,12 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
437
752
|
}
|
|
438
753
|
|
|
439
754
|
// unframed-chart — full-text tag-scoped scan (not per-line, see RAW_CHART_LEGEND_ARRAY comment).
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
755
|
+
// Scans `codeText` (comment-stripped) so a legend example inside a comment can't match; reports
|
|
756
|
+
// at the line of the `items={[` token itself, honoring the same allow-comment escape as every
|
|
757
|
+
// per-line kind by checking the ORIGINAL reported line directly.
|
|
758
|
+
if (GUARD_RULES['unframed-chart'].enabled!(cfg) && ruleApplies('unframed-chart', relPath)) {
|
|
759
|
+
for (const m of codeText.matchAll(RAW_CHART_LEGEND_ARRAY)) {
|
|
760
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + m[0].length).split('\n').length
|
|
445
761
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
446
762
|
findings.push({ relPath, line: lineNo, token: 'items={[', kind: 'unframed-chart' })
|
|
447
763
|
}
|
|
@@ -449,11 +765,14 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
449
765
|
|
|
450
766
|
// chart-missing-aria-label — full-text tag-scoped scan (same shape as unframed-chart above).
|
|
451
767
|
// A tag is a violation only when its own (possibly multi-line) prop list has no `ariaLabel=`.
|
|
452
|
-
if (
|
|
453
|
-
|
|
768
|
+
if (
|
|
769
|
+
GUARD_RULES['chart-missing-aria-label'].enabled!(cfg) &&
|
|
770
|
+
ruleApplies('chart-missing-aria-label', relPath)
|
|
771
|
+
) {
|
|
772
|
+
for (const m of codeText.matchAll(CHART_ENTRY_POINT_TAG)) {
|
|
454
773
|
const tagText = m[0]
|
|
455
774
|
if (HAS_ARIA_LABEL_PROP.test(tagText)) continue
|
|
456
|
-
const lineNo =
|
|
775
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + tagText.length).split('\n').length
|
|
457
776
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
458
777
|
findings.push({
|
|
459
778
|
relPath,
|
|
@@ -467,11 +786,11 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
467
786
|
// card-with-border — full-text tag-scoped scan (same shape as the two above). Reports at the line
|
|
468
787
|
// of the `withBorder` token itself (not the end of the tag) so a multi-line-formatted Card points
|
|
469
788
|
// the fix at the prop to delete.
|
|
470
|
-
if (GUARD_RULES['card-with-border'].enabled!(cfg)) {
|
|
471
|
-
for (const m of
|
|
789
|
+
if (GUARD_RULES['card-with-border'].enabled!(cfg) && ruleApplies('card-with-border', relPath)) {
|
|
790
|
+
for (const m of codeText.matchAll(CARD_SURFACE_TAG)) {
|
|
472
791
|
const withBorder = WITH_BORDER_PROP.exec(m[0])
|
|
473
792
|
if (withBorder === null) continue
|
|
474
|
-
const lineNo =
|
|
793
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + withBorder.index).split('\n').length
|
|
475
794
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
476
795
|
findings.push({ relPath, line: lineNo, token: 'withBorder', kind: 'card-with-border' })
|
|
477
796
|
}
|
|
@@ -481,30 +800,33 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
481
800
|
// form-control's own inline `style={{ fontSize: N }}`, (b) a Mantine `styles={{ input: { fontSize:
|
|
482
801
|
// N } }}` per-part style. Either shape is now DEAD CODE against the `!important` floor in
|
|
483
802
|
// styles.css — see the guard's doc comment for exactly which shapes this covers.
|
|
484
|
-
if (GUARD_RULES['sub-16-input-font'].enabled!(cfg)) {
|
|
485
|
-
for (const m of
|
|
803
|
+
if (GUARD_RULES['sub-16-input-font'].enabled!(cfg) && ruleApplies('sub-16-input-font', relPath)) {
|
|
804
|
+
for (const m of codeText.matchAll(RAW_FORM_CONTROL_TAG)) {
|
|
486
805
|
const tagText = m[0]
|
|
487
806
|
if (!INLINE_STYLE.test(tagText)) continue
|
|
488
807
|
const fontSizeMatch = [...tagText.matchAll(SUB_16_FONT_SIZE)][0]
|
|
489
808
|
if (fontSizeMatch === undefined) continue
|
|
490
809
|
const value = Number.parseFloat(fontSizeMatch[1] ?? '')
|
|
491
810
|
if (!Number.isFinite(value) || value >= 16) continue
|
|
492
|
-
const lineNo =
|
|
811
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + tagText.length).split('\n').length
|
|
493
812
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
494
813
|
findings.push({ relPath, line: lineNo, token: fontSizeMatch[0], kind: 'sub-16-input-font' })
|
|
495
814
|
}
|
|
496
815
|
|
|
497
|
-
for (const m of
|
|
816
|
+
for (const m of codeText.matchAll(STYLES_INPUT_PART)) {
|
|
498
817
|
const inputBody = m[1] ?? ''
|
|
499
818
|
const fontSizeMatch = [...inputBody.matchAll(SUB_16_FONT_SIZE)][0]
|
|
500
819
|
if (fontSizeMatch === undefined) continue
|
|
501
820
|
const value = Number.parseFloat(fontSizeMatch[1] ?? '')
|
|
502
821
|
if (!Number.isFinite(value) || value >= 16) continue
|
|
503
|
-
const lineNo =
|
|
822
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + m[0].length).split('\n').length
|
|
504
823
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
505
824
|
findings.push({ relPath, line: lineNo, token: fontSizeMatch[0], kind: 'sub-16-input-font' })
|
|
506
825
|
}
|
|
507
826
|
}
|
|
508
827
|
|
|
509
|
-
|
|
828
|
+
// Per-rule, per-path exemption post-filter (§exemptRules) — applied once here so it uniformly
|
|
829
|
+
// covers every kind regardless of whether it was emitted via the GUARD_RULES registry loop above
|
|
830
|
+
// or one of the inline-handled kinds (raw-surface, raw-html-layout, sub-16-input-font, …).
|
|
831
|
+
return findings.filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules))
|
|
510
832
|
}
|