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

Make Node#left_curly_brace? aware of lambda brace #272

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -355,6 +359,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

it 'returns false for non left block brace tokens' do
Expand Down