facebook / stylex

StyleX is the styling system for ambitious user interfaces.
https://stylexjs.com
MIT License
8.34k stars 307 forks source link

Add new lint rule for margin/padding shorthands #614

Closed mellyeliu closed 3 months ago

mellyeliu commented 3 months ago

Context

This PR introduces a new lint rule for the handling of margin and padding shorthands in stylex.

Legacy Property Mapping: Legacy margin and padding properties like marginStart and paddingEnd are now automatically mapped to their logical property counterparts (marginInlineStart, marginInlineEnd, etc.)

Shorthand Expansion: The handling of CSS shorthands for margin and padding (e.g., margin: 0 0 0 0) will be autodetected and fixable. Shorthands are now automatically expanded into separate properties (e.g., marginInlineStart, marginInlineEnd, etc.).

Testing

Added tests to cover a number of different cases, including:

mellyeliu commented 3 months ago

Other shorthands are out of scope for this specific change, but can be explored in a follow up!

github-actions[bot] commented 3 months ago

compressed-size: runtime library

Size change: 0.00 kB Total size: 2.52 kB

View unchanged | Filename: gzip (minify) | kB size | kB change | % change | | :--- | :--- | :--- | :--- | | `./packages/stylex/lib/stylex.js` | **1.04** (3.22) | **0.00** (0.00) | **0.0%** (0.0%) | | `./packages/stylex/lib/StyleXSheet.js` | **1.48** (3.75) | **0.00** (0.00) | **0.0%** (0.0%) |
github-actions[bot] commented 3 months ago

compressed-size: e2e bundles

Size change: 0.00 kB Total size: 1128.74 kB

View unchanged | Filename: gzip (minify) | kB size | kB change | % change | | :--- | :--- | :--- | :--- | | `./apps/rollup-example/.build/bundle.js` | **1005.32** (10185.35) | **0.00** (0.00) | **0.0%** (0.0%) | | `./apps/rollup-example/.build/stylex.css` | **123.42** (774.34) | **0.00** (0.00) | **0.0%** (0.0%) |
mellyeliu commented 3 months ago

Updated to include the following:

  1. Proper support for expanding marginBlock, marginInline, paddingBlock, paddingInline
  2. A config option to specify whether to preserve !important tags in the fix

For the next iteration we can (1) expand this rule to include handling for other shorthands and (2) provide more specific handling for shorthands with two values (margin -> marginBlock. marginInline)