Sha256: 513ba4a866e5cf0ca7b22e4a844a79cf8967c5ced9331584de71f519eae6a71e
Contents?: true
Size: 1.22 KB
Versions: 8
Compression:
Stored size: 1.22 KB
Contents
require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector') require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), '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. # class BooleanParameter < SmellDetector SMELL_CLASS = 'ControlCouple' SMELL_SUBCLASS = self.name.split(/::/)[-1] PARAMETER_KEY = 'parameter' # # Checks whether the given method has any Boolean parameters. # # @return [Array<SmellWarning>] # def examine_context(method_ctx) method_ctx.parameters.default_assignments.select do |param, value| [:true, :false].include?(value[0]) end.map do |param, value| SmellWarning.new(SMELL_CLASS, method_ctx.full_name, [method_ctx.exp.line], "has boolean parameter '#{param.to_s}'", @source, SMELL_SUBCLASS, {PARAMETER_KEY => param.to_s}) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems