class RuboCop::Cop::Style::FormatString
argument is an array literal.
if the first argument is a string literal and if the second
manner for all cases, so only two scenarios are considered -
The detection of String#% cannot be implemented in a reliable
Valid options include Kernel#format, Kernel#sprintf and String#%.
This cop enforces the use of a single string formatting utility.
def message(detected_style)
def message(detected_style) format(MSG, method_name(style), method_name(detected_style)) end
def method_name(style_name)
def method_name(style_name) style_name == :percent ? 'String#%' : style_name end
def on_send(node)
def on_send(node) return unless (selector = formatter(node)) detected_style = selector == :% ? :percent : selector return if detected_style == style add_offense(node, :selector, message(detected_style)) end