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

Spaces after ternary operator colons are reported/corrected twice #3010

Closed
owst opened this issue Apr 5, 2016 · 0 comments
Closed

Spaces after ternary operator colons are reported/corrected twice #3010

owst opened this issue Apr 5, 2016 · 0 comments

Comments

@owst
Copy link
Contributor

owst commented Apr 5, 2016

Consider the following simple Ruby source file:

➜  /tmp cat foo.rb
'a' == 'b' ? 1 :2

Using Rubocop 0.39.0 (using Parser 2.3.0.7, running on ruby 2.2.3 x86_64-darwin14) the following offenses/corrections are listed:

➜  /tmp rubocop -a foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:1:16: C: [Corrected] Space missing after colon.
'a' == 'b' ? 1 :2
               ^
foo.rb:1:16: C: [Corrected] Operator : should be surrounded by a single space.
'a' == 'b' ? 1 :  2
               ^
foo.rb:1:16: C: [Corrected] Surrounding space missing for operator :.
'a' == 'b' ? 1 :2
               ^
foo.rb:1:17: C: [Corrected] Unnecessary spacing detected.
'a' == 'b' ? 1 :  2
                ^

1 file inspected, 4 offenses detected, 4 offenses corrected

Notice that the since both Style/SpaceAfterColon and Style/Style/SpaceAroundOperators logged and corrected offenses, Rubocop generated double spacing after the colon, which it then detected and corrected. Indeed the file is corrected properly:

➜  /tmp cat foo.rb
'a' == 'b' ? 1 : 2

I think Style/SpaceAfterColon should not handle spaces in a ternary operator, which would avoid the double reporting and too much correction.

owst added a commit to owst/rubocop that referenced this issue Apr 7, 2016
Both `Style/SpaceAfterColon` and `Style/SpaceAroundOperators` were
detecting the missing space after a colon in a ternary operator, this
led to redundant warnings and corrections. To fix, the ternary handling
from `Style/SpaceAfterColon` was removed.
@bbatsov bbatsov closed this as completed in fdf79e3 Apr 8, 2016
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

No branches or pull requests

1 participant