Sha256: a190219049d83c5a9515db6b28de5d0e45c16d56b12b43c67ecc551b97598c94

Contents?: true

Size: 882 Bytes

Versions: 31

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require_relative 'base_detector'

module Reek
  module SmellDetectors
    #
    # 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
    #
    # See {file:docs/Module-Initialize.md} for details.
    class ModuleInitialize < BaseDetector
      def self.contexts # :nodoc:
        [:module]
      end

      #
      # Checks whether module has method 'initialize'.
      #
      # @return [Array<SmellWarning>]
      #
      def sniff
        context.defined_instance_methods.each do |node|
          if node.name == :initialize
            return smell_warning(
              lines:   [source_line],
              message: 'has initialize method')
          end
        end
        []
      end
    end
  end
end

Version data entries

31 entries across 29 versions & 2 rubygems

Version Path
reek-5.3.1 lib/reek/smell_detectors/module_initialize.rb
reek-5.3.0 lib/reek/smell_detectors/module_initialize.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/module_initialize.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/module_initialize.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/module_initialize.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/smell_detectors/module_initialize.rb
reek-5.2.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.1.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.0.2 lib/reek/smell_detectors/module_initialize.rb
reek-5.0.1 lib/reek/smell_detectors/module_initialize.rb
reek-5.0.0 lib/reek/smell_detectors/module_initialize.rb