Class: CustomCops::VariableNameShadowingMethod

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/simplycop/custom_cops/variable_name_shadowing_method.rb

Instance Method Summary collapse

Instance Method Details

#on_lvasgn(node) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/simplycop/custom_cops/variable_name_shadowing_method.rb', line 23

def on_lvasgn(node)
  if @declared_method_names.include?(node.name)
    add_offense(
      node,
      message: "Shadowing method name - `#{node.name}`."
    )
  end
end

#on_new_investigationObject



18
19
20
21
# File 'lib/simplycop/custom_cops/variable_name_shadowing_method.rb', line 18

def on_new_investigation
  ast = processed_source.ast
  @declared_method_names = ast ? method_names(processed_source.ast).to_a : []
end