[fix] indentation & trailing whitespace in Heredoc#945
Open
nicholasdower wants to merge 2 commits into
Open
Conversation
An attempt at fixing a few Heredoc issues: * 1 tab equals 8 spaces * 1 space + 1 tab equals 8 spaces * Trailing whitespace in squiggly Heredoc should not be stripped. * A single whitespace-only line should be preserved * Multiple whitespace-only lines should be preserved See: https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#here-document-literals >The indentation of the least-indented line will be removed from each >line of the content. Note that empty lines and lines consisting solely >of literal tabs and spaces will be ignored for the purposes of >determining indentation, but escaped tabs and spaces are considered >non-indentation characters. > >For the purpose of measuring an indentation, a horizontal tab is >regarded as a sequence of one to eight spaces such that the column >position corresponding to its end is a multiple of eight. The amount to >be removed is counted in terms of the number of spaces. If the boundary >appears in the middle of a tab, that tab is not removed.
63959ad to
7153043
Compare
Contributor
Author
|
In my original commit, I added test cases to existing fixtures. But this had a few downsides:
I've now added a commit that introduces Please let me know whether this is an acceptable approach. Also note that I had to bump the Ruby version in CI to 3.4. Prior to 3.4, there was a bug related to trailing whitespace in heredocs: echo "puts <<~FOO.inspect\n \nFOO\n" | /Users/nickdower/.rvm/rubies/ruby-3.3.0/bin/ruby
"\n"
echo "puts <<~FOO.inspect\n \nFOO\n" | /Users/nickdower/.rvm/rubies/ruby-3.4.1/bin/ruby
" \n"The issue was fixed in ruby/ruby@5bb656e4. |
7153043 to
04d41ff
Compare
04d41ff to
8ce11e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An attempt at fixing a few Heredoc issues (including #921).
See: https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#here-document-literals
Issues Addressed
To run the following tests locally, first run:
1 tab equals 8 spaces
The first line is indented 8 spaces. The second is indented 1 tab. The indentation is equal.
Test
Result
1 space + 1 tab equals 8 spaces
The first line is indented 9 spaces. The second is indented 1 space and 1 tab. This should leave 1 space before "foo".
Test
Result
Trailing whitespace in squiggly Heredoc should not be stripped
Test
Result
A single whitespace-only line should be preserved
Test
Result
Multiple whitespace-only lines should be preserved
Test
Result
Issues Not Yet Addressed
Heredoc containing only an empty line
Test
Result
Heredoc containing only multiple empty lines
Test
Result