lib/rubocop/cop/lint/format_parameter_mismatch.rb in rubocop-1.43.0 vs lib/rubocop/cop/lint/format_parameter_mismatch.rb in rubocop-1.44.0
- old
+ new
@@ -92,12 +92,12 @@
end
end
# @!method called_on_string?(node)
def_node_matcher :called_on_string?, <<~PATTERN
- {(send {nil? const_type?} _ (str _) ...)
- (send (str ...) ...)}
+ {(send {nil? const_type?} _ {str dstr} ...)
+ (send {str dstr} ...)}
PATTERN
def method_with_format_args?(node)
sprintf?(node) || format?(node) || percent?(node)
end
@@ -141,15 +141,15 @@
def format_method?(name, node)
return false if node.const_receiver? && !node.receiver.loc.name.is?(KERNEL)
return false unless node.method?(name)
- node.arguments.size > 1 && node.first_argument.str_type?
+ node.arguments.size > 1 && string_type?(node.first_argument)
end
def expected_fields_count(node)
- return :unknown unless node.str_type?
+ return :unknown unless string_type?(node)
format_string = RuboCop::Cop::Utils::FormatString.new(node.source)
return 1 if format_string.named_interpolation?
max_digit_dollar_num = format_string.max_digit_dollar_num
@@ -170,14 +170,13 @@
end
def percent?(node)
receiver = node.receiver
- percent = node.method?(:%) &&
- (STRING_TYPES.include?(receiver.type) || node.first_argument.array_type?)
+ percent = node.method?(:%) && (string_type?(receiver) || node.first_argument.array_type?)
- return false if percent && STRING_TYPES.include?(receiver.type) && heredoc?(node)
+ return false if percent && string_type?(receiver) && heredoc?(node)
percent
end
def message(node)
@@ -185,9 +184,13 @@
method_name = node.method?(:%) ? 'String#%' : node.method_name
format(MSG, arg_num: num_args_for_format, method: method_name,
field_num: num_expected_fields)
+ end
+
+ def string_type?(node)
+ STRING_TYPES.include?(node.type)
end
end
end
end
end