eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

`jsx-sort-props`: minimum number of props

Open Garrett-R opened this issue 6 months ago • 3 comments

Similar to how ESLint's sort-keys has a configuration option of minKeys, it would be nice to have a minProps option.

Garrett-R avatar May 04 '25 00:05 Garrett-R

Why, exactly?

ljharb avatar May 04 '25 04:05 ljharb

Ah sorry, should have added context. Two reasons:

  1. for components with only a couple props, like say 2, the ordering isn't too important and the rule might be more annoying than helpful to the devs.
  2. devs may want the option to order "semantically" for reasonable number of props, for example:
<MyButton
    type="submit"
    color="blue"
    variant="solid"
    onBlur={onBlur}
    onClick={onClick}
/>

while if a component has like 10+ props, then I think it should definitely be ordered.

It seems (1) was the motivation for the analogue sort-keys being added to ESLint (see convo here).

Garrett-R avatar May 05 '25 18:05 Garrett-R

I guess it's fine, altho I'm not sure it's a good thing to be tacitly encouraging reduced enforcement.

ljharb avatar May 05 '25 18:05 ljharb