Sha256: 7c4230ecf4a67fc83b6d3ec2782518d1200dda6d38d8a7cf25953b23326b32fe
Contents?: true
Size: 825 Bytes
Versions: 5
Compression:
Stored size: 825 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Lint # This cop checks for unreachable code. # The check are based on the presence of flow of control # statement in non-final position in *begin*(implicit) blocks. class UnreachableCode < Cop MSG = 'Unreachable code detected.' NODE_TYPES = [:return, :next, :break, :retry, :redo] FLOW_COMMANDS = [:throw, :raise, :fail] def on_begin(node) expressions = *node expressions.each_cons(2) do |e1, e2| if NODE_TYPES.include?(e1.type) || flow_command?(e1) warning(e2, :expression) end end end private def flow_command?(node) FLOW_COMMANDS.any? { |c| command?(c, node) } end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems