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

Group static lifecycle methods under lifecycle #1962

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

metreniuk
Copy link
Contributor

@metreniuk metreniuk commented Aug 29, 2018

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 .

@metreniuk
Copy link
Contributor Author

metreniuk commented Sep 13, 2018

@alexzherdev what do you think about this? Is it accurate to do so or this is a breaking change that isn't worth doing?

@ljharb
Copy link
Member

ljharb commented Sep 17, 2018

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.

@metreniuk
Copy link
Contributor Author

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?

@alexzherdev
Copy link
Contributor

@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?

@metreniuk
Copy link
Contributor Author

@alexzherdev sure. I've added the new functionality under the preferLifecycle option (false by default) and added more tests.

'class Hello extends React.Component {',
' constructor() {}',
' static getDerivedStateFromProps() {}',
'}'
].join('\n')
].join('\n'),
options: [{preferLifecycle: true}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of modifying this test, can we duplicate it and modify the duplicate?

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

Successfully merging this pull request may close these issues.

None yet

3 participants