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 #7509] Layout/SpaceInsideArrayLiteralBrackets to correct empty lines #7511

Merged
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: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#7493](https://github.com/rubocop-hq/rubocop/issues/7493): Fix `Style/RedundantReturn` to inspect conditional constructs that are preceded by other statements. ([@buehmann][])
* [#7509](https://github.com/rubocop-hq/rubocop/issues/7509): Fix `Layout/SpaceInsideArrayLiteralBrackets` to correct empty lines. ([@ayacai115][])

### Changes

Expand Down Expand Up @@ -4258,3 +4259,4 @@
[@jdkaplan]: https://github.com/jdkaplan
[@cstyles]: https://github.com/cstyles
[@avmnu-sng]: https://github.com/avmnu-sng
[@ayacai115]: https://github.com/ayacai115
3 changes: 1 addition & 2 deletions lib/rubocop/cop/correctors/space_corrector.rb
Expand Up @@ -12,12 +12,11 @@ class << self
def empty_corrections(processed_source, corrector, empty_config,
left_token, right_token)
@processed_source = processed_source
range = range_between(left_token.end_pos, right_token.begin_pos)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if offending_empty_space?(empty_config, left_token, right_token)
range = side_space_range(range: left_token.pos, side: :right)
corrector.remove(range)
corrector.insert_after(left_token.pos, ' ')
elsif offending_empty_no_space?(empty_config, left_token, right_token)
range = side_space_range(range: left_token.pos, side: :right)
corrector.remove(range)
end
end
Expand Down
Expand Up @@ -42,6 +42,11 @@
new_source = autocorrect_source('a = [ ]')
expect(new_source).to eq('a = []')
end

it 'auto-corrects multiline spaces' do
new_source = autocorrect_source("a = [\n]")
expect(new_source).to eq('a = []')
end
end

context 'with space inside empty braces allowed' do
Expand Down