Class: Reek::Smells::ModuleInitialize

Inherits:
SmellDetector show all
Defined in:
lib/reek/smells/module_initialize.rb

Overview

a module is usually a mixin, so when initialize method is present it is hard to tell initialization order and parameters so having 'initialize' in a module is usually a bad idea

Constant Summary

Constants inherited from SmellDetector

SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from SmellDetector

#smell_category, #smell_type, #smells_found, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SmellDetector

#config_for, #configure_with, default_config, default_smell_category, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_category, smell_type, #value

Constructor Details

This class inherits a constructor from Reek::Smells::SmellDetector

Class Method Details

.contextsObject

:nodoc:


12
13
14
# File 'lib/reek/smells/module_initialize.rb', line 12

def self.contexts # :nodoc:
  [:module]
end

Instance Method Details

#examine_context(module_ctx) ⇒ Array<SmellWarning>

Checks whether module has method 'initialize'.


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/reek/smells/module_initialize.rb', line 21

def examine_context(module_ctx)
  module_ctx.local_nodes(:def) do |node| # FIXME: also search for :defs?
    if node.name.to_s == 'initialize'
      return [
        SmellWarning.new(self, context: module_ctx.full_name,
                               lines:   [module_ctx.exp.line],
                               message: 'has initialize method')
      ]
    end
  end
  []
end