Skip to content

Commit

Permalink
Refactor smell detector organisation
Browse files Browse the repository at this point in the history
* Changes the namespace of smell detectors from "smells" to "smell_detectors"
  and renames everything that comes with it
* Renames "SmellDetector" to "BaseDetector"
  • Loading branch information
troessner committed Oct 3, 2016
1 parent d5095e6 commit c9bea17
Show file tree
Hide file tree
Showing 83 changed files with 273 additions and 273 deletions.
2 changes: 1 addition & 1 deletion ataru_setup.rb
@@ -1,5 +1,5 @@
require 'reek'
require 'reek/smells'
require 'reek/smell_detectors'

# Ataru setup module.
module Setup
Expand Down
2 changes: 1 addition & 1 deletion docs/API.md
Expand Up @@ -144,7 +144,7 @@ Instead of the smell detector names you can also use the full detector class in
your configuration hash, for example:

```ruby
config_hash = { Reek::Smells::IrresponsibleModule => { 'enabled' => false } }
config_hash = { Reek::SmellDetectors::IrresponsibleModule => { 'enabled' => false } }
```

Of course, directory specific configuration and excluded paths are supported as
Expand Down
4 changes: 2 additions & 2 deletions lib/reek/code_comment.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'yaml'
require_relative 'smells/smell_detector'
require_relative 'smell_detectors/base_detector'
require_relative 'errors/bad_detector_in_comment_error'
require_relative 'errors/bad_detector_configuration_in_comment_error'

Expand Down Expand Up @@ -38,7 +38,7 @@ def initialize(comment:, line: nil, source: nil)
@config = Hash.new { |hash, key| hash[key] = {} }

@original_comment.scan(CONFIGURATION_REGEX) do |detector, _option_string, options|
escalate_bad_detector(detector) unless Smells::SmellDetector.valid_detector?(detector)
escalate_bad_detector(detector) unless SmellDetectors::BaseDetector.valid_detector?(detector)

begin
parsed_options = YAML.load(options || DISABLE_DETECTOR_CONFIGURATION)
Expand Down
4 changes: 2 additions & 2 deletions lib/reek/configuration/configuration_validator.rb
Expand Up @@ -14,7 +14,7 @@ def smell_type?(key)
true
when String
begin
Reek::Smells.const_defined? key
Reek::SmellDetectors.const_defined? key
rescue NameError
false
end
Expand All @@ -27,7 +27,7 @@ def key_to_smell_detector(key)
when Class
key
else
Reek::Smells.const_get key
Reek::SmellDetectors.const_get key
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/reek/examiner.rb
Expand Up @@ -3,7 +3,7 @@
require_relative 'source/source_code'
require_relative 'errors/bad_detector_in_comment_error'
require_relative 'errors/bad_detector_configuration_in_comment_error'
require_relative 'smells/detector_repository'
require_relative 'smell_detectors/detector_repository'

