Sha256: f7284628d566a91cd04858a055828de3f7d3233037ad725e39374e74b56b4ff9
Contents?: true
Size: 1.51 KB
Versions: 3
Compression:
Stored size: 1.51 KB
Contents
require 'reek/smells/smell_detector' require 'reek/smell_warning' module Reek module Smells # # A variant on LongParameterList that checks the number of items # passed to a block by a +yield+ call. # class LongYieldList < SmellDetector SMELL_CLASS = 'LongParameterList' SMELL_SUBCLASS = name.split(/::/)[-1] # The name of the config field that sets the maximum number of # parameters permitted in any method or block. MAX_ALLOWED_PARAMS_KEY = 'max_params' # The default value of the +MAX_ALLOWED_PARAMS_KEY+ configuration # value. DEFAULT_MAX_ALLOWED_PARAMS = 3 PARAMETER_COUNT_KEY = 'parameter_count' def self.default_config super.merge( MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS ) end # # Checks the number of parameters in the given scope. # # @return [Array<SmellWarning>] # def examine_context(method_ctx) @max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, method_ctx, DEFAULT_MAX_ALLOWED_PARAMS) method_ctx.local_nodes(:yield).select do |yield_node| yield_node.args.length > @max_allowed_params end.map do |yield_node| num_params = yield_node.args.length SmellWarning.new(SMELL_CLASS, method_ctx.full_name, [yield_node.line], "yields #{num_params} parameters", @source, SMELL_SUBCLASS, PARAMETER_COUNT_KEY => num_params) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
reek-1.5.1 | lib/reek/smells/long_yield_list.rb |
reek-1.5.0 | lib/reek/smells/long_yield_list.rb |
reek-1.4.0 | lib/reek/smells/long_yield_list.rb |