Skip to content

prefer-padding-components

Fixable

Prefer local padding components when a <uipadding /> element already matches them.

This rule checks empty <uipadding /> elements with exactly these four attributes: PaddingTop, PaddingBottom, PaddingLeft, and PaddingRight.

It reports two cases:

Shape Report
All four values are the same EqualPadding
PaddingTop matches PaddingBottom, and PaddingLeft matches PaddingRight DirectionalPadding

The rule only reports when the project already has a matching local component.

Incorrect
<uipadding
PaddingBottom={padding}
PaddingLeft={padding}
PaddingRight={padding}
PaddingTop={padding}
/>;
Correct
<EqualPadding padding={padding} />;
<DirectionalPadding horizontal={horizontal} vertical={vertical} />;

Auto-fix only runs in .jsx and .tsx files, and only when the current file already imports exactly one matching local component.

For DirectionalPadding, the generated props follow the local component contract used by the rule:

  • horizontal comes from PaddingTop and PaddingBottom
  • vertical comes from PaddingLeft and PaddingRight