Skip to content

Commit

Permalink
Merge pull request #10736 from gsamokovarov/space-inside-numblock
Browse files Browse the repository at this point in the history
Fix Layout/SpaceInsideBlockBraces for blocks with numbered arguments
  • Loading branch information
koic committed Jun 22, 2022
2 parents 1dd8ee3 + b6c9b2a commit 0d09460
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10736](https://github.com/rubocop/rubocop/pull/10736): Fix Layout/SpaceInsideBlockBraces for blocks with numbered arguments. ([@gsamokovarov][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/layout/space_inside_block_braces.rb
Expand Up @@ -98,6 +98,8 @@ def on_block(node)
check_inside(node, left_brace, right_brace)
end

alias on_numblock on_block

private

def check_inside(node, left_brace, right_brace)
Expand Down Expand Up @@ -126,7 +128,7 @@ def adjacent_braces(left_brace, right_brace)
end

def braces_with_contents_inside(node, inner)
args_delimiter = node.arguments.loc.begin # Can be ( | or nil.
args_delimiter = node.arguments.loc.begin if node.block_type? # Can be ( | or nil.

check_left_brace(inner, node.loc.begin, args_delimiter)
check_right_brace(inner, node.loc.begin, node.loc.end, node.single_line?)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/layout/space_inside_block_braces_spec.rb
Expand Up @@ -90,6 +90,20 @@
end
end

context 'Ruby >= 2.7', :ruby27 do
it 'registers an offense for numblocks without inner space' do
expect_offense(<<~RUBY)
[1, 2, 3].each {_1 * 2}
^ Space missing inside {.
^ Space missing inside }.
RUBY

expect_correction(<<~RUBY)
[1, 2, 3].each { _1 * 2 }
RUBY
end
end

it 'accepts braces surrounded by spaces' do
expect_no_offenses('each { puts }')
end
Expand Down

0 comments on commit 0d09460

Please sign in to comment.