Skip to content

Add(ESLint): class-recommended rule for axis-collapse suggestions - #428

Closed
0Miles wants to merge 1 commit into
master-co:rcfrom
0Miles:feat/338-eslint-recommended-syntax
Closed

0Miles wants to merge 1 commit into
master-co:rcfrom
0Miles:feat/338-eslint-recommended-syntax

Conversation

@0Miles

@0Miles 0Miles commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Closes #338.

Summary

Adds a 4th rule to `@master/eslint-plugin-css`: warns (with auto-fix) when a set of long-hand utilities can be collapsed to the equivalent shorthand.

Initial recommendation set

Long-hands Shorthand
`mt mr mb ml` `m`
`mt mb` `my`
`ml mr` `mx`
`pt pr pb pl` `p`
`pt pb` `py`
`pl pr` `px`
`top right bottom left` `inset`
`top bottom` `inset-y`
`left right` `inset-x`

Strict matching: same value, same conditional-query suffix (`@sm`, `:hover`), same `!` flag. 4-side recommendation runs before 2-side so a fully-bracketed group is collapsed once. Auto-fix uses a single `replaceTextRange` over the whole span, avoiding ESLint's "overlapped fix" guard.

Wired into the `recommended` config at `warn` severity. Easy to extend — the `RECOMMENDATIONS` table accepts more entries.

Bonus fix in resolve-class-node

Building the auto-fix surfaced a pre-existing bug: the LAST class node of a className attribute had `range[0]` set to the className value's start instead of the individual class's start. Any rule that sorts class nodes by source position would mis-order. Fixed in the same PR; all 14 existing eslint-plugin test files still pass.

Testing

  • 13 RuleTester cases (valid: already-shorthand / different values / different conditions / single longhand; invalid: 2-side, 4-side, 3-side, conditions, important, mixed with non-axis classes)
  • 14/14 plugin test files pass
  • `pnpm lint` + `pnpm type-check` clean

@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

@0Miles is attempting to deploy a commit to the Aoyue Team on Vercel.

A member of the Team first needs to authorize it.

0Miles added a commit to 0Miles/css that referenced this pull request Apr 30, 2026
The validator's existing TODO-marked workaround for math functions
only checked the error fragment (error.css) for min(/max(/clamp(
substrings. Some mismatches surface only a sub-token (e.g.
right: max(0px, 1rem) reports the bare 0px arg), so the suppression
missed valid usages and users saw false positives.

- validate-css.ts: check FULL value text in addition to error.css
- Extended math-fn list to all CSS Values 4 functions: calc, min,
  max, clamp, sin, cos, tan, asin, acos, atan, atan2, exp, log,
  pow, sqrt, hypot, abs, sign, round, mod, rem
- 16 validator test cases (min/max/clamp/calc/oklch/rotate/
  aspect-ratio/contain/container-type valid; truly invalid still
  errors) + 7 eslint-plugin RuleTester cases including right:max(),
  font-size:clamp(calc()), aspect:16/9

Scope: master-co#338 was originally tagged in the same umbrella but it's a
separate feature (recommended-syntax warnings, new lint rules) — see
PR master-co#428.

Closes master-co#405
Closes master-co#323
Closes master-co#331
Adds a 4th rule to @master/eslint-plugin-css: warns (with auto-fix)
when a set of long-hand utilities can be collapsed to the equivalent
shorthand.

Initial recommendation set:
- mt mr mb ml → m
- mt mb → my
- ml mr → mx
- pt pr pb pl → p
- pt pb → py
- pl pr → px
- top right bottom left → inset
- top bottom → inset-y
- left right → inset-x

Strict matching: same value, same conditional-query suffix (@sm,
:hover), same ! flag. 4-side runs before 2-side so a fully-bracketed
group is collapsed once. Auto-fix uses a single replaceTextRange
over the whole span, avoiding ESLint's "overlapped fix" guard.

Wired into the recommended config at warn severity. Easy to extend —
the RECOMMENDATIONS table accepts more entries.

Bonus fix in resolve-class-node: the LAST class node of a className
attribute had range[0] set to the className value's start instead of
the individual class's start; any rule that sorts class nodes by
source position would mis-order. Same PR.

- 13 RuleTester cases covering valid (already-shorthand, different
  values, different conditions) and invalid (4-side, 2-side, 3-side,
  conditions, important, mixed)
- 14 plugin test files still pass; pnpm lint + pnpm type-check clean

Closes master-co#338
@0Miles
0Miles force-pushed the feat/338-eslint-recommended-syntax branch from 59805be to 2ab4279 Compare April 30, 2026 19:05
@0Miles
0Miles requested a review from 1aron April 30, 2026 19:11
@0Miles

0Miles commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Retracting. Implementation is technically sound (13 RuleTester cases pass, auto-fix works, bonus pre-existing range[0] bug fixed in resolve-class-node), but the choice of which 9 RECOMMENDATIONS to ship is a policy call for the maintainer:

  • Should it cover only 4-side collapses (less noisy) vs both 4-side and 2-side?
  • Should it warn or error?
  • Should it include other patterns I didn't add (same-modifier duplicates, group → utility suggestions, bg multi-declaration)?

The framework is ready and easy to extend. Will re-submit after maintainer signs off on the recommendation list. Branch feat/338-eslint-recommended-syntax preserved.

@0Miles 0Miles closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ ESLint: Recommended Syntax Warnings

1 participant