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

Add instance-properties group to sort-comp. Issue #599. #685

Closed
wants to merge 4 commits into from
Closed

Add instance-properties group to sort-comp. Issue #599. #685

wants to merge 4 commits into from

Conversation

le0nik
Copy link

@le0nik le0nik commented Jul 17, 2016

Relevant issue: #599

It's a common convention to have instance properties on top(right below the static properties/methods), like this:

class Hello extends React.Component {
  static displayName = 'Hello';

  count = 0;

  componentDidMount() {
    // ...
  }

  handleClick = () => {
    this.count += 1;
    // ...
  }

  render() {
    // ...
  }
}

Right now sort-comp rule doesn't allow that and wants count to be below componentDidMount, unless you specify it by name in the configuration.

This PR's aim is to allow placing instance properties separately.

The default configuration is not changed.

@ljharb
Copy link
Member

ljharb commented Jul 17, 2016

Allowing it to be configurable is excellent. However, changing the default order makes it a breaking change. Should this preserve the default order, and be semver-minor, and change the default later?

@le0nik
Copy link
Author

le0nik commented Jul 17, 2016

@ljharb I've reverted the default order. My initial way of thinking was that this change could be part of 6.0.0, considering that it's in alpha now.

@ljharb
Copy link
Member

ljharb commented Jul 17, 2016

That's a fair point. @yannickcr should weigh in on that.

@yannickcr
Copy link
Member

Since 6.0.0 is imminent we could do this, but I don't know if it is a good thing to force instance properties on top in the default configuration.

What is the most common order used by React users here?

@ljharb
Copy link
Member

ljharb commented Jul 18, 2016

Instance properties are still stage 1, so we don't use them yet at Airbnb. However, since instance properties run almost as if they were in the constructor, i think they absolutely should all be placed just like the constructor - at the top.

@kylpo
Copy link

kylpo commented Jan 12, 2017

This has become a common pattern for the react community, and one that I would certainly like to enforce in my projects. Mind taking another look at this and weighing in on why it is not accepted? (other than the conflicts to be resolved now)

@lencioni lencioni added this to the 7.0.0 milestone Feb 15, 2017
Copy link
Collaborator

@lencioni lencioni left a comment

Choose a reason for hiding this comment

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

It would be great to get a rebase of this.

2. lifecycle methods: `displayName`, `propTypes`, `contextTypes`, `childContextTypes`, `mixins`, `statics`,`defaultProps`, `constructor`, `getDefaultProps`, `getInitialState`, `state`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate`, `componentWillUnmount` (in this order).
3. custom methods
4. `render` method
2. instance properties
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this documentation needs to be updated, since the default order has not been modified yet.

It would be nice to open a PR that updates the default and documentation that we could bring in as part of v7.0.0.

@lencioni lencioni removed this from the 7.0.0 milestone Feb 15, 2017
@klimashkin
Copy link

Public Class Fields are on stage 2 already, why it still hasn't been merged into 7.x?...

@ljharb
Copy link
Member

ljharb commented Jun 12, 2017

@klimashkin this needs reviews from more collabs first, and it needs a rebase.

Separately, stage 3 is the time when it's safe to start using a feature, so that's when it will become critical to be supported here.

@ljharb ljharb requested review from yannickcr and EvHaus June 12, 2017 19:26
Copy link
Member

@yannickcr yannickcr left a comment

Choose a reason for hiding this comment

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

Default configuration should not be updated in the documentation (see @lencioni comment) and a rebase is needed.

@noahbenham
Copy link

Class fields is now a stage 3 proposal. Happy to contribute if this needs someone else to take it on.

@ljharb ljharb marked this pull request as draft October 18, 2020 02:19
@EvHaus EvHaus removed their request for review March 28, 2022 16:13
@ljharb
Copy link
Member

ljharb commented Oct 10, 2022

Unfortunately @le0nik deleted their fork, so this PR can never land.

@ljharb ljharb closed this Oct 10, 2022
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.

7 participants