Sha256: b2d15d1c20a4e5acd16731e9a6a96a92d5b4ccf46456b3eb6888cc52004162b9

Contents?: true

Size: 870 Bytes

Versions: 14

Compression:

Stored size: 870 Bytes

Contents

# encoding: utf-8
# 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

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/lint/unreachable_code.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.43.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.42.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.41.2 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.41.1 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.41.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.40.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.39.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.38.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.37.2 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.37.1 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.37.0 lib/rubocop/cop/lint/unreachable_code.rb
rubocop-0.36.0 lib/rubocop/cop/lint/unreachable_code.rb