Skip to content

sort-comp reorders static propTypes #1838

Closed
@dan-kez

Description

@dan-kez

Hello!

I recently started receiving errors about my static propTypes being out of order. It looks like with the grouping logic, all static variables must be in alphabetical order. This causes my prop types to be forced down.

I've gotten around this by adding the following regex to my config which will push displayName, propTypes, and defaultProps to the top while allowing all other static methods to be below them.

"react/sort-comp": [
      "error",
      {
        order: [
          'static-methods',
          'lifecycle',
          'everything-else',
          'render'
        ],
        groups: {
          'static-methods': [
            'displayName',
            'propTypes',
            'defaultProps',
            '/^((?!propTypes|defaultProps).)*$/',
          ],
          lifecycle: [
            'displayName',
            'propTypes',
            'contextTypes',
            'childContextTypes',
            'mixins',
            'statics',
            'defaultProps',
            'constructor',
            'getDefaultProps',
            'state',
            'getInitialState',
            'getChildContext',
            'getDerivedStateFromProps',
            'componentWillMount',
            'UNSAFE_componentWillMount',
            'componentDidMount',
            'componentWillReceiveProps',
            'UNSAFE_componentWillReceiveProps',
            'shouldComponentUpdate',
            'componentWillUpdate',
            'UNSAFE_componentWillUpdate',
            'getSnapshotBeforeUpdate',
            'componentDidUpdate',
            'componentDidCatch',
            'componentWillUnmount'
          ]
        }
      }
    ]

example error:

  13:3  error  propTypes should be placed after determineDropdownValue  react/sort-comp
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions