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 rule doesn't enforce getDerivedStateFromProps placement #1793
Comments
What is your full eslint config? |
@lynxtaa you should be specifying a version pragma in "settings" (see the read me), but I don't think that's it. Could you also share the entire component code in question? |
Still the same issue with specified pragma. Example component import React from 'react'
class Test extends React.Component {
static getDerivedStateFromProps() {
return null
}
constructor(props) {
super(props)
this.state = { test: 'test' }
}
render() {
return this.state.test
}
}
export default Test React 16.3.2. |
ok, what warning do you get with that component? |
No warning. But i should get "react/sort-comp" warning according to this https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md getDerivedStateFromProps should be declared after constructor. |
aha, this seems to be a bug in the sort-comp implementation then - since the lifecycle methods are typically instance methods, but cc @joe-denea / #1771 which has tests for the "valid" case for this method, but not for the "invalid" case. |
Sorry about that, I should definitely have tested that. |
Fixed in #1795. |
With "react/sort-comp": "warn" provided code shouldn't be considered valid:
Tested on version 7.8.2
The text was updated successfully, but these errors were encountered: