Sha256: 5ee2d85c6aef14d9801f7ca06411a5ccd52b2541a896534b698981bc3003e324
Contents?: true
Size: 980 Bytes
Versions: 4
Compression:
Stored size: 980 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Lint # This cop looks for unused local variables in each scope. # Actually this is a mimic of the warning # "assigned but unused variable - foo" from `ruby -cw`. class UnusedLocalVariable < Cop include VariableInspector MSG = 'Assigned but unused variable - %s' TYPES_TO_ACCEPT_UNUSED = (ARGUMENT_DECLARATION_TYPES - [:shadowarg]).freeze def investigate(processed_source) inspect_variables(processed_source.ast) end def after_leaving_scope(scope) scope.variable_entries.each_value do |entry| next if entry.used? next if TYPES_TO_ACCEPT_UNUSED.include?(entry.node.type) next if entry.name.to_s.start_with?('_') message = sprintf(MSG, entry.name) add_offence(:warning, entry.node.loc.expression, message) end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems