Sha256: 266b960e5fdc549c6a782fc587484d8be9b520140d59fa82fd9eacfb59acff2a
Contents?: true
Size: 667 Bytes
Versions: 4
Compression:
Stored size: 667 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop class VariableInterpolation < Cop MSG = 'Replace interpolated var %s with expression #{%s}.' 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 private def var_nodes(nodes) nodes.select { |n| [:ivar, :cvar, :gvar, :nth_ref].include?(n.type) } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems