Sha256: 59db482efbe880b4cad59c586840d3e0af67dfe6f0123f8fb322292a27174588

Contents?: true

Size: 966 Bytes

Versions: 11

Compression:

Stored size: 966 Bytes

Contents

require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # 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 < SmellDetector
      def self.contexts # :nodoc:
        [:module]
      end

      #
      # Checks whether module has method 'initialize'.
      #
      # @return [Array<SmellWarning>]
      #
      # :reek:FeatureEnvy
      def inspect(ctx)
        ctx.local_nodes(:def) do |node|
          if node.name.to_s == 'initialize'
            return [
              smell_warning(
                context: ctx,
                lines:   [ctx.exp.line],
                message: 'has initialize method')
            ]
          end
        end
        []
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reek-3.11 lib/reek/smells/module_initialize.rb
reek-3.10.2 lib/reek/smells/module_initialize.rb
reek-3.10.1 lib/reek/smells/module_initialize.rb
reek-3.10.0 lib/reek/smells/module_initialize.rb
reek-3.9.1 lib/reek/smells/module_initialize.rb
reek-3.9.0 lib/reek/smells/module_initialize.rb
reek-3.8.3 lib/reek/smells/module_initialize.rb
reek-3.8.2 lib/reek/smells/module_initialize.rb
reek-3.8.1 lib/reek/smells/module_initialize.rb
reek-3.8.0 lib/reek/smells/module_initialize.rb
reek-3.7.1 lib/reek/smells/module_initialize.rb