diff --git a/changelog/change_make_token_left_curly_brace_aware_of_lambda_brace.md b/changelog/change_make_token_left_curly_brace_aware_of_lambda_brace.md new file mode 100644 index 000000000..b6352a25e --- /dev/null +++ b/changelog/change_make_token_left_curly_brace_aware_of_lambda_brace.md @@ -0,0 +1 @@ +* [#272](https://github.com/rubocop/rubocop-ast/pull/272): Make `Node#left_curly_brace?` aware of lambda brace. ([@koic][]) diff --git a/lib/rubocop/ast/token.rb b/lib/rubocop/ast/token.rb index ccf9af928..f523681e4 100644 --- a/lib/rubocop/ast/token.rb +++ b/lib/rubocop/ast/token.rb @@ -83,7 +83,7 @@ def left_brace? end def left_curly_brace? - type == :tLCURLY + type == :tLCURLY || type == :tLAMBEG end def right_curly_brace? diff --git a/spec/rubocop/ast/token_spec.rb b/spec/rubocop/ast/token_spec.rb index 65d6866b0..7ca8e92a1 100644 --- a/spec/rubocop/ast/token_spec.rb +++ b/spec/rubocop/ast/token_spec.rb @@ -319,6 +319,7 @@ def foo let(:source) { <<~RUBY } { a: 1 } foo { |f| bar(f) } + -> { f } RUBY let(:left_hash_brace_token) do @@ -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 @@ -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