Sha256: 2a3777e3dfc70fa77be60ddd16c18b3836d12c2b4a63a25f24a612e9e8e069e5
Contents?: true
Size: 852 Bytes
Versions: 11
Compression:
Stored size: 852 Bytes
Contents
# frozen_string_literal: true 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.'.freeze NODE_TYPES = [:return, :next, :break, :retry, :redo].freeze FLOW_COMMANDS = [:throw, :raise, :fail].freeze def on_begin(node) expressions = *node expressions.each_cons(2) do |e1, e2| next unless NODE_TYPES.include?(e1.type) || flow_command?(e1) add_offense(e2, :expression) end end private def flow_command?(node) FLOW_COMMANDS.any? { |c| node.command?(c) } end end end end end
Version data entries
11 entries across 11 versions & 2 rubygems