class Rubocop::Cop::Lint::Void

This cop checks for operators, variables and literals used in void context.

Constants

LITERALS
LIT_MSG
OPS
OP_MSG
VARS
VAR_MSG

Public Instance Methods

on_begin(node) click to toggle source
Calls superclass method
# File lib/rubocop/cop/lint/void.rb, line 18
def on_begin(node)
  expressions = *node

  expressions[0...-1].each do |expr|
    check_for_void_op(expr)
    check_for_literal(expr)
    check_for_var(expr)
  end

  super
end

Private Instance Methods

check_for_literal(node) click to toggle source
# File lib/rubocop/cop/lint/void.rb, line 49
def check_for_literal(node)
  if LITERALS.include?(node.type)
    add_offence(:warning, node.loc.expression,
                sprintf(LIT_MSG, node.loc.expression.source))
  end
end
check_for_var(node) click to toggle source
# File lib/rubocop/cop/lint/void.rb, line 42
def check_for_var(node)
  if VARS.include?(node.type)
    add_offence(:warning, node.loc.name,
                sprintf(VAR_MSG, node.loc.name.source))
  end
end
check_for_void_op(node) click to toggle source
# File lib/rubocop/cop/lint/void.rb, line 32
def check_for_void_op(node)
  return unless node.type == :send

  op = node.loc.selector.source

  if OPS.include?(op)
    add_offence(:warning, node.loc.selector, sprintf(OP_MSG, op))
  end
end