Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[unnecessary-else] Add option to disable error at else-if statements #4598

Closed
timocov opened this issue Mar 23, 2019 · 3 comments
Closed

[unnecessary-else] Add option to disable error at else-if statements #4598

timocov opened this issue Mar 23, 2019 · 3 comments

Comments

@timocov
Copy link
Contributor

timocov commented Mar 23, 2019

Feature request

Is your feature request related to a problem? Please describe.

It would be nice to have an option to configure unnecessary-else rule to don't fail on else if statements (only on else).

@JoshuaKGoldberg
Copy link
Contributor

Hi @timocov! Could you explain more on why you want this rule option? It seems rather arbitrary to allow else if but not else.

@timocov
Copy link
Contributor Author

timocov commented Mar 24, 2019

For me it looks strange to change a code from

if (a > 0) {
  return 1;
} else if (a < 0) {
  return 2;
} else {
  return 3;
}

to

if (a > 0) {
  return 1;
}

if (a < 0) {
  return 2;
}

return 3;

These conditions are related and (for me) they should be in "one flow" (not separated conditions), because if someone decide to add new condition between if (a > 0) { and if (a < 0) { it "breaks" their relating.

But I agree, that else block in this case is unnecessary and should be "removed":

if (a > 0) {
  return 1;
} else if (a < 0) {
  return 2;
}

return 3;

@JoshuaKGoldberg
Copy link
Contributor

Seems reasonable as a style preference. Not very important in the context of linting, but it's nice to relax these style preference rules when requested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants