class Reek::SmellDetectors::UnusedPrivateMethod
Classes should use their private methods. Otherwise this is dead code which is confusing and bad for maintenance.
See {file:docs/Unused-Private-Method.md} for details.
Public Class Methods
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 30 def self.contexts [:class] end
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 14 def self.default_config super.merge(SmellConfiguration::ENABLED_KEY => false) end
Calls superclass method
Reek::SmellDetectors::BaseDetector::default_config
Public Instance Methods
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 37 def sniff hits.map do |hit| name = hit.name smell_warning( lines: [hit.line], message: "has the unused private instance method '#{name}'", parameters: { name: name.to_s }) end end
@return [Array<SmellWarning>]
Private Instance Methods
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 52 def hits unused_private_methods.filter_map do |defined_method| Hit.new(defined_method) unless ignore_method?(defined_method) end end
@return [Array<Hit>]
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 75 def ignore_method?(method) # ignore_contexts will be e.g. ["Foo::Smelly#my_method", "..."] ignore_contexts = value(EXCLUDE_KEY, context) ignore_contexts.any? do |ignore_context| full_name = "#{method.parent.full_name}##{method.name}" full_name[ignore_context] end end
@param method [Context::MethodContext] @return [Boolean]
Source
# File lib/reek/smell_detectors/unused_private_method.rb, line 61 def unused_private_methods defined_private_methods = context.defined_instance_methods(visibility: :private) called_method_names = context.instance_method_calls.map(&:name) called_method_names.concat(context.instance_method_names_via_to_call) defined_private_methods.reject do |defined_method| called_method_names.include?(defined_method.name) end end
@return [Array<Context::MethodContext]