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

Rubocop incorrectly complains about tabs in strings #2446

Closed
drbrain opened this issue Nov 19, 2015 · 3 comments
Closed

Rubocop incorrectly complains about tabs in strings #2446

drbrain opened this issue Nov 19, 2015 · 3 comments
Labels

Comments

@drbrain
Copy link

drbrain commented Nov 19, 2015

Create a file with a here-document. If you copy-paste this example double-check it with hexdump -C or equivalent to make sure the tabs were copied out of github successfully (as preview mode appears to eat tabs).

<<-'TAB_BUG'
    ← tab
    ← space, tab
     ← tab, space
TAB_BUG

Run rubocop against this file.

Expected results:

No offenses

Actual results:

Rubocop thinks it knows better than the string content author what content is allowed in a String.

$ ruby -Ilib bin/rubocop tabs_in_heredoc_bug.rb 
Inspecting 1 file
C

Offenses:

tabs_in_heredoc_bug.rb:1:1: C: Missing utf-8 encoding comment.
<<-'TAB_BUG'
^
tabs_in_heredoc_bug.rb:2:1: C: Tab detected.
    ← tab
^
tabs_in_heredoc_bug.rb:3:2: C: Tab detected.
    ← space, tab
 ^
tabs_in_heredoc_bug.rb:4:1: C: Tab detected.
     ← tab, space
^

1 file inspected, 4 offenses detected
@drbrain drbrain changed the title Rubocop incorrectly complains about tabs in here-document Rubocop incorrectly complains about tabs in strings Nov 19, 2015
@drbrain
Copy link
Author

drbrain commented Nov 19, 2015

Oh, it fails for all strings:

<<-'TAB_BUG'
    ← tab
    ← space, tab
     ← tab, space
TAB_BUG

'
    ← tab
    ← space, tab
     ← tab, space
'
Inspecting 1 file
W

Offenses:

tabs_in_strings_bug.rb:1:1: W: Literal <<-'TAB_BUG' used in void context.
<<-'TAB_BUG'
^^^^^^^^^^^^
tabs_in_strings_bug.rb:1:1: C: Missing utf-8 encoding comment.
<<-'TAB_BUG'
^
tabs_in_strings_bug.rb:2:1: C: Tab detected.
    ← tab
^
tabs_in_strings_bug.rb:3:2: C: Tab detected.
    ← space, tab
 ^
tabs_in_strings_bug.rb:4:1: C: Tab detected.
     ← tab, space
^
tabs_in_strings_bug.rb:8:1: C: Tab detected.
    ← tab
^
tabs_in_strings_bug.rb:9:2: C: Tab detected.
    ← space, tab
 ^
tabs_in_strings_bug.rb:10:1: C: Tab detected.
     ← tab, space
^

1 file inspected, 8 offenses detected

@jonas054 jonas054 added the bug label Nov 21, 2015
@jonas054
Copy link
Collaborator

I agree it's a bug. Needs to be fixed.

@alexdowad
Copy link
Contributor

@drbrain, when reporting bugs against RuboCop, please run with -D so it shows the "cop" which is producing the erroneous warning (or correction).

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

3 participants