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 doesn't recognize instance variables declared without explicit value #2183

Closed
ericgio opened this issue Mar 1, 2019 · 2 comments
Closed

Comments

@ericgio
Copy link

ericgio commented Mar 1, 2019

Thanks for a very useful library. Apologies if I'm missing something obvious here, but it seems that instance variables are not recognized as such unless a value is explicitly assigned.

Given this sort-comp rule

"react/sort-comp": [2, {
  "order": [
    "state",
    "instance-variables",
    "static-methods",
    "lifecycle",
    "render",
    "everything-else"
  ],
}],

and this class definition

class MyComponent extends React.Component {
  state = {};
  foo;
  static propTypes;

  render() {
    return null;
  }
}

I get this error:

error  foo should be placed after render  react/sort-comp

Changing foo; to foo = undefined; solves the problem, but the behavior is confusing to me.

@ericgio ericgio changed the title sort-comp doesn't recognize instance variables declared with implicit undefined sort-comp doesn't recognize instance variables declared without explicit value Mar 1, 2019
@ljharb
Copy link
Member

ljharb commented Mar 3, 2019

Seems like a bug, to be sure.

@ericgio
Copy link
Author

ericgio commented Mar 5, 2019

Thanks guys!

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