lib/reek/smells/smell_detector.rb in reek-1.2.7.3 vs lib/reek/smells/smell_detector.rb in reek-1.2.8
- old
+ new
@@ -27,11 +27,11 @@
# The default value for the +EXCLUDE_KEY+ if it isn't specified
# in any configuration file.
DEFAULT_EXCLUDE_SET = []
class << self
- def contexts # :nodoc:
+ def contexts
[:defn, :defs]
end
def default_config
{
@@ -44,11 +44,11 @@
attr_reader :smells_found # SMELL: only published for tests
def initialize(source, config = self.class.default_config)
@source = source
@config = Core::SmellConfiguration.new(config)
- @smells_found = Set.new
+ @smells_found = []
end
def register(hooks)
return unless @config.enabled?
self.class.contexts.each { |ctx| hooks[ctx] << self }
@@ -62,34 +62,34 @@
def configure_with(config)
@config.adopt!(config)
end
def examine(context)
- examine_context(context) if @config.enabled? and !exception?(context)
+ enabled = @config.enabled? && config_for(context)[Core::SmellConfiguration::ENABLED_KEY] != false
+ if enabled && !exception?(context)
+ sm = examine_context(context)
+ @smells_found += sm
+ end
end
def examine_context(context)
end
def exception?(context)
context.matches?(value(EXCLUDE_KEY, context, DEFAULT_EXCLUDE_SET))
end
- def found(context, message, subclass = '', parameters = {}, lines = nil)
- lines ||= [context.exp.line] # SMELL: nil?!?!?! Yuk
- smell = SmellWarning.new(self.class.name.split(/::/)[-1], context.full_name,
- lines, message,
- @source, subclass, parameters)
- @smells_found << smell
- smell
- end
-
def report_on(report)
@smells_found.each { |smell| smell.report_on(report) }
end
def value(key, ctx, fall_back)
- @config.value(key, ctx, fall_back)
+ config_for(ctx)[key] || @config.value(key, ctx, fall_back)
+ end
+
+ def config_for(ctx)
+ ctx.config[self.class.name.split(/::/)[-1]] || {}
+ # BUG: needs to consider smell class AND subclass
end
end
end
end