Description
Is there an existing issue for this?
- I have searched the existing issues and my issue is unique
- My issue appears in the command-line and not only in the text editor
Description Overview
Unlike with jsx-sort-props
, the sort-prop-types
rule doesn’t respect the { noSortAlphabetically: true }
option passed when fixing the order of prop types.
When "react/sort-prop-types": ["warn", { callbacksLast: true, noSortAlphabetically: true }]
is set, the example below:
AccordionItem.propTypes = {
open: PropTypes.bool,
onClick: PropTypes.func,
id: PropTypes.string,
};
Gets fixed as follows:
AccordionItem.propTypes = {
id: PropTypes.string,
open: PropTypes.bool,
onClick: PropTypes.func,
};
While the underlying callbacksLast
issue is fixed, it appears that noSortAlphabetically
isn’t respected by the fixer, just as seen in the source:
eslint-plugin-react/lib/rules/sort-prop-types.js
Lines 178 to 187 in ae64aa8
eslint-plugin-react/lib/rules/sort-prop-types.js
Lines 109 to 119 in ae64aa8
The fixPropTypesSort
method doesn’t take a noSortAlphabetically
parameter.
Expected Behavior
The correct fix for the snippet above would be:
AccordionItem.propTypes = {
open: PropTypes.bool,
id: PropTypes.string,
onClick: PropTypes.func,
};
Only onClick
should be moved to the bottom, leaving the order of non-callback props intact.
eslint-plugin-react version
7.32.2
eslint version
v8.43.0
node version
v16.20.0