eslint-plugin-react
eslint-plugin-react copied to clipboard
Group static lifecycle methods under lifecycle
Since the lifecycle group is a special group that deals with state/props changes, grouping static lifecycle methods under lifecycle group helps to have this logic together. This looks like a good default behavior that follows the docs.
This PR enforces static lifecycle methods to be grouped under lifecycle
group as one of possible solutions suggested by @ljharb .
@alexzherdev what do you think about this? Is it accurate to do so or this is a breaking change that isn't worth doing?
It's definitely a breaking change; it'd be ideal to ship this now under an option, and then we can flip the option in the next major if desired.
Since the current behavior was intended to allow the same method to be part of multiple groups I am willing to keep this as it is. At the same time there could be different opinions about where a method should be (ex: getDerivedStateFromProps
before/after state declaration).
What do you think about naming the option preferLifecycle
that will be implemented under the behavior from this PR?
@metreniuk sorry, I don't have a lot of experience with this rule. From looking at this PR, I would expect more changes in tests though? Am I missing something?
@alexzherdev sure. I've added the new functionality under the preferLifecycle
option (false
by default) and added more tests.