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

Rule Request: avoid if-not-else #2031

Open
2 tasks done
guilhermearaujo opened this issue Jan 30, 2018 · 0 comments
Open
2 tasks done

Rule Request: avoid if-not-else #2031

guilhermearaujo opened this issue Jan 30, 2018 · 0 comments

Comments

@guilhermearaujo
Copy link

New Issue Checklist

Rule Request

  1. Proposal: when an if statement includes the else clause, the if clause should not be negated. The same applies to the ternary operator.

  2. Examples:

// Would trigger:
  if !test {
    methodA()
  } else {
    methodB()
  }

  if !(testA || testB) {
    methodA()
  } else {
    methodB()
  }

  !test ? methodA() : methodB()

// Would not trigger:
  if test {
    methodB()
  } else {
    methodA()
  }

  if testA || testB {
    methodB()
  } else {
    methodA()
  }

  if test ? methodB() : methodA()
  1. Should the rule be configurable, if so what parameters should be configurable?
    Not that I can think of.

  2. Should the rule be opt-in or enabled by default? Why?
    I, personally, would say yes, as if one is handling both possibilities, there is no need to do it with inverted logic.

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

No branches or pull requests

2 participants