Skip to content

Commit

Permalink
[Fix #8799] Fix SpaceInsideBlockBraces cop regression.
Browse files Browse the repository at this point in the history
In 6c05f69 this cop
was changed in a way which prevents it from running multiple
times on a single line.

It appears that this is due to the misunderstanding about
what the 'unrecognized_style_detected' and 'opposite_style_detected'
methods are designed to do.

I do not believe that they should be used as inquiry methods,
but should be used as side-effecting methods.

e.g. `opposite_style_detected` ALWAYS returns a truthy value.
  • Loading branch information
rdunlop committed Sep 30, 2020
1 parent 90d909d commit e291f21
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

* [#8810](https://github.com/rubocop-hq/rubocop/pull/8810): Fix multiple offense detection for `Style/RaiseArgs`. ([@pbernays][])
* [#8809](https://github.com/rubocop-hq/rubocop/pull/8809): Fix multiple offense detection for `Style/For`. ([@pbernays][])
* [#8801](https://github.com/rubocop-hq/rubocop/pull/8801): Fix `Layout/SpaceAroundEqualsInParameterDefault` only registered once in a line. ([@rdunlop][])
* [#8801](https://github.com/rubocop-hq/rubocop/issues/8801): Fix `Layout/SpaceAroundEqualsInParameterDefault` only registered once in a line. ([@rdunlop][])

### Changes

Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/layout/space_inside_block_braces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ def space_inside_right_brace(right_brace)

def no_space(begin_pos, end_pos, msg)
if style == :space
return unless opposite_style_detected

offense(begin_pos, end_pos, msg)
else
correct_style_detected
Expand All @@ -216,8 +214,6 @@ def no_space(begin_pos, end_pos, msg)

def space(begin_pos, end_pos, msg)
if style == :no_space
return unless opposite_style_detected

offense(begin_pos, end_pos, msg)
else
correct_style_detected
Expand Down
28 changes: 28 additions & 0 deletions spec/rubocop/cop/layout/space_inside_block_braces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@
RUBY
end

it 'registers an offense and corrects both left and right brace without inner space after success' do
expect_offense(<<~RUBY)
each { puts }
each {puts}
^ Space missing inside {.
^ Space missing inside }.
RUBY

expect_correction(<<~RUBY)
each { puts }
each { puts }
RUBY
end

it 'register offenses and correct both braces without inner space' do
expect_offense(<<~RUBY)
a {}
Expand Down Expand Up @@ -285,6 +299,20 @@
RUBY
end

it 'registers an offense and corrects both left and right brace with inner space after success' do
expect_offense(<<~RUBY)
each {puts}
each { puts }
^ Space inside { detected.
^ Space inside } detected.
RUBY

expect_correction(<<~RUBY)
each {puts}
each {puts}
RUBY
end

it 'accepts left brace without outer space' do
expect_no_offenses('each{puts}')
end
Expand Down

0 comments on commit e291f21

Please sign in to comment.