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/TernaryParentheses #4106

Closed
satnami opened this issue Mar 10, 2017 · 1 comment · May be fixed by juslee/java-buildpack#1
Closed

Style/TernaryParentheses #4106

satnami opened this issue Mar 10, 2017 · 1 comment · May be fixed by juslee/java-buildpack#1

Comments

@satnami
Copy link

satnami commented Mar 10, 2017

Class or Module required (TypeError)

('String'.is_a? String) ? do_something : do_something_else

Expected behavior

remains as it is.

Actual behavior

Omit parentheses for ternary conditions.
'String'.is_a? String ? do_something : do_something_else

Faulty auro-correct

irb(main):001:0> 'String'.is_a? String ? true : false
TypeError: class or module required
	from (irb):1:in `is_a?'
	from (irb):1
	from /home/.rbenv/versions/2.3.1/bin/irb:11:in `<main>'

RuboCop version

$ rubocop -V
0.47.1 (using Parser 2.4.0.0, running on ruby 2.3.1 x86_64-linux)
@rrosenblum
Copy link
Contributor

#4118 discusses a similar issue as the invalid correction in this code. I am not sure how difficult this will be to fix.

For example (foo == 'String') ? do_something : do_something_else will produce the same offense and the correction will be valid.

Drenmi added a commit to Drenmi/rubocop that referenced this issue Apr 2, 2017
… detector smarter

This cop, despite checking for unsafe autocorrects, did not recognize
methods sent to constants or literals, leading to inappropriate omission
recommendations.

This change fixes that.
@bbatsov bbatsov closed this as completed in ef9607c Apr 2, 2017
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.

2 participants