Skip to content

Commit

Permalink
Add range_type? which means irange_type? and erange_type?
Browse files Browse the repository at this point in the history
Follow up of rubocop#6126 (comment).

This PR adds `range_type?` method which means both
`irange_type?` method and `erange_type?` method.
  • Loading branch information
koic committed Feb 17, 2019
1 parent 333d650 commit 4105b22
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ def numeric_type?
int_type? || float_type?
end

def range_type?
irange_type? || erange_type?
end

def_node_matcher :guard_clause?, <<-PATTERN
[{(send nil? {:raise :fail} ...) return break next} single_line?]
PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/correctors/for_to_each_corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def collection_source
end

def requires_parentheses?
collection_node.irange_type? || collection_node.erange_type?
collection_node.range_type?
end

def end_position
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/block_delimiters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def conditional?(node)
end

def array_or_range?(node)
node.array_type? || node.irange_type? || node.erange_type?
node.array_type? || node.range_type?
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/style/method_call_with_args_parentheses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,14 @@ def legitimate_call_with_parentheses?(node)
allowed_chained_call_with_parentheses?(node)
end

# rubocop:disable Metrics/CyclomaticComplexity
def call_in_literals?(node)
node.parent &&
(node.parent.pair_type? ||
node.parent.array_type? ||
node.parent.irange_type? || node.parent.erange_type? ||
node.parent.range_type? ||
splat?(node.parent) ||
ternary_if?(node.parent))
end
# rubocop:enable Metrics/CyclomaticComplexity

def call_in_logical_operators?(node)
node.parent &&
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/style/mutable_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def frozen_string_literal?(node)
end

def requires_parentheses?(node)
node.irange_type? ||
node.erange_type? ||
node.range_type? ||
(node.send_type? && node.loc.dot.nil?)
end

Expand Down
3 changes: 3 additions & 0 deletions spec/rubocop/ast/range_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
end

it { expect(range_node.is_a?(described_class)).to be(true) }
it { expect(range_node.range_type?).to be(true) }
end

context 'with an exclusive range' do
Expand All @@ -18,6 +19,7 @@
end

it { expect(range_node.is_a?(described_class)).to be(true) }
it { expect(range_node.range_type?).to be(true) }
end

context 'with an infinite range' do
Expand All @@ -27,6 +29,7 @@
end

it { expect(range_node.is_a?(described_class)).to be(true) }
it { expect(range_node.range_type?).to be(true) }
end
end
end

0 comments on commit 4105b22

Please sign in to comment.