Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort-comp reorders static propTypes #1838

Closed
dan-kez opened this issue Jun 21, 2018 · 0 comments · Fixed by #1858
Closed

sort-comp reorders static propTypes #1838

dan-kez opened this issue Jun 21, 2018 · 0 comments · Fixed by #1858

Comments

@dan-kez
Copy link

dan-kez commented Jun 21, 2018

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
``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant