Skip to content

Commit

Permalink
[Fix rubocop#12374] Fix a false positive for `Layout/SpaceBeforeSemic…
Browse files Browse the repository at this point in the history
…olon`

Fixes rubocop#12374.

This PR fixes a false positive for `Layout/SpaceBeforeSemicolon`
when a space between an opening lambda brace and a semicolon.

NOTE: When `Token#left_curly_brace?` supports `:tLAMBEG`,
the condition `token.type == :tLAMBEG` can be removed.
  • Loading branch information
koic committed Nov 9, 2023
1 parent 2d48430 commit 2a056d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12374](https://github.com/rubocop/rubocop/issues/12374): Fix a false positive for `Layout/SpaceBeforeSemicolon` when a space between an opening lambda brace and a semicolon. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/space_before_punctuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def space_missing?(token1, token2)
end

def space_required_after?(token)
token.left_curly_brace? && space_required_after_lcurly?
(token.left_curly_brace? || token.type == :tLAMBEG) && space_required_after_lcurly?
end

def space_required_after_lcurly?
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/layout/space_before_semicolon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
it 'accepts a space between an opening brace and a semicolon' do
expect_no_offenses('test { ; }')
end

it 'accepts a space between an opening lambda brace and a semicolon' do
expect_no_offenses('-> { ; }')
end
end

context 'when EnforcedStyle for SpaceInsideBlockBraces is no_space' do
Expand Down

0 comments on commit 2a056d2

Please sign in to comment.