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-6.4.0 lib/reek/smell_detectors/module_initialize.rb
reek-6.3.0 lib/reek/smell_detectors/module_initialize.rb
reek-6.2.0 lib/reek/smell_detectors/module_initialize.rb
reek-6.1.4 lib/reek/smell_detectors/module_initialize.rb
reek-6.1.3 lib/reek/smell_detectors/module_initialize.rb
reek-6.1.2 lib/reek/smell_detectors/module_initialize.rb
reek-6.1.1 lib/reek/smell_detectors/module_initialize.rb
reek-6.1.0 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.6 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.5 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.4 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.3 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.2 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.1 lib/reek/smell_detectors/module_initialize.rb
reek-6.0.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.6.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.5.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.4.1 lib/reek/smell_detectors/module_initialize.rb
reek-5.4.0 lib/reek/smell_detectors/module_initialize.rb
reek-5.3.2 lib/reek/smell_detectors/module_initialize.rb