Sha256: e7ec11294c64d80c93a30417fad61aac0d696ab341ef40b6feacbef3e6ed9fea
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
# encoding: utf-8 module Rubocop module Cop module Lint # This cop checks for operators, variables and literals used # in void context. class Void < Cop OP_MSG = 'Operator %s used in void context.' VAR_MSG = 'Variable %s used in void context.' LIT_MSG = 'Literal %s used in void context' OPS = %w(* / % + - == === != < > <= >= <=>) VARS = [:ivar, :lvar, :cvar, :const] LITERALS = [:str, :dstr, :int, :float, :array, :hash, :regexp, :nil, :true, :false] def on_begin(node) expressions = *node expressions.drop_last(1).each do |expr| check_for_void_op(expr) check_for_literal(expr) check_for_var(expr) end end private def check_for_void_op(node) return unless node.type == :send op = node.loc.selector.source add_offense(node, :selector, format(OP_MSG, op)) if OPS.include?(op) end def check_for_var(node) if VARS.include?(node.type) add_offense(node, :name, format(VAR_MSG, node.loc.name.source)) end end def check_for_literal(node) if LITERALS.include?(node.type) add_offense(node, :expression, format(LIT_MSG, node.loc.expression.source)) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.19.1 | lib/rubocop/cop/lint/void.rb |
rubocop-0.19.0 | lib/rubocop/cop/lint/void.rb |