Closed as not planned
Description
Rule details
An ESLint plugin that forbids else blocks and encourages early returns instead
Related ECMAScript feature
None
What type of rule is this?
Suggests an alternate way of doing something
Example code
/**
* Bad example
* /
function getSign(x) {
if (x > 0) {
return '+';
} else if (x < 0) {
return '-';
} else {
return '';
}
}
/**
* Good example
* /
function getSign(x) {
if (x > 0) {
return '+';
}
if (x < 0) {
return '-';
}
return '';
}
Why should this rule be in the core instead of a plugin?
This makes the code flow more linear and easier to follow / understand.
Participation
- I am willing to submit a pull request to implement this rule.
Additional comments
Here would be an example implementation of the rule: https://github.com/raphael-arce/eslint-plugin-no-else/blob/main/src/no-else.js
(First time writing an EsLint plugin/rule, not sure the implementation is correct)
Metadata
Metadata
Assignees
Type
Projects
Status
Complete