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

Single-line if/then/end, WITHOUT else, generates OneLineConditional offense #2093

Closed
zach-brockway opened this issue Jul 31, 2015 · 1 comment
Labels

Comments

@zach-brockway
Copy link

Offending code/output:

lib/ndb_ascii_parser.rb:70:9: C: Favor the ternary operator (?:) over if/then/else/end constructs.
        if gsub_result.nil? then warn( "Malformed alphanumeric value: '#{field}'" ) end
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note that the same line also triggers IfUnlessModifier, which I would actually expect in this case. On the other hand, OneLineConditional seems like it should only be triggered when there exists an "else" to become the right half of the ternary.

$ rubocop -V
0.32.1 (using Parser 2.2.2.6, running on ruby 2.2.1 x86_64-darwin14)
@bbatsov bbatsov added the bug label Jul 31, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 31, 2015

Yep, that's a bug.

@bbatsov bbatsov closed this as completed in 8028b12 Aug 4, 2015
bbatsov added a commit that referenced this issue Aug 4, 2015
[Fix #2093] if/then/end generates OLC offense
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants