Sha256: d46c049cf86d5e0f40d743f3ba0b77f01e5c3536fb76cf1b8c3392a8bce6e564

Contents?: true

Size: 997 Bytes

Versions: 18

Compression:

Stored size: 997 Bytes

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(
            lines: [source_line],
            message: "has boolean parameter '#{parameter}'",
            parameters: { parameter: parameter.to_s })
        end
      end
    end
  end
end

Version data entries

18 entries across 16 versions & 2 rubygems

Version Path
reek-6.0.1 lib/reek/smell_detectors/boolean_parameter.rb
reek-6.0.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.6.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.5.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.4.1 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.4.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.3.2 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.3.1 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.3.0 lib/reek/smell_detectors/boolean_parameter.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/boolean_parameter.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/boolean_parameter.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/boolean_parameter.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/boolean_parameter.rb
reek-5.2.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.1.0 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.0.2 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.0.1 lib/reek/smell_detectors/boolean_parameter.rb
reek-5.0.0 lib/reek/smell_detectors/boolean_parameter.rb