sort-comp rule is broken
See original GitHub issueHi 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:
- Created 5 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I’ll try to make a PR then!
This rule now has “instance-variables” and “instance-methods” as group options.