Sha256: b57cffc55320f06de8f8ca08ea55084f3f61557835ba04165102a4642a179ac0

Contents?: true

Size: 920 Bytes

Versions: 2

Compression:

Stored size: 920 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Lint
      # This cop looks for use of the same name as outer local variables
      # for block arguments or block local variables.
      # This is a mimic of the warning
      # "shadowing outer local variable - foo" from `ruby -cw`.
      class ShadowingOuterLocalVariable < Cop
        include VariableInspector

        MSG = 'Shadowing outer local variable - `%s`'

        def investigate(processed_source)
          inspect_variables(processed_source.ast)
        end

        def before_declaring_variable(variable)
          return if variable.name.to_s.start_with?('_')

          outer_local_variable = variable_table.find_variable(variable.name)
          return unless outer_local_variable

          message = format(MSG, variable.name)
          add_offense(variable.declaration_node, :expression, message)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.20.1 lib/rubocop/cop/lint/shadowing_outer_local_variable.rb
rubocop-0.20.0 lib/rubocop/cop/lint/shadowing_outer_local_variable.rb