Skip to content

Commit

Permalink
Revert "Remove unused code"
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoTrindade authored and bbatsov committed Dec 29, 2019
1 parent b5ea427 commit d292b31
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rubocop/ast/node/mixin/conditional_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def single_line_condition?
loc.keyword.line == condition.source_range.line
end

# Checks whether the condition of the node is written on more than
# one line.
#
# @return [Boolean] whether the condition is on more than one line
def multiline_condition?
!single_line_condition?
end

# Returns the condition of the node. This works together with each node's
# custom destructuring method to select the correct part of the node.
#
Expand Down
9 changes: 9 additions & 0 deletions lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MethodDispatchNode
extend NodePattern::Macros
include MethodIdentifierPredicates

ARITHMETIC_OPERATORS = %i[+ - * / % **].freeze
SPECIAL_MODIFIERS = %w[private protected].freeze

# The receiving node of the method dispatch.
Expand Down Expand Up @@ -152,6 +153,14 @@ def block_literal?
parent&.block_type? && eql?(parent.send_node)
end

# Checks whether this node is an arithmetic operation
#
# @return [Boolean] whether the dispatched method is an arithmetic
# operation
def arithmetic_operation?
ARITHMETIC_OPERATORS.include?(method_name)
end

# Checks if this node is part of a chain of `def` modifiers.
#
# @example
Expand Down
10 changes: 10 additions & 0 deletions lib/rubocop/cop/layout/line_length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def max
cop_config['Max']
end

def allow_heredoc?
allowed_heredoc
end

def allowed_heredoc
cop_config['AllowHeredoc']
end
Expand All @@ -207,6 +211,12 @@ def line_in_permitted_heredoc?(line_number)
end
end

def line_in_heredoc?(line_number)
heredocs.any? do |range, _delimiter|
range.cover?(line_number)
end
end

def check_directive_line(line, line_index)
return if line_length_without_directive(line) <= max

Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/ast/send_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,26 @@ module Foo
end
end

describe '#arithmetic_operation?' do
context 'with a binary arithmetic operation' do
let(:source) { 'foo + bar' }

it { expect(send_node.arithmetic_operation?).to be_truthy }
end

context 'with a unary numeric operation' do
let(:source) { '+foo' }

it { expect(send_node.arithmetic_operation?).to be_falsey }
end

context 'with a regular method call' do
let(:source) { 'foo.bar' }

it { expect(send_node.arithmetic_operation?).to be_falsey }
end
end

describe '#block_node' do
context 'with a block literal' do
let(:send_node) { parse_source(source).ast.children[0] }
Expand Down

0 comments on commit d292b31

Please sign in to comment.