Skip to content

Commit

Permalink
Make Node#left_curly_brace? aware of lambda brace
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop#12376.

This PR makes `Node#left_curly_brace?` aware of lambda brace (`-> {f}`).
  • Loading branch information
koic authored and bbatsov committed Feb 25, 2024
1 parent 736e033 commit 49b135b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
@@ -0,0 +1 @@
* [#272](https://github.com/rubocop/rubocop-ast/pull/272): Make `Node#left_curly_brace?` aware of lambda brace. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/ast/token.rb
Expand Up @@ -83,7 +83,7 @@ def left_brace?
end

def left_curly_brace?
type == :tLCURLY
type == :tLCURLY || type == :tLAMBEG
end

def right_curly_brace?
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/ast/token_spec.rb
Expand Up @@ -319,6 +319,7 @@ def foo
let(:source) { <<~RUBY }
{ a: 1 }
foo { |f| bar(f) }
-> { f }
RUBY

let(:left_hash_brace_token) do
Expand All @@ -331,6 +332,9 @@ def foo
let(:left_block_brace_token) do
processed_source.find_token { |t| t.text == '{' && t.line == 2 }
end
let(:left_lambda_brace_token) do
processed_source.find_token { |t| t.text == '{' && t.line == 3 }
end
let(:left_parens_token) do
processed_source.find_token { |t| t.text == '(' }
end
Expand All @@ -357,6 +361,7 @@ def foo
describe '#left_curly_brace?' do
it 'returns true for left block brace tokens' do
expect(left_block_brace_token).to be_left_curly_brace
expect(left_lambda_brace_token).to be_left_curly_brace
end

# FIXME: `broken_on: :prism` can be removed when
Expand Down

0 comments on commit 49b135b

Please sign in to comment.