Sha256: e0303e511ab2adfdba1966801d17b8b14350202f77d998d3dccd55555383b5ac

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require_relative 'base_detector'

module Reek
  module SmellDetectors
    #
    # A Boolean parameter effectively permits a method's caller
    # to decide which execution path to take. The
    # offending parameter is a kind of Control Couple.
    #
    # Currently Reek can only detect a Boolean parameter when it has a
    # default initializer.
    #
    # See {file:docs/Boolean-Parameter.md} for details.
    class BooleanParameter < BaseDetector
      #
      # Checks whether the given method has any Boolean parameters.
      #
      # @return [Array<SmellWarning>]
      #
      def sniff
        context.default_assignments.select do |_parameter, value|
          [:true, :false].include?(value.type)
        end.map do |parameter, _value|
          smell_warning(
            context: context,
            lines: [source_line],
            message: "has boolean parameter '#{parameter}'",
            parameters: { parameter: parameter.to_s })
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reek-4.8.2 lib/reek/smell_detectors/boolean_parameter.rb
reek-4.8.1 lib/reek/smell_detectors/boolean_parameter.rb
reek-4.8.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-4.7.3 lib/reek/smell_detectors/boolean_parameter.rb