-
Notifications
You must be signed in to change notification settings - Fork 14
fix(ds): sweep composition drift against design.md + ratchet five new metrics #2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3438a18
fix(ds): sweep composition drift against design.md, ratchet five new …
innolope-dev 2f31716
fix(ds-lint): invert drift ratchets to allowlists per review
innolope-dev 4b10822
fix(ds-lint): cover logical spacing families, add rule regression tests
innolope-dev 6ed5343
fix(ds-lint): reject arbitrary spacing values, match weight stacks pe…
innolope-dev af94ffc
fix(ds-lint): scan *ClassName props, expression-valued Icon classes, …
innolope-dev 10f92f0
fix(ds-lint): scan .ts class modules, builder-call variables, bracket…
innolope-dev 36d4fa8
fix(ds-lint): match every font-weight utility on type tokens
innolope-dev 437a1c6
fix(ds-lint): -px suffix, block-axis logical families, custom-propert…
innolope-dev d67a98d
fix(ds-lint): match theme and custom-property font weights
innolope-dev 5bc79fa
fix(ds-lint): typed arbitrary weights, multiline class constants, non…
innolope-dev 712dc66
fix(ds-lint): quoted icon size props, document the heuristic boundary
innolope-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import { | ||
| countOffScaleSpacing, | ||
| countWeightStacks, | ||
| countOffScaleRadius, | ||
| OFF_SCALE_ICON_RE, | ||
| RAW_DURATION_RE, | ||
| } from '../ds-lint-rules.cjs' | ||
|
|
||
| const countMatches = (text: string, re: RegExp) => (text.match(re) ?? []).length | ||
|
|
||
| describe('offScaleSpacing', () => { | ||
| it('flags off-scale steps across every spacing family, logical ps/pe/ms/me included', () => { | ||
| for (const cls of ['p-5', 'px-7', 'py-2.5', 'gap-11', 'p-4.5', 'pr-18', 'ps-5', 'pe-18', 'ms-2.5', 'me-7']) { | ||
| expect(countOffScaleSpacing(`<div className="${cls}" />`)).toBe(1) | ||
| } | ||
| }) | ||
|
|
||
| it('flags negative and variant-prefixed forms', () => { | ||
| expect(countOffScaleSpacing('className="-m-2.5"')).toBe(1) | ||
| expect(countOffScaleSpacing('className="-mt-5"')).toBe(1) | ||
| expect(countOffScaleSpacing('className="md:pr-18"')).toBe(1) | ||
| expect(countOffScaleSpacing('className="first:ps-7"')).toBe(1) | ||
| }) | ||
|
|
||
| it('accepts every documented scale step, negatives and variants included', () => { | ||
| for (const cls of [ | ||
| 'p-0', | ||
| 'p-0.5', | ||
| 'gap-1', | ||
| 'px-2', | ||
| 'py-3', | ||
| 'p-4', | ||
| 'gap-6', | ||
| 'p-8', | ||
| 'mt-10', | ||
| 'pb-12', | ||
| 'ps-4', | ||
| 'me-2', | ||
| '-mt-4', | ||
| 'md:gap-6', | ||
| 'space-y-8', | ||
| 'gap-x-16', | ||
| ]) { | ||
| expect(countOffScaleSpacing(`<div className="${cls}" />`)).toBe(0) | ||
| } | ||
| }) | ||
|
|
||
| it('flags arbitrary spacing values wholesale — the bracket form is always drift', () => { | ||
| for (const cls of ['p-[5px]', 'gap-[20px]', 'p-[13px]', '-m-[3px]', 'md:ps-[10%]']) { | ||
| expect(countOffScaleSpacing(`<div className="${cls}" />`)).toBe(1) | ||
| } | ||
| }) | ||
|
|
||
| it('does not misread longer utilities or words as spacing classes', () => { | ||
| for (const text of [ | ||
| 'className="max-p-5"', | ||
| 'theme-3', | ||
| 'frame-2', | ||
| 'className="w-[13px]"', | ||
| 'className="ms-auto"', | ||
| ]) { | ||
| expect(countOffScaleSpacing(text)).toBe(0) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('fontWeightOnTypeToken (countWeightStacks)', () => { | ||
| it('counts a token and weight split across lines inside one className expression', () => { | ||
| const jsx = [ | ||
| '<span', | ||
| ' className={`text-body-m ${twMerge(', | ||
| " 'font-semibold text-foreground-primary capitalize',", | ||
| ' titleClassName', | ||
| ' )}`}', | ||
| '>', | ||
| ].join('\n') | ||
| expect(countWeightStacks(jsx)).toBe(1) | ||
| }) | ||
|
|
||
| it('counts same-line stacks in plain strings and const class strings', () => { | ||
| expect(countWeightStacks('<p className="text-body-s font-bold" />')).toBe(1) | ||
| expect(countWeightStacks("const style = 'text-body-s font-bold underline'")).toBe(1) | ||
| }) | ||
|
|
||
| it('counts stacks carried through *ClassName props, not just className', () => { | ||
| const jsx = [ | ||
| '<TitleBlock', | ||
| " titleClassName={twMerge('text-body-m',", | ||
| " 'font-semibold')}", | ||
| '/>', | ||
| ].join('\n') | ||
| expect(countWeightStacks(jsx)).toBe(1) | ||
| }) | ||
|
|
||
| it('counts extracted multiline class builders assigned to variables', () => { | ||
| const code = [ | ||
| 'const classes = twMerge(', | ||
| " 'text-body-m',", | ||
| " active && 'font-semibold'", | ||
| ')', | ||
| 'return <p className={classes} />', | ||
| ].join('\n') | ||
| expect(countWeightStacks(code)).toBe(1) | ||
| }) | ||
|
|
||
| it('does not count a token and a weight living in different elements', () => { | ||
| const jsx = [ | ||
| '<p className="text-body-m">a</p>', | ||
| '<p className="font-semibold">b</p>', | ||
| '<p className={twMerge("text-label-l", cls)}>c</p>', | ||
| ].join('\n') | ||
| expect(countWeightStacks(jsx)).toBe(0) | ||
| }) | ||
| }) | ||
|
|
||
| describe('iconOffScale', () => { | ||
| it('flags off-step size, width/height props, and class-sized Icons', () => { | ||
| for (const text of [ | ||
| '<Icon name="info" size={18} />', | ||
| '<Icon name={logo} width={18} height={18} />', | ||
| '<Icon name="swap" width={32} height={32} />', | ||
| 'iconSize={13}', | ||
| '<Icon name="check" className="size-4" />', | ||
| '<Icon name="paste" className="h-3.5 w-3.5" />', | ||
| '<Icon name="chevron-up" className={`h-4 w-4 transition-transform ${open ? "" : "rotate-180"}`} />', | ||
| "<Icon name={icon} className={twMerge('size-6', extra)} />", | ||
| '<Icon name="x" className="size-[18px]" />', | ||
| "<Icon name={icon} className={twMerge('h-[18px] w-[18px]', extra)} />", | ||
| ]) { | ||
| expect(countMatches(text, OFF_SCALE_ICON_RE)).toBeGreaterThan(0) | ||
| } | ||
| }) | ||
|
|
||
| it('accepts the 16/20/24 steps', () => { | ||
| for (const text of [ | ||
| '<Icon name="info" size={16} />', | ||
| '<Icon size={20} />', | ||
| '<Icon size={24} />', | ||
| 'iconSize={20}', | ||
| ]) { | ||
| expect(countMatches(text, OFF_SCALE_ICON_RE)).toBe(0) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('offScaleRadius (countOffScaleRadius)', () => { | ||
| it('flags radii off the scale — named steps, sides, and arbitrary values', () => { | ||
| for (const cls of [ | ||
| 'rounded-md', | ||
| 'rounded-lg', | ||
| 'rounded-t-2xl', | ||
| 'rounded-3xl', | ||
| 'rounded-[1px]', | ||
| 'rounded-[5px]', | ||
| 'rounded-t-[10px]', | ||
| 'rounded-xs', | ||
| ]) { | ||
| expect(countOffScaleRadius(`className="${cls}"`)).toBe(1) | ||
| } | ||
| }) | ||
|
|
||
| it('accepts the scale classes, bare rounded and sides included', () => { | ||
| for (const cls of [ | ||
| 'rounded-sm', | ||
| 'rounded-round', | ||
| 'rounded-full', | ||
| 'rounded-none', | ||
| 'rounded', | ||
| 'rounded-t-sm', | ||
| 'rounded-e-full', | ||
| ]) { | ||
| expect(countOffScaleRadius(`className="${cls}"`)).toBe(0) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('rawDuration', () => { | ||
| it('flags any numeric or arbitrary duration', () => { | ||
| for (const cls of ['duration-100', 'duration-250', 'duration-75', 'duration-[250ms]']) { | ||
| expect(countMatches(`className="${cls}"`, RAW_DURATION_RE)).toBe(1) | ||
| } | ||
| }) | ||
|
|
||
| it('accepts the motion tokens', () => { | ||
| for (const cls of ['duration-instant', 'duration-fast', 'duration-moderate', 'duration-slow']) { | ||
| expect(countMatches(`className="${cls}"`, RAW_DURATION_RE)).toBe(0) | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.