class RuboCop::Cop::Style::RedundantCapitalW
Checks for usage of the %W() syntax when %w() would do.
@example
# bad %W(cat dog pig) %W[door wall floor] # good %w/swim run bike/ %w[shirt pants shoes] %W(apple #{fruit} grape)
Constants
- MSG
Public Instance Methods
on_array(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_capital_w.rb, line 23 def on_array(node) process(node, '%W') end
Private Instance Methods
on_percent_literal(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_capital_w.rb, line 29 def on_percent_literal(node) return if requires_interpolation?(node) add_offense(node) do |corrector| src = node.loc.begin.source corrector.replace(node.loc.begin, src.tr('W', 'w')) end end
requires_interpolation?(node)
click to toggle source
# File lib/rubocop/cop/style/redundant_capital_w.rb, line 38 def requires_interpolation?(node) node.child_nodes.any? do |string| string.dstr_type? || double_quotes_required?(string.source) end end