module Reek
#
Expand Down Expand Up @@ -57,7 +57,7 @@ class Examiner
def initialize(source,
filter_by_smells: [],
configuration: Configuration::AppConfiguration.default,
detector_repository_class: Smells::DetectorRepository)
detector_repository_class: SmellDetectors::DetectorRepository)
@source = Source::SourceCode.from(source)
@smell_types = detector_repository_class.eligible_smell_types(filter_by_smells)
@detector_repository = detector_repository_class.new(smell_types: @smell_types,
Expand Down
30 changes: 30 additions & 0 deletions lib/reek/smell_detectors.rb
@@ -0,0 +1,30 @@
# frozen_string_literal: true
require_relative 'smell_detectors/attribute'
require_relative 'smell_detectors/boolean_parameter'
require_relative 'smell_detectors/class_variable'
require_relative 'smell_detectors/control_parameter'
require_relative 'smell_detectors/data_clump'
require_relative 'smell_detectors/duplicate_method_call'
require_relative 'smell_detectors/feature_envy'
require_relative 'smell_detectors/irresponsible_module'
require_relative 'smell_detectors/instance_variable_assumption'
require_relative 'smell_detectors/long_parameter_list'
require_relative 'smell_detectors/long_yield_list'
require_relative 'smell_detectors/manual_dispatch'
require_relative 'smell_detectors/module_initialize'
require_relative 'smell_detectors/nested_iterators'
require_relative 'smell_detectors/nil_check'
require_relative 'smell_detectors/prima_donna_method'
require_relative 'smell_detectors/repeated_conditional'
require_relative 'smell_detectors/subclassed_from_core_class'
require_relative 'smell_detectors/too_many_instance_variables'
require_relative 'smell_detectors/too_many_constants'
require_relative 'smell_detectors/too_many_methods'
require_relative 'smell_detectors/too_many_statements'
require_relative 'smell_detectors/uncommunicative_method_name'
require_relative 'smell_detectors/uncommunicative_module_name'
require_relative 'smell_detectors/uncommunicative_parameter_name'
require_relative 'smell_detectors/uncommunicative_variable_name'
require_relative 'smell_detectors/unused_parameters'
require_relative 'smell_detectors/unused_private_method'
require_relative 'smell_detectors/utility_function'
@@ -1,10 +1,10 @@
# frozen_string_literal: true
require_relative 'smell_configuration'
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# A class that publishes a getter or setter for an instance variable
# invites client classes to become too intimate with its inner workings,
Expand All @@ -16,7 +16,7 @@ module Smells
# See {file:docs/Attribute.md} for details.
#
# TODO: Catch attributes declared "by hand"
class Attribute < SmellDetector
class Attribute < BaseDetector
def initialize(*args)
super
end
Expand Down
Expand Up @@ -3,7 +3,7 @@
require_relative 'smell_configuration'

module Reek
module Smells
module SmellDetectors
#
# Shared responsibilities of all smell detectors.
#
Expand All @@ -14,7 +14,7 @@ module Smells
# for details.
#
# :reek:UnusedPrivateMethod: { exclude: [ smell_warning ] }
class SmellDetector
class BaseDetector
attr_reader :config
# The name of the config field that lists the names of code contexts
# that should not be checked. Add this field to the config for each
Expand Down Expand Up @@ -102,7 +102,7 @@ def inherited(subclass)
end

#
# Returns all descendants of SmellDetector
# Returns all descendants of BaseDetector
#
# @return [Array<Constant>], e.g.:
# [Reek::Smells::Attribute,
Expand Down
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# A Boolean parameter effectively permits a method's caller
# to decide which execution path to take. The
Expand All @@ -13,7 +13,7 @@ module Smells
# default initializer.
#
# See {file:docs/Boolean-Parameter.md} for details.
class BooleanParameter < SmellDetector
class BooleanParameter < BaseDetector
#
# Checks whether the given method has any Boolean parameters.
#
Expand Down
@@ -1,10 +1,10 @@
# frozen_string_literal: true
require 'set'
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# Class variables form part of the global runtime state, and as such make
# it easy for one part of the system to accidentally or inadvertently
Expand All @@ -14,7 +14,7 @@ module Smells
# the context of the test includes all global state).
#
# See {file:docs/Class-Variable.md} for details.
class ClassVariable < SmellDetector
class ClassVariable < BaseDetector
def self.contexts # :nodoc:
[:class, :module]
end
Expand Down
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# Control Coupling occurs when a method or block checks the value of
# a parameter in order to decide which execution path to take. The
Expand Down Expand Up @@ -42,7 +42,7 @@ module Smells
# the source code.
#
# See {file:docs/Control-Parameter.md} for details.
class ControlParameter < SmellDetector
class ControlParameter < BaseDetector
#
# Checks whether the given method chooses its execution path
# by testing the value of one of its parameters.
Expand Down
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# A Data Clump occurs when the same two or three items frequently
# appear together in classes and parameter lists, or when a group
Expand All @@ -17,7 +17,7 @@ module Smells
# the same names that are expected by three or more methods of a class.
#
# See {file:docs/Data-Clump.md} for details.
class DataClump < SmellDetector
class DataClump < BaseDetector
#
# The name of the config field that sets the maximum allowed
# copies of any clump. No group of common parameters will be
Expand Down
@@ -1,28 +1,28 @@
# frozen_string_literal: true
require_relative '../smells'
require_relative 'smell_detector'
require_relative '../smell_detectors'
require_relative 'base_detector'
require_relative '../configuration/app_configuration'

module Reek
module Smells
module SmellDetectors
#
# Contains all the existing smell detectors and exposes operations on them.
#
class DetectorRepository
# @return [Array<Reek::Smells::SmellDetector>] All known SmellDetectors
# @return [Array<Reek::SmellDetectors::BaseDetector>] All known SmellDetectors
# e.g. [Reek::Smells::BooleanParameter, Reek::Smells::ClassVariable].
def self.smell_types
Reek::Smells::SmellDetector.descendants.sort_by(&:name)
Reek::SmellDetectors::BaseDetector.descendants.sort_by(&:name)
end

# @param filter_by_smells [Array<String>]
# List of smell types to filter by, e.g. "DuplicateMethodCall".
# More precisely it should be whatever is returned by `SmellDetector`.smell_type.
# More precisely it should be whatever is returned by `BaseDetector`.smell_type.
# This means that you can write the "DuplicateMethodCall" from above also like this:
# Reek::Smells::DuplicateMethodCall.smell_type
# if you want to make sure you do not fat-finger strings.
#
# @return [Array<Reek::Smells::SmellDetector>] All SmellDetectors that we want to filter for
# @return [Array<Reek::SmellDetectors::BaseDetector>] All SmellDetectors that we want to filter for
# e.g. [Reek::Smells::Attribute].
def self.eligible_smell_types(filter_by_smells = [])
return smell_types if filter_by_smells.empty?
Expand Down
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# Duplication occurs when two fragments of code look nearly identical,
# or when two fragments of code have nearly identical effects
Expand All @@ -18,7 +18,7 @@ module Smells
# end
#
# See {file:docs/Duplicate-Method-Call.md} for details.
class DuplicateMethodCall < SmellDetector
class DuplicateMethodCall < BaseDetector
# The name of the config field that sets the maximum number of
# identical calls to be permitted within any single method.
MAX_ALLOWED_CALLS_KEY = 'max_calls'.freeze
Expand Down
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# Feature Envy occurs when a code fragment references another object
# more often than it references itself, or when several clients do
Expand Down Expand Up @@ -35,7 +35,7 @@ module Smells
# reported instead.
#
# See {file:docs/Feature-Envy.md} for details.
class FeatureEnvy < SmellDetector
class FeatureEnvy < BaseDetector
#
# Checks whether the given +context+ includes any code fragment that
# might "belong" on another class.
Expand Down
@@ -1,15 +1,15 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# The +InstanceVariableAssumption+ class is responsible for
# detecting directly access of instance variables in a class
# that does not define them in its initialize method.
#
class InstanceVariableAssumption < SmellDetector
class InstanceVariableAssumption < BaseDetector
def self.contexts
[:class]
end
Expand Down
@@ -1,15 +1,15 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# It is considered good practice to annotate every class and module
# with a brief comment outlining its responsibilities.
#
# See {file:docs/Irresponsible-Module.md} for details.
class IrresponsibleModule < SmellDetector
class IrresponsibleModule < BaseDetector
def self.contexts
[:casgn, :class, :module]
end
Expand Down
@@ -1,10 +1,10 @@
# frozen_string_literal: true
require_relative 'smell_configuration'
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# A Long Parameter List occurs when a method has more than one
# or two parameters, or when a method yields more than one or
Expand All @@ -14,7 +14,7 @@ module Smells
# many parameters.
#
# See {file:docs/Long-Parameter-List.md} for details.
class LongParameterList < SmellDetector
class LongParameterList < BaseDetector
# The name of the config field that sets the maximum number of
# parameters permitted in any method or block.
MAX_ALLOWED_PARAMS_KEY = 'max_params'.freeze
Expand Down
@@ -1,15 +1,15 @@
# frozen_string_literal: true
require_relative 'smell_detector'
require_relative 'base_detector'
require_relative 'smell_warning'

module Reek
module Smells
module SmellDetectors
#
# A variant on LongParameterList that checks the number of items
# passed to a block by a +yield+ call.
#
# See {file:docs/Long-Yield-List.md} for details.
class LongYieldList < SmellDetector
class LongYieldList < BaseDetector
# The name of the config field that sets the maximum number of
# parameters permitted in any method or block.
MAX_ALLOWED_PARAMS_KEY = 'max_params'.freeze
Expand Down

0 comments on commit c9bea17

Please sign in to comment.