Sha256: 2936d1b6417a251b651c502d620ec18f0b7baedeb2ad93406efaa0ce94631ce6

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # 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 < SmellDetector
      def self.smell_category
        'ControlCouple'
      end

      #
      # Checks whether the given method has any Boolean parameters.
      #
      # @return [Array<SmellWarning>]
      #
      # :reek:FeatureEnvy
      def inspect(ctx)
        ctx.default_assignments.select do |_param, value|
          [:true, :false].include?(value.type)
        end.map do |parameter, _value|
          smell_warning(
            context: ctx,
            lines: [ctx.exp.line],
            message: "has boolean parameter '#{parameter}'",
            parameters: { name: parameter.to_s })
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
reek-3.11 lib/reek/smells/boolean_parameter.rb
reek-3.10.2 lib/reek/smells/boolean_parameter.rb
reek-3.10.1 lib/reek/smells/boolean_parameter.rb
reek-3.10.0 lib/reek/smells/boolean_parameter.rb
reek-3.9.1 lib/reek/smells/boolean_parameter.rb
reek-3.9.0 lib/reek/smells/boolean_parameter.rb
reek-3.8.3 lib/reek/smells/boolean_parameter.rb
reek-3.8.2 lib/reek/smells/boolean_parameter.rb
reek-3.8.1 lib/reek/smells/boolean_parameter.rb
reek-3.8.0 lib/reek/smells/boolean_parameter.rb
reek-3.7.1 lib/reek/smells/boolean_parameter.rb
reek-3.7.0 lib/reek/smells/boolean_parameter.rb
reek-3.6.1 lib/reek/smells/boolean_parameter.rb