Skip to content

[Bug]: Fixer of sort-prop-types doesn’t respect noSortAlphabetically  #3591

@kripod

Description

@kripod

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions