[eslint-plugin] Add flex shorthand expansion to stylex-valid-shorthands#1537
[eslint-plugin] Add flex shorthand expansion to stylex-valid-shorthands#1537
Conversation
Add flex shorthand expansion following the createSpecificTransformer pattern. The rule now reports an error and autofixes when users write `flex: '1 0 auto'` instead of the expanded longhands. Handles all CSS spec cases: - Keywords: auto (1 1 auto), none (0 0 auto), initial (0 1 auto) - Single number: flex-grow with shrink=1, basis=0% - Single basis: grow=1, shrink=1 with the basis value - Two values: grow+shrink or grow+basis - Three values: grow shrink basis - calc(), var(), min-content, max-content, fit-content as basis - !important support
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
workflow: benchmarks/perfComparison of performance test results, measured in operations per second. Larger is better.
|
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
|
I'm not sure I follow the motivation here, the compiler doesn't require them expanded. And the linter didn't flag |
|
I still find this change very restrictive. Can we add a linter config option? |
What changed / motivation ?
Added flex shorthand expansion to
stylex-valid-shorthandsusing the samecreateSpecificTransformerpattern already used forbackground,font,border,grid, andoutline.Changes:
flex: createSpecificTransformer('flex')to shorthand aliases.expandFlexShorthand()insplitShorthands.jsplus helper classifiers for:flex-grow/flex-shrink)auto,content,min-content,max-content,fit-content,calc()/min()/max()/clamp()/fit-content(),var(), unit/percent values)property === 'flex'dispatch insplitSpecificShorthandsbefore generic single-value passthrough so cases likeflex: 1still expand.auto,none,initialgrow shrink,grow basis)grow shrink basis)calc()basis!importantpropagationBehavior:
flex: '1 0 auto'now reports and autofixes to:flexGrow: '1'flexShrink: '0'flexBasis: 'auto'Motivation:
flexshorthand is common in StyleX authoring and migration paths.flexin line with existing shorthand autofix behavior while keeping fixes safe and deterministic.Linked PR/Issues
N/A
Additional Context
Example autofix:
flex: '1 0 auto'flexGrow: '1', flexShrink: '0', flexBasis: 'auto'Tests:
npx jest --watchman=false --coverage=false stylex-valid-shorthands-test.jsPASS(94 passed,0 failed)Screenshots:
Pre-flight checklist
Contribution Guidelines