Sha256: b1e872a57bafcb42bb0fe7cd72e22f1061e0bb738473a2c5438f9ef1046ade5c
Contents?: true
Size: 987 Bytes
Versions: 3
Compression:
Stored size: 987 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 inspect(source_buffer, source, tokens, ast, comments) inspect_variables(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
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
rubocop-0.9.1 | lib/rubocop/cop/lint/unused_local_variable.rb |
sabat-rubocop-0.9.0 | lib/rubocop/cop/lint/unused_local_variable.rb |
rubocop-0.9.0 | lib/rubocop/cop/lint/unused_local_variable.rb |