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 Layout/SpaceInsideBlockBraces for blocks with numbered arguments #10736

Merged
merged 1 commit into from Jun 22, 2022
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
@@ -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