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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unit tests for checkSource — the pure (text, relPath, cfg) → Finding[] core.
|
|
3
3
|
*
|
|
4
|
-
* Covers all
|
|
4
|
+
* Covers all 19 guard kinds. Co-located with the guard, excluded from tsc
|
|
5
5
|
* (tsconfig exclude: src/**\/*.test.ts), run via `bun test`.
|
|
6
6
|
*
|
|
7
7
|
* The walker/reporter half is covered by the integration test in
|
|
@@ -82,8 +82,8 @@ describe('raw-color-fn', () => {
|
|
|
82
82
|
expect(kinds(f)).not.toContain('raw-color-fn')
|
|
83
83
|
})
|
|
84
84
|
|
|
85
|
-
it('does NOT flag a
|
|
86
|
-
const f = find(
|
|
85
|
+
it('does NOT flag rgba() mentioned inside a real block comment', () => {
|
|
86
|
+
const f = find('/*\n * use rgba() for opacity\n */')
|
|
87
87
|
expect(kinds(f)).not.toContain('raw-color-fn')
|
|
88
88
|
})
|
|
89
89
|
})
|
|
@@ -233,6 +233,32 @@ describe('raw-surface', () => {
|
|
|
233
233
|
expect(kinds(f)).not.toContain('raw-surface')
|
|
234
234
|
})
|
|
235
235
|
|
|
236
|
+
it('does NOT flag a ${…}-composed border (token-driven, e.g. VX.divider)', () => {
|
|
237
|
+
const f = find('const s = { borderLeft: `2px solid ${VX.divider}` }')
|
|
238
|
+
expect(kinds(f)).not.toContain('raw-surface')
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
it('does NOT flag a ${…}-composed boxShadow (VX.shadowCard + a token ring)', () => {
|
|
242
|
+
const f = find(
|
|
243
|
+
'const s = { boxShadow: `${VX.shadowCard}, 0 0 0 1px ${alpha(VX.status.bad, 0.25)}` }',
|
|
244
|
+
)
|
|
245
|
+
expect(kinds(f)).not.toContain('raw-surface')
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('does NOT flag a border reset keyword (none/transparent)', () => {
|
|
249
|
+
expect(kinds(find(`<button style={{ border: 'none' }} />`))).not.toContain('raw-surface')
|
|
250
|
+
expect(kinds(find(`<div style={{ border: 'transparent' }} />`))).not.toContain('raw-surface')
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('STILL flags a genuinely raw ${…}-free literal border/shadow', () => {
|
|
254
|
+
// A template literal escapes only because its color is separately caught by raw-hex/raw-color-fn;
|
|
255
|
+
// a plain quoted literal has no such backstop, so it must still fire.
|
|
256
|
+
expect(kinds(find(`<div style={{ border: '2px solid red' }} />`))).toContain('raw-surface')
|
|
257
|
+
expect(kinds(find(`<div style={{ boxShadow: '0 2px 4px rgba(0,0,0,.1)' }} />`))).toContain(
|
|
258
|
+
'raw-surface',
|
|
259
|
+
)
|
|
260
|
+
})
|
|
261
|
+
|
|
236
262
|
it('does NOT flag when rawSurface is false', () => {
|
|
237
263
|
const f = checkSource(`<div style={{ borderRadius: 8 }} />`, PATH, {
|
|
238
264
|
...DEFAULT_GUARD_CONFIG,
|
|
@@ -771,6 +797,85 @@ describe('sub-16-input-font', () => {
|
|
|
771
797
|
})
|
|
772
798
|
})
|
|
773
799
|
|
|
800
|
+
// ── 19. raw-font-family ──────────────────────────────────────────────────────
|
|
801
|
+
|
|
802
|
+
describe('raw-font-family', () => {
|
|
803
|
+
it('flags a quoted fontFamily object property', () => {
|
|
804
|
+
const f = find(`const s = { fontFamily: 'Inter, sans-serif' }`)
|
|
805
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
806
|
+
})
|
|
807
|
+
|
|
808
|
+
it('flags a quoted fontFamily JSX prop', () => {
|
|
809
|
+
const f = find(`<Text style={{ fontFamily: "Arial" }}>hi</Text>`)
|
|
810
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
811
|
+
})
|
|
812
|
+
|
|
813
|
+
it('flags a bare kebab-case font-family CSS declaration', () => {
|
|
814
|
+
const f = find(`font-family: Inter;`)
|
|
815
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
816
|
+
})
|
|
817
|
+
|
|
818
|
+
it('does NOT flag a fontFamily bound to a var(--basalt-font-…) reference', () => {
|
|
819
|
+
const f = find(`fontFamily: 'var(--basalt-font-sans, ui-sans-serif, system-ui, sans-serif)',`)
|
|
820
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
821
|
+
})
|
|
822
|
+
|
|
823
|
+
it('does NOT flag a kebab-case font-family bound to var(…)', () => {
|
|
824
|
+
const f = find(`font-family: var(--basalt-font-mono);`)
|
|
825
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
826
|
+
})
|
|
827
|
+
|
|
828
|
+
it('does NOT flag an unquoted fontFamily identifier reference (a token ref, not a literal)', () => {
|
|
829
|
+
const f = find(`fontFamily: LABEL_FONT_FAMILY,`)
|
|
830
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
831
|
+
})
|
|
832
|
+
|
|
833
|
+
it('does NOT flag a theme-allow line', () => {
|
|
834
|
+
const f = find(`fontFamily: 'Inter, sans-serif', // theme-allow: legacy widget`)
|
|
835
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
836
|
+
})
|
|
837
|
+
|
|
838
|
+
it('flags a quoted kebab-case font-family CSS value (the (a) bypass)', () => {
|
|
839
|
+
const f = find(`font-family: 'Inter', sans-serif;`)
|
|
840
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
841
|
+
})
|
|
842
|
+
|
|
843
|
+
it('flags a fontFamily bound to a var(...) reference OUTSIDE the two allowed prefixes (the (b) bypass)', () => {
|
|
844
|
+
const f = find(`fontFamily: 'var(--some-other-var)'`)
|
|
845
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
it('flags a kebab-case font-family bound to a var(...) reference outside the allowed prefixes', () => {
|
|
849
|
+
const f = find(`font-family: var(--some-other-var);`)
|
|
850
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
851
|
+
})
|
|
852
|
+
|
|
853
|
+
it('does NOT flag a kebab-case font-family bound to var(--mantine-font-family-…)', () => {
|
|
854
|
+
const f = find(`fontFamily: 'var(--mantine-font-family-monospace)',`)
|
|
855
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
856
|
+
})
|
|
857
|
+
|
|
858
|
+
it('does NOT flag the CSS-wide keyword inherit (camelCase, quoted)', () => {
|
|
859
|
+
const f = find(`fontFamily: 'inherit'`)
|
|
860
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
861
|
+
})
|
|
862
|
+
|
|
863
|
+
it('does NOT flag the CSS-wide keyword initial (kebab-case, bare)', () => {
|
|
864
|
+
const f = find(`font-family: initial;`)
|
|
865
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
it('does NOT flag the CSS-wide keyword unset', () => {
|
|
869
|
+
const f = find(`font-family: unset;`)
|
|
870
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
871
|
+
})
|
|
872
|
+
|
|
873
|
+
it('does NOT flag the CSS-wide keyword revert', () => {
|
|
874
|
+
const f = find(`font-family: revert;`)
|
|
875
|
+
expect(kinds(f)).not.toContain('raw-font-family')
|
|
876
|
+
})
|
|
877
|
+
})
|
|
878
|
+
|
|
774
879
|
// ── theme-allow skip ─────────────────────────────────────────────────────────
|
|
775
880
|
|
|
776
881
|
describe('theme-allow skip', () => {
|
|
@@ -802,8 +907,8 @@ describe('pure-comment skip', () => {
|
|
|
802
907
|
expect(kinds(f)).not.toContain('raw-hex')
|
|
803
908
|
})
|
|
804
909
|
|
|
805
|
-
it('skips a
|
|
806
|
-
const f = find(
|
|
910
|
+
it('skips a JSDoc body line that is genuinely inside a block comment', () => {
|
|
911
|
+
const f = find('/**\n * Use rgba() for opacity, not raw hex\n */')
|
|
807
912
|
expect(kinds(f)).not.toContain('raw-color-fn')
|
|
808
913
|
})
|
|
809
914
|
|
|
@@ -819,6 +924,155 @@ describe('pure-comment skip', () => {
|
|
|
819
924
|
})
|
|
820
925
|
})
|
|
821
926
|
|
|
927
|
+
// ── stripComments pre-pass: real block/line-comment awareness ───────────────────
|
|
928
|
+
//
|
|
929
|
+
// checkSource used to decide "is this a comment?" per line, from that line's OWN leading prefix
|
|
930
|
+
// (`//` / `*` / `/*`). A block-comment CONTINUATION line that didn't happen to start with `*` (the
|
|
931
|
+
// common "wrapped prose" style, e.g. styles.css) slipped straight through as code — a real
|
|
932
|
+
// false-positive, not a hypothetical one (see the 3 real sites this fixed, asserted in
|
|
933
|
+
// index.test.ts / reproduced below). These cases prove the replacement — an actual comment-
|
|
934
|
+
// stripping pre-pass — neither under- nor over-strips.
|
|
935
|
+
|
|
936
|
+
describe('stripComments pre-pass', () => {
|
|
937
|
+
it('does NOT flag a hex on a block-comment CONTINUATION line with no leading *', () => {
|
|
938
|
+
// This is exactly the styles.css shape: a /* ... */ block whose middle lines are wrapped
|
|
939
|
+
// prose, not `* `-prefixed. The old per-line prefix heuristic missed this entirely.
|
|
940
|
+
const text = ['/* line one', ' #e5e5e5 in the middle, no leading star', 'line three */'].join(
|
|
941
|
+
'\n',
|
|
942
|
+
)
|
|
943
|
+
const f = find(text)
|
|
944
|
+
expect(kinds(f)).not.toContain('raw-hex')
|
|
945
|
+
})
|
|
946
|
+
|
|
947
|
+
it('flags a real hex that follows a same-line /* */ comment', () => {
|
|
948
|
+
const f = find(`/* note */ const c = '#ff0000'`)
|
|
949
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
950
|
+
})
|
|
951
|
+
|
|
952
|
+
it('flags a hex inside a single-quoted string with a trailing // comment', () => {
|
|
953
|
+
const f = find(`const c = '#ff0000' // trailing note`)
|
|
954
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
955
|
+
expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
|
|
956
|
+
})
|
|
957
|
+
|
|
958
|
+
it('does not mangle a URL hash-fragment inside a quoted string via // handling', () => {
|
|
959
|
+
// The `//` in `https://` sits INSIDE a single-quoted string, so it must not be treated as a
|
|
960
|
+
// line-comment opener. The guard's raw-hex regex has no URL awareness (never did — that's
|
|
961
|
+
// unrelated to this fix), so it still matches the `#aabbcc` fragment literally: the real-code
|
|
962
|
+
// semantics here are "1 finding", proving the string content survived the strip untouched
|
|
963
|
+
// rather than being blanked out by an over-eager `//` rule.
|
|
964
|
+
const f = find(`const u = 'https://example.com/#aabbcc'`)
|
|
965
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
966
|
+
})
|
|
967
|
+
|
|
968
|
+
it('preserves the exact original line number across a preceding multi-line block comment', () => {
|
|
969
|
+
const text = ['/*', 'line2', 'line3', 'line4', 'end */', '', "const c = '#ff0000'"].join('\n')
|
|
970
|
+
const f = find(text)
|
|
971
|
+
const hit = f.find((x) => x.kind === 'raw-hex')
|
|
972
|
+
expect(hit?.line).toBe(7)
|
|
973
|
+
})
|
|
974
|
+
|
|
975
|
+
it('still honors the theme-allow escape on a code line', () => {
|
|
976
|
+
const f = find(`const c = '#ff0000' // theme-allow: legacy`)
|
|
977
|
+
expect(kinds(f)).not.toContain('raw-hex')
|
|
978
|
+
})
|
|
979
|
+
|
|
980
|
+
it('does not crash on an unterminated block comment at EOF, and strips everything after it', () => {
|
|
981
|
+
const text = `const before = '#ff0000'\n/* unterminated\nconst c = '#00ff00'`
|
|
982
|
+
const f = find(text)
|
|
983
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
984
|
+
expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
|
|
985
|
+
})
|
|
986
|
+
|
|
987
|
+
it('still finds a hex inside a backtick template literal containing ${}', () => {
|
|
988
|
+
const f = find('const s = `value ${x} is #ff0000`')
|
|
989
|
+
expect(kinds(f)).toContain('raw-hex')
|
|
990
|
+
})
|
|
991
|
+
|
|
992
|
+
it('CSS-shaped input: flags only the real declaration, not the comment mention', () => {
|
|
993
|
+
const text = '/* comment with #e5e5e5 */\n.a { color: #ff0000; }'
|
|
994
|
+
const f = find(text)
|
|
995
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
996
|
+
expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
|
|
997
|
+
})
|
|
998
|
+
|
|
999
|
+
// ── regex-literal disambiguation (BUG 1: a `/*`- or `//`-shaped sequence INSIDE a regex body
|
|
1000
|
+
// must never be misread as opening a comment — the char-class case ran away to EOF and silently
|
|
1001
|
+
// deleted guard coverage for the rest of the file) ──────────────────────────────────────────────
|
|
1002
|
+
|
|
1003
|
+
it('does not treat a `/*` inside a regex character class as a block-comment opener (BUG 1 repro)', () => {
|
|
1004
|
+
const text = "const RE = /[/*]/\nconst c = '#ff0000'"
|
|
1005
|
+
const f = find(text)
|
|
1006
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1007
|
+
})
|
|
1008
|
+
|
|
1009
|
+
it('does not treat two `/` inside a regex character class as a line-comment opener', () => {
|
|
1010
|
+
const text = "const RE = /[//]/\nconst c = '#ff0000'"
|
|
1011
|
+
const f = find(text)
|
|
1012
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
it('treats a `/` between identifiers as division, not a regex open', () => {
|
|
1016
|
+
const text = "const a = x / y\nconst c = '#ff0000'"
|
|
1017
|
+
const f = find(text)
|
|
1018
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1019
|
+
})
|
|
1020
|
+
|
|
1021
|
+
it('treats a `/` as division and still finds a REAL // comment later on the same line', () => {
|
|
1022
|
+
const text = "const a = x / y // #aabbcc\nconst c = '#ff0000'"
|
|
1023
|
+
const f = find(text)
|
|
1024
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1025
|
+
})
|
|
1026
|
+
|
|
1027
|
+
it('consumes a regex literal with an escaped slash without closing early', () => {
|
|
1028
|
+
const text = "const RE = /a\\/b/\nconst c = '#ff0000'"
|
|
1029
|
+
const f = find(text)
|
|
1030
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1031
|
+
})
|
|
1032
|
+
|
|
1033
|
+
it('still recognizes a real block comment right after a regex literal (regex handling did not break comment handling)', () => {
|
|
1034
|
+
const text = 'const RE = /abc/\n/* #ff0000 */'
|
|
1035
|
+
const f = find(text)
|
|
1036
|
+
expect(kinds(f)).not.toContain('raw-hex')
|
|
1037
|
+
})
|
|
1038
|
+
|
|
1039
|
+
// ── CSS vs TS syntax split (BUG 2: an unquoted `//` in CSS, e.g. inside `url(https://…)`,
|
|
1040
|
+
// is real CSS text, not a comment opener — CSS has no `//` comment syntax at all) ───────────────
|
|
1041
|
+
|
|
1042
|
+
it('does not treat an unquoted "//" inside a CSS url() as a comment opener (BUG 2 repro)', () => {
|
|
1043
|
+
const f = checkSource(
|
|
1044
|
+
'.a { background: url(https://x.com/a.png); color: #ff0000; }',
|
|
1045
|
+
'src/styles.css',
|
|
1046
|
+
DEFAULT_GUARD_CONFIG,
|
|
1047
|
+
)
|
|
1048
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1049
|
+
})
|
|
1050
|
+
|
|
1051
|
+
it('still strips a real /* */ block comment in a .css file alongside an unquoted url()', () => {
|
|
1052
|
+
const f = checkSource(
|
|
1053
|
+
'.a { background: url(https://x.com/a.png); /* #aabbcc */ color: #ff0000; }',
|
|
1054
|
+
'src/styles.css',
|
|
1055
|
+
DEFAULT_GUARD_CONFIG,
|
|
1056
|
+
)
|
|
1057
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1058
|
+
expect(f.find((x) => x.kind === 'raw-hex')?.token).toBe('#ff0000')
|
|
1059
|
+
})
|
|
1060
|
+
|
|
1061
|
+
it('resolves a .module.css path to CSS syntax too (suffix match, not a naive split)', () => {
|
|
1062
|
+
const f = checkSource(
|
|
1063
|
+
'.a { background: url(https://x.com/a.png); color: #ff0000; }',
|
|
1064
|
+
'src/Card.module.css',
|
|
1065
|
+
DEFAULT_GUARD_CONFIG,
|
|
1066
|
+
)
|
|
1067
|
+
expect(f.filter((x) => x.kind === 'raw-hex')).toHaveLength(1)
|
|
1068
|
+
})
|
|
1069
|
+
|
|
1070
|
+
it('a .ts file still strips a real // line comment (the CSS/TS syntax split did not disable TS)', () => {
|
|
1071
|
+
const f = checkSource('// #ff0000\nconst ok = 1', 'src/x.ts', DEFAULT_GUARD_CONFIG)
|
|
1072
|
+
expect(kinds(f)).not.toContain('raw-hex')
|
|
1073
|
+
})
|
|
1074
|
+
})
|
|
1075
|
+
|
|
822
1076
|
// ── isChartFile gates raw-visx-axis ──────────────────────────────────────────
|
|
823
1077
|
|
|
824
1078
|
describe('isChartFile path gate', () => {
|
|
@@ -832,3 +1086,160 @@ describe('isChartFile path gate', () => {
|
|
|
832
1086
|
expect(kinds(f)).not.toContain('raw-visx-axis')
|
|
833
1087
|
})
|
|
834
1088
|
})
|
|
1089
|
+
|
|
1090
|
+
// ── CSS applicability — the CLI walker now scans .css, so checkSource's per-kind gating over
|
|
1091
|
+
// CSS-shaped input matters for real: color-meaningful kinds must still fire, JSX/tag-shaped kinds
|
|
1092
|
+
// must not false-positive on genuine CSS syntax ──────────────────────────────────────────────────
|
|
1093
|
+
|
|
1094
|
+
describe('CSS applicability', () => {
|
|
1095
|
+
it('flags a raw hex in a real CSS declaration (proves .css is genuinely scanned)', () => {
|
|
1096
|
+
const f = checkSource(
|
|
1097
|
+
'.input {\n color: #ff0000;\n}\n',
|
|
1098
|
+
'src/Card.module.css',
|
|
1099
|
+
DEFAULT_GUARD_CONFIG,
|
|
1100
|
+
)
|
|
1101
|
+
expect(kinds(f)).toContain('raw-hex')
|
|
1102
|
+
})
|
|
1103
|
+
|
|
1104
|
+
it('does NOT false-positive inline-display/raw-html-layout/raw-surface on genuine CSS shapes', () => {
|
|
1105
|
+
const f = checkSource(
|
|
1106
|
+
'.foo {\n display: flex;\n padding: 8px;\n border-radius: 8px;\n}\n',
|
|
1107
|
+
'src/Card.module.css',
|
|
1108
|
+
DEFAULT_GUARD_CONFIG,
|
|
1109
|
+
)
|
|
1110
|
+
expect(kinds(f)).not.toContain('inline-display')
|
|
1111
|
+
expect(kinds(f)).not.toContain('raw-html-layout')
|
|
1112
|
+
expect(kinds(f)).not.toContain('raw-surface')
|
|
1113
|
+
})
|
|
1114
|
+
|
|
1115
|
+
it('still flags off-system-surface-var on a raw Mantine ramp step inside CSS', () => {
|
|
1116
|
+
const f = checkSource(
|
|
1117
|
+
'.foo {\n background: var(--mantine-color-gray-3);\n}\n',
|
|
1118
|
+
'src/Card.module.css',
|
|
1119
|
+
DEFAULT_GUARD_CONFIG,
|
|
1120
|
+
)
|
|
1121
|
+
expect(kinds(f)).toContain('off-system-surface-var')
|
|
1122
|
+
})
|
|
1123
|
+
|
|
1124
|
+
it('still flags raw-font-family on a kebab-case CSS font-family declaration', () => {
|
|
1125
|
+
const f = checkSource(
|
|
1126
|
+
'.foo {\n font-family: system-ui;\n}\n',
|
|
1127
|
+
'src/Card.module.css',
|
|
1128
|
+
DEFAULT_GUARD_CONFIG,
|
|
1129
|
+
)
|
|
1130
|
+
expect(kinds(f)).toContain('raw-font-family')
|
|
1131
|
+
})
|
|
1132
|
+
|
|
1133
|
+
it('still flags inline-spacing on a genuine CSS padding/margin/gap declaration (the pattern is CSS-shaped, not JSX-only, despite the name)', () => {
|
|
1134
|
+
const f = checkSource(
|
|
1135
|
+
'.foo {\n padding: 8px;\n margin: 4px;\n gap: 8px;\n}\n',
|
|
1136
|
+
'src/Card.module.css',
|
|
1137
|
+
DEFAULT_GUARD_CONFIG,
|
|
1138
|
+
)
|
|
1139
|
+
expect(kinds(f).filter((k) => k === 'inline-spacing')).toHaveLength(3)
|
|
1140
|
+
})
|
|
1141
|
+
|
|
1142
|
+
it('does NOT false-positive raw-form-control on a CSS element selector (input, select, textarea)', () => {
|
|
1143
|
+
const f = checkSource(
|
|
1144
|
+
'input, select, textarea {\n color: red;\n}\n',
|
|
1145
|
+
'src/Card.module.css',
|
|
1146
|
+
DEFAULT_GUARD_CONFIG,
|
|
1147
|
+
)
|
|
1148
|
+
expect(kinds(f)).not.toContain('raw-form-control')
|
|
1149
|
+
})
|
|
1150
|
+
|
|
1151
|
+
it('does NOT false-positive raw-spacing/raw-radius/off-identity-accent/raw-motion-value on CSS property syntax', () => {
|
|
1152
|
+
const f = checkSource(
|
|
1153
|
+
'.foo {\n border-radius: 6px;\n transition: all 0.3s ease;\n color: teal;\n gap: 16px;\n}\n',
|
|
1154
|
+
'src/Card.module.css',
|
|
1155
|
+
DEFAULT_GUARD_CONFIG,
|
|
1156
|
+
)
|
|
1157
|
+
expect(kinds(f)).not.toContain('raw-radius')
|
|
1158
|
+
expect(kinds(f)).not.toContain('raw-motion-value')
|
|
1159
|
+
expect(kinds(f)).not.toContain('off-identity-accent')
|
|
1160
|
+
})
|
|
1161
|
+
|
|
1162
|
+
it('does NOT false-positive card-with-border/unframed-chart/chart-missing-aria-label/raw-visx-axis on CSS class selectors that echo JSX names', () => {
|
|
1163
|
+
const f = checkSource(
|
|
1164
|
+
'.Card {\n border: 1px solid red;\n}\n.ChartLegend {\n display: flex;\n}\n.AxisLeft {\n color: red;\n}\n',
|
|
1165
|
+
'src/charts/kinds/Card.module.css',
|
|
1166
|
+
DEFAULT_GUARD_CONFIG,
|
|
1167
|
+
)
|
|
1168
|
+
expect(kinds(f)).not.toContain('card-with-border')
|
|
1169
|
+
expect(kinds(f)).not.toContain('unframed-chart')
|
|
1170
|
+
expect(kinds(f)).not.toContain('chart-missing-aria-label')
|
|
1171
|
+
expect(kinds(f)).not.toContain('raw-visx-axis')
|
|
1172
|
+
})
|
|
1173
|
+
|
|
1174
|
+
it('does NOT false-positive localstorage-theme on CSS text', () => {
|
|
1175
|
+
const f = checkSource(
|
|
1176
|
+
"/* localStorage.getItem('theme') example */\n.foo { color: red; }\n",
|
|
1177
|
+
'src/Card.module.css',
|
|
1178
|
+
DEFAULT_GUARD_CONFIG,
|
|
1179
|
+
)
|
|
1180
|
+
expect(kinds(f)).not.toContain('localstorage-theme')
|
|
1181
|
+
})
|
|
1182
|
+
})
|
|
1183
|
+
|
|
1184
|
+
// ── exemptRules — per-rule, per-path guard exemptions ────────────────────────
|
|
1185
|
+
|
|
1186
|
+
describe('exemptRules', () => {
|
|
1187
|
+
const TEXT = `<div style={{ display: 'flex' }} />`
|
|
1188
|
+
|
|
1189
|
+
it('drops a finding of an exempted kind at a matching path', () => {
|
|
1190
|
+
const f = checkSource(TEXT, 'src/agent/x.tsx', {
|
|
1191
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1192
|
+
exemptRules: { 'inline-display': ['agent'] },
|
|
1193
|
+
})
|
|
1194
|
+
expect(kinds(f)).not.toContain('inline-display')
|
|
1195
|
+
})
|
|
1196
|
+
|
|
1197
|
+
it('still fires at a non-matching path (path-scoped, not global)', () => {
|
|
1198
|
+
const f = checkSource(TEXT, 'src/dashboard/x.tsx', {
|
|
1199
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1200
|
+
exemptRules: { 'inline-display': ['agent'] },
|
|
1201
|
+
})
|
|
1202
|
+
expect(kinds(f)).toContain('inline-display')
|
|
1203
|
+
})
|
|
1204
|
+
|
|
1205
|
+
it('a trailing-slash pattern matches identically to the bare segment', () => {
|
|
1206
|
+
const f = checkSource(TEXT, 'src/agent/x.tsx', {
|
|
1207
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1208
|
+
exemptRules: { 'inline-display': ['agent/'] },
|
|
1209
|
+
})
|
|
1210
|
+
expect(kinds(f)).not.toContain('inline-display')
|
|
1211
|
+
})
|
|
1212
|
+
|
|
1213
|
+
it('does NOT match a substring of a segment (not a whole-segment match)', () => {
|
|
1214
|
+
const f = checkSource(TEXT, 'src/agent/x.tsx', {
|
|
1215
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1216
|
+
exemptRules: { 'inline-display': ['age'] },
|
|
1217
|
+
})
|
|
1218
|
+
expect(kinds(f)).toContain('inline-display')
|
|
1219
|
+
})
|
|
1220
|
+
|
|
1221
|
+
it('does NOT suppress a different kind on the same line/path', () => {
|
|
1222
|
+
const f = checkSource(`const c = '#ff0000'; ${TEXT}`, 'src/agent/x.tsx', {
|
|
1223
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1224
|
+
exemptRules: { 'inline-display': ['agent'] },
|
|
1225
|
+
})
|
|
1226
|
+
expect(kinds(f)).not.toContain('inline-display')
|
|
1227
|
+
expect(kinds(f)).toContain('raw-hex')
|
|
1228
|
+
})
|
|
1229
|
+
|
|
1230
|
+
it('exempts raw-html-layout, an INLINE-handled kind — proves the post-filter covers those too', () => {
|
|
1231
|
+
const f = checkSource(TEXT, 'src/agent/x.tsx', {
|
|
1232
|
+
...DEFAULT_GUARD_CONFIG,
|
|
1233
|
+
exemptRules: { 'raw-html-layout': ['agent'] },
|
|
1234
|
+
})
|
|
1235
|
+
expect(kinds(f)).not.toContain('raw-html-layout')
|
|
1236
|
+
// inline-display isn't exempted here, so it still fires from the same text.
|
|
1237
|
+
expect(kinds(f)).toContain('inline-display')
|
|
1238
|
+
})
|
|
1239
|
+
|
|
1240
|
+
it('default (no exemptRules) behavior is unchanged', () => {
|
|
1241
|
+
const f = find(TEXT, 'src/agent/x.tsx')
|
|
1242
|
+
expect(kinds(f)).toContain('inline-display')
|
|
1243
|
+
expect(kinds(f)).toContain('raw-html-layout')
|
|
1244
|
+
})
|
|
1245
|
+
})
|