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

Style/EmptyElse probably doesn't distinguish between actual nil and empty block #1611

Closed
zenspider opened this issue Jan 27, 2015 · 7 comments · Fixed by #1660
Closed

Style/EmptyElse probably doesn't distinguish between actual nil and empty block #1611

zenspider opened this issue Jan 27, 2015 · 7 comments · Fixed by #1660

Comments

@zenspider
Copy link

      @diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ &&
                  system("diff.exe", __FILE__, __FILE__)) then
                "diff.exe -u"
              elsif Minitest::Test.maglev? then
                "diff -u"
              elsif system("gdiff", __FILE__, __FILE__)
                "gdiff -u" # solaris and kin suck
              elsif system("diff", __FILE__, __FILE__)
                "diff -u"
              else
                nil
              end unless defined? @diff
@Koronen
Copy link
Contributor

Koronen commented Jan 27, 2015

That's correct. This is intentional, see #1444. On the other hand, I can understand if some prefer to be explicit about returning nil in the else case. Maybe this behavior should be configurable?

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 28, 2015

I'm fine with having it be configurable (the other setting would complain
only for truly empty else clauses).

On 27 January 2015 at 22:09, Victor Koronen [email protected]
wrote:

That's correct. This is intentional, see #1444
#1444. On the other hand, I can
understand if some prefer to be explicit about returning nil in the else
case. Maybe this behavior should be configurable?


Reply to this email directly or view it on GitHub
#1611 (comment).

@edvardm
Copy link

edvardm commented Feb 7, 2015

Totally agree with explicit nil being better. That communicates to the reader that else clause was not just forgotten. Returning implicit nil when falling through case statement is hard to understand being intentional.

Other than that, great tool! I especially love all the auto-correct stuff.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 7, 2015

Btw, there's one more case to consider - a missing else. In such scenarios there's an implicit else returning nil, but some people might prefer to make all such cases explicit...

@edvardm
Copy link

edvardm commented Feb 9, 2015

That's precisely what I meant. My convention is to even add comment

...
else
   nil # no-op
end

in such cases, to indicate that this not just something that is unhandled, but returning nil in purpose. There are probably better solutions, though.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 9, 2015

So, it seems to me this cop should support 3 styles:

  • warn on implicit nil (both empty else and missing else)
  • warn on explicit/redundant nil/else
  • warn on on empty else

@edvardm
Copy link

edvardm commented Feb 9, 2015

+1, should satisfy both the followers of "be explicit" and "meh I know what I'm doing" schools :)

rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Feb 23, 2015
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Feb 24, 2015
bbatsov added a commit that referenced this issue Feb 24, 2015
[Fix #1611] Add SupportedStyles to EmptyElse cop
rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Feb 28, 2015
bbatsov added a commit that referenced this issue Feb 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants