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

Fix autocorrection for Layout/TrailingWhitespace in heredocs. #8914

Merged
merged 1 commit into from Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@
* [#8889](https://github.com/rubocop-hq/rubocop/pull/8889): Cops can use new `after_<type>` callbacks (only for nodes that may have children nodes, like `:send` and unlike `:sym`). ([@marcandre][])
* [#8906](https://github.com/rubocop-hq/rubocop/pull/8906): Fix a false positive for `Layout/SpaceAroundOperators` when upward alignment. ([@koic][])
* [#8585](https://github.com/rubocop-hq/rubocop/pull/8585): Fix false positive in `Style/RedundantSelf` cop with nested `self` access. ([@marcotc][])
* [#8692](https://github.com/rubocop-hq/rubocop/pull/8692): Fix `Layout/TrailingWhitespace` auto-correction in heredoc. ([@marcandre][])

### Changes

Expand Down Expand Up @@ -182,7 +183,6 @@
* [#8661](https://github.com/rubocop-hq/rubocop/pull/8661): Fix an incorrect auto-correct for `Style/MultilineTernaryOperator` when returning a multiline ternary operator expression. ([@koic][])
* [#8526](https://github.com/rubocop-hq/rubocop/pull/8526): Fix a false positive for `Style/CaseEquality` cop when the receiver is not a camel cased constant. ([@koic][])
* [#8673](https://github.com/rubocop-hq/rubocop/issues/8673): Fix the JSON parse error when specifying `--format=json` and `--stdin` options. ([@koic][])
* [#8692](https://github.com/rubocop-hq/rubocop/pull/8692): Fix `Layout/TrailingWhitespace` auto-correction in heredoc. ([@marcandre][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions changelog/fix_fix_autocorrection_for.md
@@ -0,0 +1 @@
* [#8914](https://github.com/rubocop-hq/rubocop/pull/8914): Fix autocorrection for `Layout/TrailingWhitespace` in heredocs. ([@marcandre][])
2 changes: 1 addition & 1 deletion config/default.yml
Expand Up @@ -1334,7 +1334,7 @@ Layout/TrailingWhitespace:
StyleGuide: '#no-trailing-whitespace'
Enabled: true
VersionAdded: '0.49'
VersionChanged: '0.83'
VersionChanged: '1.0'
AllowInHeredoc: false

#################### Lint ##################################
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_layout.adoc
Expand Up @@ -6344,7 +6344,7 @@ class Foo; end
| Yes
| Yes
| 0.49
| 0.83
| 1.0
|===

This cop looks for trailing whitespace in the source code.
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/trailing_whitespace.rb
Expand Up @@ -63,7 +63,7 @@ def process_line(line, lineno)
range = offense_range(lineno, line)
add_offense(range) do |corrector|
if heredoc
corrector.insert_after(range, '#{}') unless static?(heredoc) # rubocop:disable Lint/InterpolationCheck
corrector.wrap(range, "\#{'", "'}") unless static?(heredoc)
else
corrector.remove(range)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/layout/trailing_whitespace_spec.rb
Expand Up @@ -96,15 +96,15 @@
it 'corrects safely trailing whitespace in a heredoc string' do
expect_offense(<<~RUBY)
x = <<~EXAMPLE
has trailing#{trailing_whitespace}
^ Trailing whitespace detected.
has trailing #{trailing_whitespace}
^^^^ Trailing whitespace detected.
no trailing
EXAMPLE
RUBY

expect_correction(<<~RUBY)
x = <<~EXAMPLE
has trailing \#{}
has trailing\#{' '}
no trailing
EXAMPLE
RUBY
Expand Down