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: constructor must be placed after componentWillUnmount #97

Closed
tleunen opened this issue Jun 6, 2015 · 2 comments
Closed

sort-comp: constructor must be placed after componentWillUnmount #97

tleunen opened this issue Jun 6, 2015 · 2 comments

Comments

@tleunen
Copy link

tleunen commented Jun 6, 2015

With sort-comp enabled and ES6 classes, the plugin reports that constructor should be after componentWillUnmount. It should be an exception...

Here's a simple example with the issue:

export default class MyClass extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
    }

    componentWillUnmount() {
    }

    render() {
        return <div></div>;
    }
}
@yannickcr
Copy link
Member

Currently the default configuration is:

  1. Lifecycle methods
  2. Custom methods
  3. render method

constructor is not specified in any group, so it is considered as a custom method and the rule asks you to place it after componentWillUnount(the last lifecycle method).

I think I will update the default configuration to get:

  1. constructor method
  2. Lifecycle methods
  3. Custom methods
  4. render method

For now you can set up a custom configuration in your .eslintrc:

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

@tleunen
Copy link
Author

tleunen commented Jun 9, 2015

Sounds great! And thanks for the workaround

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

No branches or pull requests

2 participants