question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sort-comp rule is broken

See original GitHub issue

Hi folks,

First of all thanks for the great work and effort on this.

I’m opening this issue because I believe that the actual order is broken, consider this example:

class App extends PureComponent {
  something = {
    whatever: true,
  };

  state = {
    count: 0,
  };

  constructor(props) {
    super(props);
    this.ws = new WebSocket("ws://localhost:5000/api/1.0/events");
    this.ws.onerror = this.onWsError.bind(this);
    this.ws.onmessage = this.onWsMessage.bind(this);
  }

  componentDidMount() {
    // ...
  }

  render() {
    // ...
  }

  onWsMessage(ev) {
    // ...
  }

  onWsError(ev) {
    // ...
  }

}

Which produces these errors:

something should be placed after onWsError state should be placed after constructor

😟 Mhh… ok, let see:

class App extends PureComponent {

  constructor(props) {
    super(props);
    this.ws = new WebSocket("ws://localhost:5000/api/1.0/events");
    this.ws.onerror = this.onWsError.bind(this);
    this.ws.onmessage = this.onWsMessage.bind(this);
  }

  state = {
    count: 0,
  };

  componentDidMount() {
    // ...
  }

  render() {
    // ...
  }

  onWsMessage(ev) {
    // ...
  }

  onWsError(ev) {
    // ...
  }

  something = {
    whatever: true,
  };

}

😄 I hope you agree with me that it doesn’t make sense… state is included inside the lifecycle category, but something in the everything-else, while in fact both are just public fields which should be both initialised before the constructor IMHO.

That would make sense for you? I could make a PR if you want.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
nuragiccommented, Jun 12, 2018

Ok, I’ll try to make a PR then!

1reaction
ljharbcommented, Feb 6, 2022

This rule now has “instance-variables” and “instance-methods” as group options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sort-comp rule is broken · Issue #1814 · jsx-eslint/eslint-plugin-react ...
I'm opening this issue because I believe that the actual order is broken, consider this example: class App extends PureComponent { something =...
Read more >
1258353 - Update the ESLint rule "react/sort-comp"
This rule wants methods inside a React class to be sorted alphabetically, and is responsible for warnings like "render must be placed after...
Read more >
When does TimSort complain about broken comparator?
The method performs a merging of two sorted runs. It does a usual merge but starts "gallopping" once it encounters that one side...
Read more >
Compensating Workers for Permanent Partial Disabilities - SSA
In a general sense, permanent partial disability benefits in the state programs can be sorted into two broad classes: individual justice and average...
Read more >
GNU make
Archive Suffix Rules, You can write a special kind of suffix rule for ... Each compilation produces an object file corresponding to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found