Skip to content

Commit

Permalink
Merge pull request #7511 from ayacai115/add-autofix-to-SpaceInsideArr…
Browse files Browse the repository at this point in the history
…ayLiteralBrackets

[Fix #7509] Layout/SpaceInsideArrayLiteralBrackets to correct empty lines
  • Loading branch information
koic committed Nov 20, 2019
2 parents 88a62c2 + 957b000 commit f6ab020
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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)
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

0 comments on commit f6ab020

Please sign in to comment.