Sha256: 8766b303c4a04b70c7f7bc3b857cd19d343e8bab0071119236c99a9768b1fa89
Contents?: true
Size: 846 Bytes
Versions: 4
Compression:
Stored size: 846 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) add_offence(:warning, e2.loc.expression, MSG) end end end private def flow_command?(node) FLOW_COMMANDS.any? { |c| command?(c, node) } end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems