Sha256: ed79c42b930905f79c044b2487250a833c1ebf6efb60caa50584950bdf4fe5a5
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 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 = self.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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reek-1.3.8 | lib/reek/smells/long_yield_list.rb |
reek-1.3.7 | lib/reek/smells/long_yield_list.rb |