From a0e6a6f8e72d415740b67f7d80b7d155d34c3bd7 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Sat, 18 Jul 2020 01:45:11 -0400 Subject: [PATCH] Fix LambdaNode (modern) --- lib/rubocop/ast/node/lambda_node.rb | 11 ++++++++--- spec/rubocop/ast/lambda_spec.rb | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 spec/rubocop/ast/lambda_spec.rb diff --git a/lib/rubocop/ast/node/lambda_node.rb b/lib/rubocop/ast/node/lambda_node.rb index b6d697cb0..ce7b72a22 100644 --- a/lib/rubocop/ast/node/lambda_node.rb +++ b/lib/rubocop/ast/node/lambda_node.rb @@ -21,7 +21,7 @@ module AST # The main RuboCop runs in legacy mode; this node is only used # if user `AST::Builder.modernize` or `AST::Builder.emit_lambda=true` class LambdaNode < Node - include ParameterizedNode + include ParameterizedTrailNode include MethodDispatchNode # For similarity with legacy mode @@ -44,14 +44,19 @@ def assignment_method? false end + # For similarity with legacy mode + def receiver + nil + end + # For similarity with legacy mode def method_name :lambda end # For similarity with legacy mode - def arguments - [] + def first_argument_index + 2 end end end diff --git a/spec/rubocop/ast/lambda_spec.rb b/spec/rubocop/ast/lambda_spec.rb new file mode 100644 index 000000000..aa7082a3b --- /dev/null +++ b/spec/rubocop/ast/lambda_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Note: specs for `lambda?` and `lambda_literal?` in `send_node_spec` +RSpec.describe RuboCop::AST::LambdaNode do + let(:source) { '->(a, b) { a + b }' } + subject(:lambda_node) { parse_source(source).ast } + + describe '#receiver' do + it { expect(lambda_node.receiver).to eq nil } + end + + describe '#method_name' do + it { expect(lambda_node.method_name).to eq :lambda } + end + + describe '#arguments' do + it { expect(lambda_node.arguments.size).to eq 2 } + end +end