Class: Rubocop::Cop::VariableInterpolation
- Defined in:
- lib/rubocop/cop/variable_interpolation.rb
Constant Summary collapse
- MSG =
'Replace interpolated var %s with expression #{%s}.'
Instance Attribute Summary
Attributes inherited from Cop
#debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#on_dstr(node) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubocop/cop/variable_interpolation.rb', line 8 def on_dstr(node) var_nodes(node.children).each do |v| var = (v.type == :nth_ref ? '$' : '') + v.to_a[0].to_s if node.loc.expression.source.include?("##{var}") add_offence(:convention, v.loc.line, sprintf(MSG, var, var)) end end super end |