Sha256: 130228e824ec40869d84a93317a70668fbee86cd70ab91b7e6119ddf81cf3a5f
Contents?: true
Size: 717 Bytes
Versions: 2
Compression:
Stored size: 717 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Style # This cop checks for variable interpolation (like "#@ivar"). 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_offense(v, :expression, format(MSG, var, var)) end end end private def var_nodes(nodes) nodes.select { |n| [:ivar, :cvar, :gvar, :nth_ref].include?(n.type) } end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.19.1 | lib/rubocop/cop/style/variable_interpolation.rb |
rubocop-0.19.0 | lib/rubocop/cop/style/variable_interpolation.rb |