class RuboCop::Cop::Lint::UnderscorePrefixedVariableName
This cop checks for underscore-prefixed variables that are actually used.
Constants
- MSG
Public Instance Methods
after_leaving_scope(scope, _variable_table)
click to toggle source
# File lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb, line 15 def after_leaving_scope(scope, _variable_table) scope.variables.each_value do |variable| check_variable(variable) end end
check_variable(variable)
click to toggle source
# File lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb, line 21 def check_variable(variable) return unless variable.should_be_unused? return if variable.references.empty? return if variable.references.none?(&:explicit?) node = variable.declaration_node location = if node.type == :match_with_lvasgn node.children.first.source_range else node.loc.name end add_offense(nil, location) end
join_force?(force_class)
click to toggle source
# File lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb, line 11 def join_force?(force_class) force_class == VariableForce end