Sha256: f46058c033513d8edbcb0c87b0846dece373b1be0b930c4fbbed45dba0fc015f

Contents?: true

Size: 906 Bytes

Versions: 4

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # A Manual Dispatch occurs when a method is only called after a
    # manual check that the method receiver is of the correct type.
    #
    # The +ManualDispatch+ checker reports any invocation of +respond_to?+
    #
    # See {file:docs/Manual-Dispatch.md} for details.
    class ManualDispatch < SmellDetector
      MESSAGE = 'manually dispatches method call'.freeze

      #
      # Checks for +respond_to?+ usage within the given method
      #
      # @return [Array<SmellWarning>]
      #
      # :reek:FeatureEnvy
      def sniff(ctx)
        ctx.each_node(:send).flat_map do |node|
          next unless node.name.equal?(:respond_to?)

          smell_warning(context: ctx, lines: [node.line], message: MESSAGE)
        end.compact
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reek-4.4.2 lib/reek/smells/manual_dispatch.rb
reek-4.4.1 lib/reek/smells/manual_dispatch.rb
reek-4.4.0 lib/reek/smells/manual_dispatch.rb
reek-4.3.0 lib/reek/smells/manual_dispatch.rb