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

Auto correct should not automatically remove trailing whitespace in heredoc #7860

Closed
KNejad opened this issue Apr 8, 2020 · 2 comments · Fixed by #7883
Closed

Auto correct should not automatically remove trailing whitespace in heredoc #7860

KNejad opened this issue Apr 8, 2020 · 2 comments · Fixed by #7883

Comments

@KNejad
Copy link
Contributor

KNejad commented Apr 8, 2020

Back in 2017 #4517 raised the issue that trailing whitespaces should not be marked as offences in heredoc strings.

This resulted in #5777 which added a new config option to prevent the cop from complaining.

Whilst this seems like a good fix, it still means that when running auto correct, it will remove trailing spaces automatically, which could result in a change in logic.

Take the below for example:

require 'digest'

my_string = <<~END
Whitespace here: 
END

sha = Digest::SHA2.new(256).hexdigest my_string
expected_sha = "74788f79010cd7a165e6df2e91013ce72903696bca4d42989de97c3150b89db2"

puts "authenticated" if expected_sha == sha

This will print "authenticated" before running rubocop --auto-correct, but will fail after.

I've had a similar issue in production where we had to verify a signed string and to test I used an example provided string, which had trailing whitespace. Running rubocop --auto-correct broke the tests.


Expected behavior

Running rubocop --auto-correct should not remove the trailing whitespace.

Actual behavior

The whitespace is removed

Steps to reproduce the problem

See the script above

RuboCop version

0.81.0

@jonas054
Copy link
Collaborator

I agree. I think we chose the wrong default in #5777. It should be

Layout/TrailingWhitespace:
  AllowInHeredoc: true

@koic
Copy link
Member

koic commented Apr 17, 2020

AllowInHeredoc: true looks good default value to me. I opened #7883.

koic added a commit to koic/rubocop that referenced this issue Apr 17, 2020
…Whitespace` to `true`

Fixes rubocop#7860.

This PR changes `AllowInHeredoc` option of `Layout/TrailingWhitespace`
to `true` by default. The default behavior will be more safe.
bbatsov pushed a commit that referenced this issue Apr 17, 2020
…ace` to `true`

Fixes #7860.

This PR changes `AllowInHeredoc` option of `Layout/TrailingWhitespace`
to `true` by default. The default behavior will be more safe.
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.

3 participants