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: static defaultProps must be placed under componentWillUnmount() #122

Closed
andrevinsky opened this issue Jun 18, 2015 · 4 comments
Closed

Comments

@andrevinsky
Copy link

For some reason, the ES6 class composition for React isn't taken into account.

For all obvious reasons, while this is supposed to be the right sort order..

class AccountInfo extends Component {

  static propTypes = {
    accountId: PropTypes.string.isRequired
  };

  static defaultProps = {
    accountId: ''
  };

..a warning shows that says:
warning defaultProps must be placed after componentWillUnmount react/sort-comp

@mathieumg
Copy link
Contributor

I'm curious, if you manually add defaultProps after propTypes in the lifecycle configuration, does it solve it? If so, it could be added at the same time as constructor is, see: #97 (comment)

@andrevinsky
Copy link
Author

I edited .eslitrc to contain this line:

    "react/sort-comp": [1,
      {
        "order": [
          "constructor",
          "lifecycle",
          "everything-else",
          "render"
        ]
      }],

Still, I get this:
28:2 warning defaultProps must be placed after componentWillUnmount react/sort-comp
for the ..

class AccountInfo extends Component {

  static propTypes = {
    accountId: PropTypes.string.isRequired
  };

  //noinspection Eslint
  static defaultProps = {
    accountId: ''
  };

@andrevinsky
Copy link
Author

And.. I am still getting this error regarding the constuctor placement:

CreateAccount.js
   36:2   warning  constructor must be placed after componentWillUnmount  react/sort-comp
  134:16  warning  Empty components are self-closing                      react/self-closing-comp
  139:16  warning  Empty components are self-closing                      react/self-closing-comp

@yannickcr
Copy link
Member

ES6 methods are not set in the default lifecycle configuration (yet). This should be fixed when I'll work on #97

So, for now you can set up a custom lifecycle configuration in your .eslintrc:

...
"react/sort-comp": [1, {
  "groups": {
    "lifecyle": [
      "constructor",
      "displayName",
      "propTypes",
      "contextTypes",
      "childContextTypes",
      "statics",
      "defaultProps",
      "getChildContext",
      "componentWillMount",
      "componentDidMount",
      "componentWillReceiveProps",
      "shouldComponentUpdate",
      "componentWillUpdate",
      "componentDidUpdate",
      "componentWillUnmount"
    ]
  }
}]
...

You can find more informations about this rule configuration settings in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants