basalt-ui 1.1.1 → 1.3.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 +46 -0
- package/README.md +64 -8
- package/agent/rules/basalt-app.md +126 -0
- package/agent/rules/basalt-content.md +3 -1
- package/agent/rules/basalt-tokens.md +14 -5
- package/agent/skills/basalt-app/SKILL.md +28 -7
- 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 +29 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +80 -9
- 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 +266 -38
- 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 +22 -11
- package/dist/surfaces.d.ts +21 -11
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +10 -3
- 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 +143 -7
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +322 -48
- 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/tokens.css +248 -0
- 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 +14 -4
- package/package.json +41 -10
- 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 +129 -6
- package/src/cli/tokens-css.test.ts +90 -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 +483 -15
- package/src/guard/index.ts +426 -47
- 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 +22 -11
- package/src/surfaces.ts +24 -10
- 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 +534 -48
- 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
|
|
@@ -48,6 +68,47 @@ const LAYOUT_SURFACE_PROP =
|
|
|
48
68
|
const INLINE_SPACING =
|
|
49
69
|
/\b(?:padding(?:Top|Bottom|Left|Right)?|margin(?:Top|Bottom|Left|Right)?|gap|rowGap|columnGap)\s*:\s*(?!var\()['"]?-?(?!0\b)\d/g
|
|
50
70
|
|
|
71
|
+
/**
|
|
72
|
+
* The sub-scale micro-spacing ceiling, in px — the largest literal `inline-spacing` tolerates in a
|
|
73
|
+
* CSS file. Below the smallest spacing scale stop (`SPACE_SCALE.xs`), which is the whole point: a
|
|
74
|
+
* value under that stop has NO token to prefer, so flagging it asks for something that does not
|
|
75
|
+
* exist. Pinned against the real scale by `check-source.test.ts` so a density retune of the ladder
|
|
76
|
+
* cannot leave this stranded above it.
|
|
77
|
+
*
|
|
78
|
+
* Deliberately CSS-ONLY. In TSX the same shape means something different: `pl={4}` is a Mantine
|
|
79
|
+
* PROP and never matches this pattern in the first place, while `style={{ paddingLeft: 4 }}` does —
|
|
80
|
+
* and there the finding is right, because the prop form exists and should have been used. In CSS
|
|
81
|
+
* there is no prop form, and the emitted `--vx-space-*` set is basalt's own component one-offs
|
|
82
|
+
* (`--vx-space-toc-sub-indent`), not a consumer surface. Without this escape a consumer's CSS
|
|
83
|
+
* module had no legal way to write a 4px cluster gap: no token to reach for, `theme-allow` on every
|
|
84
|
+
* line (which `basalt-tokens.md` explicitly warns against), or `exemptRules` — which matches whole
|
|
85
|
+
* path segments and so cannot express `*.module.css`.
|
|
86
|
+
*/
|
|
87
|
+
const MICRO_SPACING_CEILING_PX = 10
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Is this CSS declaration entirely sub-scale? True when every literal in the value is a bare px (or
|
|
91
|
+
* unitless) number at or below {@link MICRO_SPACING_CEILING_PX}. `var(...)` components are dropped
|
|
92
|
+
* before the check — a value that mixes a token with a micro literal (`padding: 4px var(--x)`) is
|
|
93
|
+
* already tokenized where it counts.
|
|
94
|
+
*
|
|
95
|
+
* Multi-value shorthands are judged as a whole: `padding: 4px 8px` passes, `padding: 4px 16px` does
|
|
96
|
+
* not — the 16 has a scale stop and should use it. Any other unit (`rem`, `em`, `%`) fails, because
|
|
97
|
+
* the doctrine is stated in px and a rem value is a different axis, not a micro-spacing one.
|
|
98
|
+
*/
|
|
99
|
+
function isSubScaleCssSpacing(line: string, matchIndex: number): boolean {
|
|
100
|
+
const colon = line.indexOf(':', matchIndex)
|
|
101
|
+
if (colon === -1) return false
|
|
102
|
+
const rest = line.slice(colon + 1)
|
|
103
|
+
const end = rest.search(/[;}]/)
|
|
104
|
+
const value = (end === -1 ? rest : rest.slice(0, end)).replace(/var\([^)]*\)/g, ' ').trim()
|
|
105
|
+
if (value === '') return true
|
|
106
|
+
return value.split(/\s+/).every((part) => {
|
|
107
|
+
const literal = /^-?(\d+(?:\.\d+)?)(?:px)?$/.exec(part)
|
|
108
|
+
return literal !== null && Number(literal[1]) <= MICRO_SPACING_CEILING_PX
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
51
112
|
// display:flex/grid/inline-flex/inline-grid in an inline style.
|
|
52
113
|
const INLINE_DISPLAY = /\bdisplay\s*:\s*['"](?:inline-)?(?:flex|grid)['"]/g
|
|
53
114
|
|
|
@@ -110,7 +171,21 @@ const SUB_16_FONT_SIZE = /font-?[Ss]ize\s*:\s*['"]?(-?\d+(?:\.\d+)?)(?:px)?['"]?
|
|
|
110
171
|
// ── Defaults ─────────────────────────────────────────────────────────────────────────────────────
|
|
111
172
|
|
|
112
173
|
/** Default spacing steps (px) flagged as raw spacing props. */
|
|
113
|
-
|
|
174
|
+
/**
|
|
175
|
+
* The `xs…xl` spacing scale, as raw numbers — what `raw-spacing` flags, because a prop value that
|
|
176
|
+
* EQUALS a step should be written as the token (`p="md"`, not `p={18}`).
|
|
177
|
+
*
|
|
178
|
+
* Mirrors `SPACE_SCALE` at level 0. Kept as a literal rather than imported from `tokens/palette` so
|
|
179
|
+
* the headless guard core stays a single file: it runs on every Write/Edit through the PreToolUse
|
|
180
|
+
* hook, and pulling the palette in would drag `derive.ts` + `hct.ts`'s color math along with it.
|
|
181
|
+
* `check-source.test.ts` asserts the two agree, so the copy cannot drift — which it did: this list
|
|
182
|
+
* still read `[10, 12, 16, 20, 32]` after the level-0 retune, telling consumers to replace `p={16}`
|
|
183
|
+
* with a `p="md"` that resolves to 18.
|
|
184
|
+
*
|
|
185
|
+
* A consumer whose theme moves the scale (`createBasaltTheme({ density })`, or its own overrides)
|
|
186
|
+
* sets `basalt.spacingSteps` in package.json rather than living with this default.
|
|
187
|
+
*/
|
|
188
|
+
const DEFAULT_SPACING_STEPS: readonly number[] = [11, 13, 18, 20, 26]
|
|
114
189
|
/** Default off-identity Mantine accent families. */
|
|
115
190
|
const DEFAULT_FORBIDDEN_ACCENTS: readonly string[] = ['teal', 'violet', 'grape', 'indigo', 'pink']
|
|
116
191
|
|
|
@@ -132,6 +207,7 @@ export const DEFAULT_GUARD_CONFIG: GuardConfig = {
|
|
|
132
207
|
rawFormControl: true,
|
|
133
208
|
sub16InputFont: true,
|
|
134
209
|
allowComment: 'theme-allow',
|
|
210
|
+
exemptRules: {},
|
|
135
211
|
}
|
|
136
212
|
|
|
137
213
|
// ── Path predicate ────────────────────────────────────────────────────────────────────────────────
|
|
@@ -141,14 +217,247 @@ function isChartFile(relPath: string): boolean {
|
|
|
141
217
|
}
|
|
142
218
|
|
|
143
219
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
220
|
+
* Whether `kind` is exempted at `relPath` via `cfg.exemptRules` — the config-driven, per-rule
|
|
221
|
+
* counterpart to `isChartFile`'s hardcoded path scoping. A pattern matches when `relPath` split on
|
|
222
|
+
* `/` includes it as a WHOLE segment (a trailing `/` is stripped first, so `'agent'` and `'agent/'`
|
|
223
|
+
* are equivalent); a substring match against one longer segment (e.g. `'age'` against `agent`)
|
|
224
|
+
* never counts.
|
|
225
|
+
*/
|
|
226
|
+
function isRuleExempt(
|
|
227
|
+
kind: GuardKind,
|
|
228
|
+
relPath: string,
|
|
229
|
+
exemptRules: GuardConfig['exemptRules'],
|
|
230
|
+
): boolean {
|
|
231
|
+
const patterns = exemptRules?.[kind]
|
|
232
|
+
if (patterns === undefined || patterns.length === 0) return false
|
|
233
|
+
const segments = relPath.split('/')
|
|
234
|
+
return patterns.some((pattern) => segments.includes(pattern.replace(/\/$/, '')))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The allow-comment skip the full-text tag-scoped scans re-apply on their own resolved report
|
|
239
|
+
* line: a line carrying the allow-comment is never a violation. Pure-comment lines need no
|
|
240
|
+
* special case here anymore — they are handled upstream by `stripComments` (matches simply can't
|
|
241
|
+
* land on blanked-out comment text), so this only ever runs against the ORIGINAL (unstripped)
|
|
242
|
+
* line, since the allow-comment annotation itself lives inside a comment.
|
|
147
243
|
*/
|
|
148
244
|
function isSkippedLine(line: string, cfg: GuardConfig): boolean {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
245
|
+
return line.includes(cfg.allowComment)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The 2 comment/regex dialects the stripper understands, resolved from the file's own extension. */
|
|
249
|
+
type GuardSyntax = 'ts' | 'css'
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* CSS (including `.module.css`) has no `//` line-comment syntax at all — an unquoted `//`, e.g.
|
|
253
|
+
* inside `url(https://…)`, is real CSS text, never a comment opener. Match on the `.css` suffix
|
|
254
|
+
* (not a naive `split('.')`) so `foo.module.css` resolves the same as `foo.css`.
|
|
255
|
+
*/
|
|
256
|
+
function guardSyntaxFor(relPath: string): GuardSyntax {
|
|
257
|
+
return relPath.endsWith('.css') ? 'css' : 'ts'
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// A `/` opens a regex literal (not division) when the previous significant token is one of these
|
|
261
|
+
// punctuation marks, or one of the REGEX_PRECEDING_KEYWORDS below, or nothing has been scanned yet
|
|
262
|
+
// (start of input) — the standard JS lexer disambiguation. `ts`-syntax only; CSS has no regexes.
|
|
263
|
+
const REGEX_PRECEDING_PUNCT = new Set([
|
|
264
|
+
'=',
|
|
265
|
+
'(',
|
|
266
|
+
',',
|
|
267
|
+
'[',
|
|
268
|
+
':',
|
|
269
|
+
'!',
|
|
270
|
+
'&',
|
|
271
|
+
'|',
|
|
272
|
+
'?',
|
|
273
|
+
'{',
|
|
274
|
+
'}',
|
|
275
|
+
';',
|
|
276
|
+
'+',
|
|
277
|
+
'-',
|
|
278
|
+
'*',
|
|
279
|
+
'%',
|
|
280
|
+
'~',
|
|
281
|
+
'^',
|
|
282
|
+
'<',
|
|
283
|
+
])
|
|
284
|
+
const REGEX_PRECEDING_KEYWORDS = new Set([
|
|
285
|
+
'return',
|
|
286
|
+
'typeof',
|
|
287
|
+
'case',
|
|
288
|
+
'in',
|
|
289
|
+
'of',
|
|
290
|
+
'delete',
|
|
291
|
+
'void',
|
|
292
|
+
'throw',
|
|
293
|
+
'do',
|
|
294
|
+
'else',
|
|
295
|
+
])
|
|
296
|
+
const WORD_CHAR = /[A-Za-z0-9_$]/
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Strip comments out of source text, leaving real comment-awareness in place of the old per-line
|
|
300
|
+
* prefix heuristic (which only caught a comment when ITS OWN line happened to start with `//` /
|
|
301
|
+
* `*` / `/*` — a block-comment continuation line that didn't start with `*` slipped straight
|
|
302
|
+
* through as if it were code).
|
|
303
|
+
*
|
|
304
|
+
* Stripped characters are replaced 1:1 with a space (newlines are preserved verbatim), so the
|
|
305
|
+
* output is the SAME LENGTH as the input and every remaining token keeps its exact original line
|
|
306
|
+
* number and character offset — callers can keep using `text.slice(0, i).split('\n').length` for
|
|
307
|
+
* line numbers exactly as before.
|
|
308
|
+
*
|
|
309
|
+
* Deliberately does NOT touch string literals (`'`, `"`, backtick, backslash-escaped): a raw hex
|
|
310
|
+
* or a `//` inside a string is real source text, not a comment, and must still be scanned as-is
|
|
311
|
+
* (e.g. a URL like `'https://x.com/#abc'` must not have its `//` treated as a line comment).
|
|
312
|
+
*
|
|
313
|
+
* `syntax === 'css'` disables `//` line-comment handling entirely (CSS only has `/* *\/`) — an
|
|
314
|
+
* unquoted `url(https://…)` must never have its rest-of-line blanked (that was the BUG 2 false
|
|
315
|
+
* negative: a real violation on the same line silently disappearing behind a bogus "comment").
|
|
316
|
+
*
|
|
317
|
+
* `syntax === 'ts'` additionally recognizes regex literals (`/…/flags`) via
|
|
318
|
+
* `REGEX_PRECEDING_PUNCT` / `REGEX_PRECEDING_KEYWORDS` and consumes them VERBATIM — a `/*` or `//`
|
|
319
|
+
* shaped sequence inside a regex body (e.g. a character class `/[/*]/`) is real regex source, not
|
|
320
|
+
* a comment opener, and must not open a block comment that then runs away to EOF eating every
|
|
321
|
+
* subsequent line unrecoverably (that was the BUG 1 false negative — total loss of guard coverage
|
|
322
|
+
* for the rest of the file). The heuristic is inherently imperfect (full disambiguation needs a
|
|
323
|
+
* real parser), so it is DELIBERATELY biased toward treating an ambiguous `/` as division, i.e.
|
|
324
|
+
* NOT a regex, i.e. NOT specially protected: an under-strip here just leaves a `/` as an ordinary
|
|
325
|
+
* character (worst case a spurious finding a human can `theme-allow`), whereas an over-eager
|
|
326
|
+
* regex-open would swallow real code as "protected regex content" and could hide a genuine
|
|
327
|
+
* violation — the failure mode BUG 1 already showed is unacceptable.
|
|
328
|
+
*/
|
|
329
|
+
function stripComments(text: string, syntax: GuardSyntax): string {
|
|
330
|
+
const out: string[] = Array.from<string>({ length: text.length })
|
|
331
|
+
let inLineComment = false
|
|
332
|
+
let inBlockComment = false
|
|
333
|
+
let stringQuote: string | null = null
|
|
334
|
+
let currentWord = ''
|
|
335
|
+
let lastUnitType: 'word' | 'punct' | 'none' = 'none'
|
|
336
|
+
let lastWord = ''
|
|
337
|
+
let lastPunct = ''
|
|
338
|
+
let i = 0
|
|
339
|
+
|
|
340
|
+
function flushWord(): void {
|
|
341
|
+
if (currentWord === '') return
|
|
342
|
+
lastUnitType = 'word'
|
|
343
|
+
lastWord = currentWord
|
|
344
|
+
currentWord = ''
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function canPrecedeRegex(): boolean {
|
|
348
|
+
if (lastUnitType === 'none') return true
|
|
349
|
+
if (lastUnitType === 'word') return REGEX_PRECEDING_KEYWORDS.has(lastWord)
|
|
350
|
+
return REGEX_PRECEDING_PUNCT.has(lastPunct)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
while (i < text.length) {
|
|
354
|
+
const ch = text[i] ?? ''
|
|
355
|
+
|
|
356
|
+
if (inLineComment) {
|
|
357
|
+
out[i] = ch === '\n' ? '\n' : ' '
|
|
358
|
+
if (ch === '\n') inLineComment = false
|
|
359
|
+
i++
|
|
360
|
+
continue
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (inBlockComment) {
|
|
364
|
+
if (ch === '*' && text[i + 1] === '/') {
|
|
365
|
+
out[i] = ' '
|
|
366
|
+
out[i + 1] = ' '
|
|
367
|
+
i += 2
|
|
368
|
+
inBlockComment = false
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
371
|
+
out[i] = ch === '\n' ? '\n' : ' '
|
|
372
|
+
i++
|
|
373
|
+
continue
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (stringQuote !== null) {
|
|
377
|
+
out[i] = ch
|
|
378
|
+
if (ch === '\\' && i + 1 < text.length) {
|
|
379
|
+
out[i + 1] = text[i + 1] ?? ''
|
|
380
|
+
i += 2
|
|
381
|
+
continue
|
|
382
|
+
}
|
|
383
|
+
if (ch === stringQuote) stringQuote = null
|
|
384
|
+
i++
|
|
385
|
+
continue
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (WORD_CHAR.test(ch)) {
|
|
389
|
+
currentWord += ch
|
|
390
|
+
out[i] = ch
|
|
391
|
+
i++
|
|
392
|
+
continue
|
|
393
|
+
}
|
|
394
|
+
flushWord()
|
|
395
|
+
|
|
396
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
397
|
+
stringQuote = ch
|
|
398
|
+
out[i] = ch
|
|
399
|
+
lastUnitType = 'punct'
|
|
400
|
+
lastPunct = ch
|
|
401
|
+
i++
|
|
402
|
+
continue
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (ch === '/' && text[i + 1] === '*') {
|
|
406
|
+
inBlockComment = true
|
|
407
|
+
out[i] = ' '
|
|
408
|
+
i++
|
|
409
|
+
continue
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (syntax === 'ts' && ch === '/' && text[i + 1] === '/') {
|
|
413
|
+
inLineComment = true
|
|
414
|
+
out[i] = ' '
|
|
415
|
+
i++
|
|
416
|
+
continue
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (syntax === 'ts' && ch === '/' && canPrecedeRegex()) {
|
|
420
|
+
// Consume the regex literal VERBATIM: backslash escapes and `[...]` character classes never
|
|
421
|
+
// close it early. A raw newline before the closing `/` means this was never a valid regex
|
|
422
|
+
// (JS disallows a literal line terminator inside one) — bail out of regex mode right there;
|
|
423
|
+
// every character up to the newline was already copied through unchanged either way, so
|
|
424
|
+
// bailing loses nothing.
|
|
425
|
+
out[i] = ch
|
|
426
|
+
let j = i + 1
|
|
427
|
+
let inClass = false
|
|
428
|
+
while (j < text.length) {
|
|
429
|
+
const rc = text[j] ?? ''
|
|
430
|
+
if (rc === '\n') break
|
|
431
|
+
out[j] = rc
|
|
432
|
+
if (rc === '\\' && j + 1 < text.length) {
|
|
433
|
+
out[j + 1] = text[j + 1] ?? ''
|
|
434
|
+
j += 2
|
|
435
|
+
continue
|
|
436
|
+
}
|
|
437
|
+
if (rc === '[') inClass = true
|
|
438
|
+
else if (rc === ']') inClass = false
|
|
439
|
+
else if (rc === '/' && !inClass) {
|
|
440
|
+
j++
|
|
441
|
+
break
|
|
442
|
+
}
|
|
443
|
+
j++
|
|
444
|
+
}
|
|
445
|
+
i = j
|
|
446
|
+
lastUnitType = 'punct'
|
|
447
|
+
lastPunct = '/'
|
|
448
|
+
continue
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Plain `/` (division, or any bare `/` in CSS syntax) — or any other punctuation/whitespace.
|
|
452
|
+
out[i] = ch
|
|
453
|
+
if (!/\s/.test(ch)) {
|
|
454
|
+
lastUnitType = 'punct'
|
|
455
|
+
lastPunct = ch
|
|
456
|
+
}
|
|
457
|
+
i++
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return out.join('')
|
|
152
461
|
}
|
|
153
462
|
|
|
154
463
|
// ── GUARD_RULES registry ─────────────────────────────────────────────────────────────────────────
|
|
@@ -166,7 +475,7 @@ type GuardRule = {
|
|
|
166
475
|
}
|
|
167
476
|
|
|
168
477
|
/**
|
|
169
|
-
* The closed registry of all
|
|
478
|
+
* The closed registry of all 19 guard kinds. The triad test asserts
|
|
170
479
|
* `surface.guardKinds ⊆ keyof GUARD_RULES` at runtime.
|
|
171
480
|
*
|
|
172
481
|
* raw-surface, raw-html-layout, and sub-16-input-font are handled inline in checkSource
|
|
@@ -194,8 +503,16 @@ export const GUARD_RULES = {
|
|
|
194
503
|
'localstorage-theme': {
|
|
195
504
|
kind: 'localstorage-theme',
|
|
196
505
|
pattern: LOCALSTORAGE_THEME,
|
|
506
|
+
// JS-call-shaped (`localStorage.getItem('theme')`) — never appears in CSS text.
|
|
507
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
197
508
|
message: 'Theme must resolve via the Mantine color scheme + --vx-* vars.',
|
|
198
509
|
},
|
|
510
|
+
'raw-font-family': {
|
|
511
|
+
kind: 'raw-font-family',
|
|
512
|
+
pattern: RAW_FONT_FAMILY,
|
|
513
|
+
message:
|
|
514
|
+
'Route the font stack through createBasaltTheme(overrides, { fonts }) / the shipped --basalt-font-sans|head|mono vars instead of a hardcoded fontFamily literal.',
|
|
515
|
+
},
|
|
199
516
|
'off-identity-accent': {
|
|
200
517
|
kind: 'off-identity-accent',
|
|
201
518
|
pattern: (cfg: GuardConfig) =>
|
|
@@ -203,6 +520,10 @@ export const GUARD_RULES = {
|
|
|
203
520
|
`\\b(?:color|c|bg|backgroundColor)\\s*=\\s*\\{?\\s*['"](${cfg.forbiddenAccents.join('|')})['"]`,
|
|
204
521
|
'g',
|
|
205
522
|
),
|
|
523
|
+
// JSX-prop-shaped (`color={"teal"}`) — CSS declares `color: teal;` with a bare keyword and
|
|
524
|
+
// `:`, which the pattern's `=` anchor can never match; gated off explicitly so a future regex
|
|
525
|
+
// tweak can't silently start false-positiving on consumer CSS.
|
|
526
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
206
527
|
message: 'For an off-identity accent use blue/gray or a status hue (red/green/orange/yellow).',
|
|
207
528
|
},
|
|
208
529
|
'raw-spacing': {
|
|
@@ -212,12 +533,17 @@ export const GUARD_RULES = {
|
|
|
212
533
|
`\\b(?:p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap)=\\{(?:${cfg.spacingSteps.join('|')})\\}`,
|
|
213
534
|
'g',
|
|
214
535
|
),
|
|
536
|
+
// JSX-prop-shaped (`p={16}`) — CSS has no `=`/`{}` prop syntax; gated off explicitly (see
|
|
537
|
+
// off-identity-accent above for why "never matches today" still gets an explicit gate).
|
|
538
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
215
539
|
message: 'Use the Mantine spacing prop/token (p/m/gap with xs..xl).',
|
|
216
540
|
},
|
|
217
541
|
'raw-radius': {
|
|
218
542
|
kind: 'raw-radius',
|
|
219
543
|
pattern: RADIUS_PROP_RE,
|
|
220
544
|
enabled: (cfg: GuardConfig) => cfg.rawRadius,
|
|
545
|
+
// JSX-prop-shaped (`radius={6}`) — CSS declares `border-radius: 6px;`, never `radius=`.
|
|
546
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
221
547
|
message: 'Use the radius token (radius="md") instead of a numeric literal.',
|
|
222
548
|
},
|
|
223
549
|
'raw-surface': {
|
|
@@ -231,6 +557,8 @@ export const GUARD_RULES = {
|
|
|
231
557
|
kind: 'card-with-border',
|
|
232
558
|
pattern: CARD_SURFACE_TAG, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
233
559
|
enabled: (cfg: GuardConfig) => cfg.cardWithBorder,
|
|
560
|
+
// JSX-tag-shaped (`<Card withBorder>`) — never appears in CSS text.
|
|
561
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
234
562
|
message:
|
|
235
563
|
'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
564
|
},
|
|
@@ -245,6 +573,8 @@ export const GUARD_RULES = {
|
|
|
245
573
|
kind: 'raw-html-layout',
|
|
246
574
|
pattern: RAW_HTML_TAG, // handled inline (3-condition conjunction); entry keeps registry complete
|
|
247
575
|
enabled: (cfg: GuardConfig) => cfg.rawHtmlLayout,
|
|
576
|
+
// JSX-tag-shaped (`<div style={{...}}>`) — never appears in CSS text.
|
|
577
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
248
578
|
message:
|
|
249
579
|
'Raw HTML element with inline layout/surface styling — use a Mantine layout primitive (Box/Flex/Grid/Stack/Group).',
|
|
250
580
|
},
|
|
@@ -258,13 +588,18 @@ export const GUARD_RULES = {
|
|
|
258
588
|
kind: 'inline-display',
|
|
259
589
|
pattern: INLINE_DISPLAY,
|
|
260
590
|
enabled: (cfg: GuardConfig) => cfg.inlineDisplay,
|
|
591
|
+
// JSX-object-shaped (`display: 'flex'`, quoted value) — CSS never quotes a keyword value
|
|
592
|
+
// (`display: flex;` is bare), so the pattern's quote anchor can never match real CSS.
|
|
593
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
261
594
|
message: 'Use <Flex>/<Grid>/<Group> instead of an inline display:flex/grid.',
|
|
262
595
|
},
|
|
263
596
|
'raw-visx-axis': {
|
|
264
597
|
kind: 'raw-visx-axis',
|
|
265
598
|
pattern: RAW_VISX_AXIS,
|
|
266
599
|
enabled: (cfg: GuardConfig) => cfg.rawVisxAxis,
|
|
267
|
-
|
|
600
|
+
// Compose the existing chart-file scope with the CSS gate — a chart-file CSS module (none
|
|
601
|
+
// exist today, but the boundary should hold regardless) still can't carry a JSX axis tag.
|
|
602
|
+
appliesTo: (relPath) => isChartFile(relPath) && !relPath.endsWith('.css'),
|
|
268
603
|
message:
|
|
269
604
|
'Raw <AxisLeft>/<AxisBottom>/<AxisRight> in a chart file — use AxisLeftNumeric / AxisBottomDate / AxisRightNumeric.',
|
|
270
605
|
},
|
|
@@ -272,6 +607,9 @@ export const GUARD_RULES = {
|
|
|
272
607
|
kind: 'raw-motion-value',
|
|
273
608
|
pattern: MOTION_TRANSITION_NUMERIC, // handled inline (2-regex kind); entry keeps registry complete
|
|
274
609
|
enabled: (cfg: GuardConfig) => cfg.rawMotionValue,
|
|
610
|
+
// JSX-prop-shaped (`transition={{ duration: … }}`) — CSS's `transition:` property has no `=`
|
|
611
|
+
// or `{{`.
|
|
612
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
275
613
|
message:
|
|
276
614
|
'Route animation timing through MOTION_DURATION / MOTION_SPRING / MOTION_EASE_STANDARD (basalt-ui motion tokens) instead of a hardcoded duration/spring/ease.',
|
|
277
615
|
},
|
|
@@ -279,6 +617,8 @@ export const GUARD_RULES = {
|
|
|
279
617
|
kind: 'unframed-chart',
|
|
280
618
|
pattern: RAW_CHART_LEGEND_ARRAY, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
281
619
|
enabled: (cfg: GuardConfig) => cfg.unframedChart,
|
|
620
|
+
// JSX-tag-shaped (`<ChartLegend items={[…]}>`) — never appears in CSS text.
|
|
621
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
282
622
|
message:
|
|
283
623
|
'Hand-rolled ChartLegend built from an inline array literal — pass a derived legend (deriveLegend(series)), or compose ChartFrame, which derives it for you.',
|
|
284
624
|
},
|
|
@@ -286,6 +626,8 @@ export const GUARD_RULES = {
|
|
|
286
626
|
kind: 'chart-missing-aria-label',
|
|
287
627
|
pattern: CHART_ENTRY_POINT_TAG, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
288
628
|
enabled: (cfg: GuardConfig) => cfg.chartMissingAriaLabel,
|
|
629
|
+
// JSX-tag-shaped (`<MultiLine …>`) — never appears in CSS text.
|
|
630
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
289
631
|
message:
|
|
290
632
|
'Chart has no accessible text alternative — pass ariaLabel="…" so screen readers get more than an unlabeled graphic.',
|
|
291
633
|
},
|
|
@@ -293,6 +635,9 @@ export const GUARD_RULES = {
|
|
|
293
635
|
kind: 'raw-form-control',
|
|
294
636
|
pattern: RAW_FORM_CONTROL,
|
|
295
637
|
enabled: (cfg: GuardConfig) => cfg.rawFormControl,
|
|
638
|
+
// JSX-tag-shaped (`<input …>`) — a CSS element selector (`input, select {…}`) has no leading
|
|
639
|
+
// `<`, so the pattern's anchor can never match real CSS.
|
|
640
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
296
641
|
message:
|
|
297
642
|
'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
643
|
},
|
|
@@ -300,11 +645,20 @@ export const GUARD_RULES = {
|
|
|
300
645
|
kind: 'sub-16-input-font',
|
|
301
646
|
pattern: SUB_16_FONT_SIZE, // handled inline (full-text tag-scoped scan); entry keeps registry complete
|
|
302
647
|
enabled: (cfg: GuardConfig) => cfg.sub16InputFont,
|
|
648
|
+
// Only ever fires nested inside a raw-form-control JSX tag or a `styles={{ input: {…} }}`
|
|
649
|
+
// object literal — both JSX-shaped, neither appears in CSS text.
|
|
650
|
+
appliesTo: (relPath) => !relPath.endsWith('.css'),
|
|
303
651
|
message:
|
|
304
652
|
'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
653
|
},
|
|
306
654
|
} as const satisfies Record<GuardKind, GuardRule>
|
|
307
655
|
|
|
656
|
+
/** Whether `kind`'s rule fires for `relPath` — `appliesTo` is opt-in; absent means always applies. */
|
|
657
|
+
function ruleApplies(kind: GuardKind, relPath: string): boolean {
|
|
658
|
+
const appliesTo = (GUARD_RULES[kind] as GuardRule).appliesTo
|
|
659
|
+
return appliesTo === undefined || appliesTo(relPath)
|
|
660
|
+
}
|
|
661
|
+
|
|
308
662
|
// ── checkSource ───────────────────────────────────────────────────────────────────────────────────
|
|
309
663
|
|
|
310
664
|
/**
|
|
@@ -331,14 +685,20 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
331
685
|
(GUARD_RULES['raw-radius'].pattern as RegExp).flags,
|
|
332
686
|
)
|
|
333
687
|
|
|
688
|
+
// Comment-stripped text drives every match below; `lines` (the ORIGINAL, unstripped split) is
|
|
689
|
+
// kept only to resolve the allow-comment escape, since that annotation lives inside a comment
|
|
690
|
+
// the stripped text has already blanked out. Same length / same newline positions as `text`, so
|
|
691
|
+
// line numbers computed off either one agree.
|
|
334
692
|
const lines = text.split('\n')
|
|
693
|
+
const syntax = guardSyntaxFor(relPath)
|
|
694
|
+
const codeText = stripComments(text, syntax)
|
|
695
|
+
const codeLines = codeText.split('\n')
|
|
696
|
+
|
|
335
697
|
for (let i = 0; i < lines.length; i++) {
|
|
336
|
-
const line =
|
|
698
|
+
const line = codeLines[i] ?? ''
|
|
337
699
|
|
|
338
|
-
// Skip lines with the allow-comment
|
|
339
|
-
if (
|
|
340
|
-
const trimmed = line.trimStart()
|
|
341
|
-
if (trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')) continue
|
|
700
|
+
// Skip lines with the allow-comment (checked against the ORIGINAL line text).
|
|
701
|
+
if ((lines[i] ?? '').includes(cfg.allowComment)) continue
|
|
342
702
|
|
|
343
703
|
// Always-on kinds (raw-hex, raw-color-fn, localstorage-theme) — patterns from GUARD_RULES.
|
|
344
704
|
for (const m of line.matchAll(GUARD_RULES['raw-hex'].pattern as RegExp)) {
|
|
@@ -347,18 +707,27 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
347
707
|
for (const m of line.matchAll(GUARD_RULES['raw-color-fn'].pattern as RegExp)) {
|
|
348
708
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-color-fn' })
|
|
349
709
|
}
|
|
350
|
-
|
|
351
|
-
|
|
710
|
+
if (ruleApplies('localstorage-theme', relPath)) {
|
|
711
|
+
for (const m of line.matchAll(GUARD_RULES['localstorage-theme'].pattern as RegExp)) {
|
|
712
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'localstorage-theme' })
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
for (const m of line.matchAll(GUARD_RULES['raw-font-family'].pattern as RegExp)) {
|
|
716
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-font-family' })
|
|
352
717
|
}
|
|
353
718
|
|
|
354
719
|
// Dynamic-regex kinds — patterns already resolved above.
|
|
355
|
-
|
|
356
|
-
|
|
720
|
+
if (ruleApplies('off-identity-accent', relPath)) {
|
|
721
|
+
for (const m of line.matchAll(forbiddenAccentRe)) {
|
|
722
|
+
findings.push({ relPath, line: i + 1, token: m[1] ?? '', kind: 'off-identity-accent' })
|
|
723
|
+
}
|
|
357
724
|
}
|
|
358
|
-
|
|
359
|
-
|
|
725
|
+
if (ruleApplies('raw-spacing', relPath)) {
|
|
726
|
+
for (const m of line.matchAll(spacingPropRe)) {
|
|
727
|
+
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-spacing' })
|
|
728
|
+
}
|
|
360
729
|
}
|
|
361
|
-
if (GUARD_RULES['raw-radius'].enabled!(cfg)) {
|
|
730
|
+
if (GUARD_RULES['raw-radius'].enabled!(cfg) && ruleApplies('raw-radius', relPath)) {
|
|
362
731
|
for (const m of line.matchAll(radiusPropRe)) {
|
|
363
732
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-radius' })
|
|
364
733
|
}
|
|
@@ -387,6 +756,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
387
756
|
// raw-html-layout: 3-condition conjunction on the same line — gated via GUARD_RULES entry.
|
|
388
757
|
if (
|
|
389
758
|
GUARD_RULES['raw-html-layout'].enabled!(cfg) &&
|
|
759
|
+
ruleApplies('raw-html-layout', relPath) &&
|
|
390
760
|
RAW_HTML_TAG.test(line) &&
|
|
391
761
|
INLINE_STYLE.test(line) &&
|
|
392
762
|
LAYOUT_SURFACE_PROP.test(line)
|
|
@@ -394,21 +764,23 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
394
764
|
findings.push({ relPath, line: i + 1, token: '<raw-html style>', kind: 'raw-html-layout' })
|
|
395
765
|
}
|
|
396
766
|
|
|
397
|
-
// inline-spacing — pattern + gating from GUARD_RULES.
|
|
767
|
+
// inline-spacing — pattern + gating from GUARD_RULES, plus the CSS-only sub-scale escape.
|
|
398
768
|
if (GUARD_RULES['inline-spacing'].enabled!(cfg)) {
|
|
399
769
|
for (const m of line.matchAll(GUARD_RULES['inline-spacing'].pattern as RegExp)) {
|
|
770
|
+
if (syntax === 'css' && isSubScaleCssSpacing(line, m.index)) continue
|
|
400
771
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'inline-spacing' })
|
|
401
772
|
}
|
|
402
773
|
}
|
|
403
774
|
|
|
404
775
|
// inline-display — pattern + gating from GUARD_RULES.
|
|
405
|
-
if (GUARD_RULES['inline-display'].enabled!(cfg)) {
|
|
776
|
+
if (GUARD_RULES['inline-display'].enabled!(cfg) && ruleApplies('inline-display', relPath)) {
|
|
406
777
|
for (const m of line.matchAll(GUARD_RULES['inline-display'].pattern as RegExp)) {
|
|
407
778
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'inline-display' })
|
|
408
779
|
}
|
|
409
780
|
}
|
|
410
781
|
|
|
411
|
-
// raw-visx-axis — pattern + gating + path applicability
|
|
782
|
+
// raw-visx-axis — pattern + gating + path applicability (chart-file scope AND CSS gate,
|
|
783
|
+
// composed on the registry's own appliesTo) from GUARD_RULES.
|
|
412
784
|
if (
|
|
413
785
|
GUARD_RULES['raw-visx-axis'].enabled!(cfg) &&
|
|
414
786
|
GUARD_RULES['raw-visx-axis'].appliesTo!(relPath)
|
|
@@ -419,7 +791,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
419
791
|
}
|
|
420
792
|
|
|
421
793
|
// raw-motion-value: 2 separate regex checks, one kind — gated via GUARD_RULES entry.
|
|
422
|
-
if (GUARD_RULES['raw-motion-value'].enabled!(cfg)) {
|
|
794
|
+
if (GUARD_RULES['raw-motion-value'].enabled!(cfg) && ruleApplies('raw-motion-value', relPath)) {
|
|
423
795
|
for (const m of line.matchAll(MOTION_TRANSITION_NUMERIC)) {
|
|
424
796
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-motion-value' })
|
|
425
797
|
}
|
|
@@ -429,7 +801,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
429
801
|
}
|
|
430
802
|
|
|
431
803
|
// raw-form-control — pattern + gating from GUARD_RULES.
|
|
432
|
-
if (GUARD_RULES['raw-form-control'].enabled!(cfg)) {
|
|
804
|
+
if (GUARD_RULES['raw-form-control'].enabled!(cfg) && ruleApplies('raw-form-control', relPath)) {
|
|
433
805
|
for (const m of line.matchAll(GUARD_RULES['raw-form-control'].pattern as RegExp)) {
|
|
434
806
|
findings.push({ relPath, line: i + 1, token: m[0], kind: 'raw-form-control' })
|
|
435
807
|
}
|
|
@@ -437,11 +809,12 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
437
809
|
}
|
|
438
810
|
|
|
439
811
|
// unframed-chart — full-text tag-scoped scan (not per-line, see RAW_CHART_LEGEND_ARRAY comment).
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
812
|
+
// Scans `codeText` (comment-stripped) so a legend example inside a comment can't match; reports
|
|
813
|
+
// at the line of the `items={[` token itself, honoring the same allow-comment escape as every
|
|
814
|
+
// per-line kind by checking the ORIGINAL reported line directly.
|
|
815
|
+
if (GUARD_RULES['unframed-chart'].enabled!(cfg) && ruleApplies('unframed-chart', relPath)) {
|
|
816
|
+
for (const m of codeText.matchAll(RAW_CHART_LEGEND_ARRAY)) {
|
|
817
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + m[0].length).split('\n').length
|
|
445
818
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
446
819
|
findings.push({ relPath, line: lineNo, token: 'items={[', kind: 'unframed-chart' })
|
|
447
820
|
}
|
|
@@ -449,11 +822,14 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
449
822
|
|
|
450
823
|
// chart-missing-aria-label — full-text tag-scoped scan (same shape as unframed-chart above).
|
|
451
824
|
// A tag is a violation only when its own (possibly multi-line) prop list has no `ariaLabel=`.
|
|
452
|
-
if (
|
|
453
|
-
|
|
825
|
+
if (
|
|
826
|
+
GUARD_RULES['chart-missing-aria-label'].enabled!(cfg) &&
|
|
827
|
+
ruleApplies('chart-missing-aria-label', relPath)
|
|
828
|
+
) {
|
|
829
|
+
for (const m of codeText.matchAll(CHART_ENTRY_POINT_TAG)) {
|
|
454
830
|
const tagText = m[0]
|
|
455
831
|
if (HAS_ARIA_LABEL_PROP.test(tagText)) continue
|
|
456
|
-
const lineNo =
|
|
832
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + tagText.length).split('\n').length
|
|
457
833
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
458
834
|
findings.push({
|
|
459
835
|
relPath,
|
|
@@ -467,11 +843,11 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
467
843
|
// card-with-border — full-text tag-scoped scan (same shape as the two above). Reports at the line
|
|
468
844
|
// of the `withBorder` token itself (not the end of the tag) so a multi-line-formatted Card points
|
|
469
845
|
// the fix at the prop to delete.
|
|
470
|
-
if (GUARD_RULES['card-with-border'].enabled!(cfg)) {
|
|
471
|
-
for (const m of
|
|
846
|
+
if (GUARD_RULES['card-with-border'].enabled!(cfg) && ruleApplies('card-with-border', relPath)) {
|
|
847
|
+
for (const m of codeText.matchAll(CARD_SURFACE_TAG)) {
|
|
472
848
|
const withBorder = WITH_BORDER_PROP.exec(m[0])
|
|
473
849
|
if (withBorder === null) continue
|
|
474
|
-
const lineNo =
|
|
850
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + withBorder.index).split('\n').length
|
|
475
851
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
476
852
|
findings.push({ relPath, line: lineNo, token: 'withBorder', kind: 'card-with-border' })
|
|
477
853
|
}
|
|
@@ -481,30 +857,33 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
|
|
|
481
857
|
// form-control's own inline `style={{ fontSize: N }}`, (b) a Mantine `styles={{ input: { fontSize:
|
|
482
858
|
// N } }}` per-part style. Either shape is now DEAD CODE against the `!important` floor in
|
|
483
859
|
// 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
|
|
860
|
+
if (GUARD_RULES['sub-16-input-font'].enabled!(cfg) && ruleApplies('sub-16-input-font', relPath)) {
|
|
861
|
+
for (const m of codeText.matchAll(RAW_FORM_CONTROL_TAG)) {
|
|
486
862
|
const tagText = m[0]
|
|
487
863
|
if (!INLINE_STYLE.test(tagText)) continue
|
|
488
864
|
const fontSizeMatch = [...tagText.matchAll(SUB_16_FONT_SIZE)][0]
|
|
489
865
|
if (fontSizeMatch === undefined) continue
|
|
490
866
|
const value = Number.parseFloat(fontSizeMatch[1] ?? '')
|
|
491
867
|
if (!Number.isFinite(value) || value >= 16) continue
|
|
492
|
-
const lineNo =
|
|
868
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + tagText.length).split('\n').length
|
|
493
869
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
494
870
|
findings.push({ relPath, line: lineNo, token: fontSizeMatch[0], kind: 'sub-16-input-font' })
|
|
495
871
|
}
|
|
496
872
|
|
|
497
|
-
for (const m of
|
|
873
|
+
for (const m of codeText.matchAll(STYLES_INPUT_PART)) {
|
|
498
874
|
const inputBody = m[1] ?? ''
|
|
499
875
|
const fontSizeMatch = [...inputBody.matchAll(SUB_16_FONT_SIZE)][0]
|
|
500
876
|
if (fontSizeMatch === undefined) continue
|
|
501
877
|
const value = Number.parseFloat(fontSizeMatch[1] ?? '')
|
|
502
878
|
if (!Number.isFinite(value) || value >= 16) continue
|
|
503
|
-
const lineNo =
|
|
879
|
+
const lineNo = codeText.slice(0, (m.index ?? 0) + m[0].length).split('\n').length
|
|
504
880
|
if (isSkippedLine(lines[lineNo - 1] ?? '', cfg)) continue
|
|
505
881
|
findings.push({ relPath, line: lineNo, token: fontSizeMatch[0], kind: 'sub-16-input-font' })
|
|
506
882
|
}
|
|
507
883
|
}
|
|
508
884
|
|
|
509
|
-
|
|
885
|
+
// Per-rule, per-path exemption post-filter (§exemptRules) — applied once here so it uniformly
|
|
886
|
+
// covers every kind regardless of whether it was emitted via the GUARD_RULES registry loop above
|
|
887
|
+
// or one of the inline-handled kinds (raw-surface, raw-html-layout, sub-16-input-font, …).
|
|
888
|
+
return findings.filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules))
|
|
510
889
|
}
|