From ee7cb9021a7144b20c0a663c3456989f9c55e69a Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 29 Apr 2019 18:59:40 -0500 Subject: [PATCH] Refactor with `range_type` Follow up #6773. This PR refactors with `range_type`. --- lib/rubocop/cop/style/redundant_parentheses.rb | 4 +--- lib/rubocop/cop/style/sample.rb | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/rubocop/cop/style/redundant_parentheses.rb b/lib/rubocop/cop/style/redundant_parentheses.rb index 45eae8e1058..a555c958e00 100644 --- a/lib/rubocop/cop/style/redundant_parentheses.rb +++ b/lib/rubocop/cop/style/redundant_parentheses.rb @@ -16,8 +16,6 @@ module Style class RedundantParentheses < Cop include Parentheses - ALLOWED_LITERALS = %i[irange erange].freeze - def_node_matcher :square_brackets?, '(send {(send _recv _msg) str array hash} :[] ...)' def_node_matcher :range_end?, '^^{irange erange}' @@ -158,7 +156,7 @@ def only_closing_paren_before_comma?(node) def disallowed_literal?(begin_node, node) node.literal? && - !ALLOWED_LITERALS.include?(node.type) && + !node.range_type? && !raised_to_power_negative_numeric?(begin_node, node) end diff --git a/lib/rubocop/cop/style/sample.rb b/lib/rubocop/cop/style/sample.rb index 6141c01b6d8..3b4a85748bf 100644 --- a/lib/rubocop/cop/style/sample.rb +++ b/lib/rubocop/cop/style/sample.rb @@ -77,10 +77,9 @@ def sample_size(method_args) end def sample_size_for_one_arg(arg) - case arg.type - when :erange, :irange + if arg.range_type? range_size(arg) - when :int + elsif arg.int_type? [0, -1].include?(arg.to_a.first) ? nil : :unknown else :unknown