reek 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +6 -0
  3. data/README.md +15 -9
  4. data/bin/reek +1 -1
  5. data/config/defaults.reek +71 -86
  6. data/features/command_line_interface/options.feature +0 -15
  7. data/features/reports/reports.feature +23 -0
  8. data/features/samples.feature +3 -12
  9. data/lib/reek.rb +3 -3
  10. data/lib/reek/cli/application.rb +1 -1
  11. data/lib/reek/cli/command_line.rb +10 -8
  12. data/lib/reek/cli/reek_command.rb +6 -7
  13. data/lib/reek/cli/report.rb +34 -38
  14. data/lib/reek/cli/version_command.rb +1 -1
  15. data/lib/reek/cli/yaml_command.rb +1 -1
  16. data/lib/reek/core/code_parser.rb +4 -4
  17. data/lib/reek/core/hash_extensions.rb +2 -2
  18. data/lib/reek/core/method_context.rb +2 -2
  19. data/lib/reek/core/module_context.rb +4 -4
  20. data/lib/reek/core/singleton_method_context.rb +1 -1
  21. data/lib/reek/core/smell_repository.rb +7 -6
  22. data/lib/reek/core/sniffer.rb +4 -4
  23. data/lib/reek/examiner.rb +10 -3
  24. data/lib/reek/smell_warning.rb +0 -2
  25. data/lib/reek/smells.rb +22 -21
  26. data/lib/reek/smells/attribute.rb +4 -8
  27. data/lib/reek/smells/boolean_parameter.rb +2 -2
  28. data/lib/reek/smells/class_variable.rb +3 -2
  29. data/lib/reek/smells/{control_couple.rb → control_parameter.rb} +5 -5
  30. data/lib/reek/smells/data_clump.rb +13 -29
  31. data/lib/reek/smells/{duplication.rb → duplicate_method_call.rb} +9 -11
  32. data/lib/reek/smells/feature_envy.rb +2 -2
  33. data/lib/reek/smells/irresponsible_module.rb +3 -2
  34. data/lib/reek/smells/long_parameter_list.rb +6 -10
  35. data/lib/reek/smells/long_yield_list.rb +4 -8
  36. data/lib/reek/smells/nested_iterators.rb +31 -25
  37. data/lib/reek/smells/nil_check.rb +11 -12
  38. data/lib/reek/smells/{simulated_polymorphism.rb → repeated_conditional.rb} +6 -10
  39. data/lib/reek/smells/smell_detector.rb +3 -6
  40. data/lib/reek/smells/too_many_instance_variables.rb +60 -0
  41. data/lib/reek/smells/too_many_methods.rb +62 -0
  42. data/lib/reek/smells/{long_method.rb → too_many_statements.rb} +7 -12
  43. data/lib/reek/smells/uncommunicative_method_name.rb +3 -7
  44. data/lib/reek/smells/uncommunicative_module_name.rb +3 -7
  45. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
  46. data/lib/reek/smells/uncommunicative_variable_name.rb +5 -9
  47. data/lib/reek/smells/unused_parameters.rb +62 -13
  48. data/lib/reek/smells/utility_function.rb +3 -7
  49. data/lib/reek/source.rb +8 -8
  50. data/lib/reek/source/core_extras.rb +1 -1
  51. data/lib/reek/source/source_code.rb +2 -2
  52. data/lib/reek/source/source_file.rb +2 -2
  53. data/lib/reek/source/source_locator.rb +1 -1
  54. data/lib/reek/source/source_repository.rb +4 -2
  55. data/lib/reek/spec.rb +9 -3
  56. data/lib/reek/spec/should_reek.rb +2 -2
  57. data/lib/reek/spec/should_reek_of.rb +1 -1
  58. data/lib/reek/spec/should_reek_only_of.rb +2 -2
  59. data/lib/reek/version.rb +1 -1
  60. data/reek.gemspec +3 -1
  61. data/spec/gem/updates_spec.rb +1 -1
  62. data/spec/gem/yard_spec.rb +1 -1
  63. data/spec/matchers/smell_of_matcher.rb +53 -19
  64. data/spec/reek/cli/help_command_spec.rb +2 -2
  65. data/spec/reek/cli/reek_command_spec.rb +6 -6
  66. data/spec/reek/cli/report_spec.rb +6 -6
  67. data/spec/reek/cli/version_command_spec.rb +2 -2
  68. data/spec/reek/cli/yaml_command_spec.rb +2 -2
  69. data/spec/reek/core/code_context_spec.rb +4 -4
  70. data/spec/reek/core/code_parser_spec.rb +2 -2
  71. data/spec/reek/core/config_spec.rb +4 -4
  72. data/spec/reek/core/method_context_spec.rb +3 -3
  73. data/spec/reek/core/module_context_spec.rb +3 -3
  74. data/spec/reek/core/object_refs_spec.rb +3 -3
  75. data/spec/reek/core/singleton_method_context_spec.rb +4 -4
  76. data/spec/reek/core/smell_configuration_spec.rb +2 -2
  77. data/spec/reek/core/stop_context_spec.rb +2 -2
  78. data/spec/reek/core/warning_collector_spec.rb +3 -3
  79. data/spec/reek/examiner_spec.rb +13 -4
  80. data/spec/reek/smell_warning_spec.rb +2 -2
  81. data/spec/reek/smells/attribute_spec.rb +4 -4
  82. data/spec/reek/smells/boolean_parameter_spec.rb +3 -3
  83. data/spec/reek/smells/class_variable_spec.rb +4 -4
  84. data/spec/reek/smells/{control_couple_spec.rb → control_parameter_spec.rb} +10 -10
  85. data/spec/reek/smells/data_clump_spec.rb +3 -3
  86. data/spec/reek/smells/{duplication_spec.rb → duplicate_method_call_spec.rb} +42 -26
  87. data/spec/reek/smells/feature_envy_spec.rb +3 -3
  88. data/spec/reek/smells/irresponsible_module_spec.rb +3 -3
  89. data/spec/reek/smells/long_parameter_list_spec.rb +3 -3
  90. data/spec/reek/smells/long_yield_list_spec.rb +3 -3
  91. data/spec/reek/smells/nested_iterators_spec.rb +42 -4
  92. data/spec/reek/smells/nil_check_spec.rb +23 -11
  93. data/spec/reek/smells/{simulated_polymorphism_spec.rb → repeated_conditional_spec.rb} +6 -6
  94. data/spec/reek/smells/smell_detector_shared.rb +2 -2
  95. data/spec/reek/smells/too_many_instance_variables_spec.rb +62 -0
  96. data/spec/reek/smells/{large_class_spec.rb → too_many_methods_spec.rb} +11 -56
  97. data/spec/reek/smells/{long_method_spec.rb → too_many_statements_spec.rb} +17 -17
  98. data/spec/reek/smells/uncommunicative_method_name_spec.rb +5 -5
  99. data/spec/reek/smells/uncommunicative_module_name_spec.rb +5 -5
  100. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +4 -4
  101. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +5 -5
  102. data/spec/reek/smells/unused_parameters_spec.rb +19 -4
  103. data/spec/reek/smells/utility_function_spec.rb +3 -3
  104. data/spec/reek/source/code_comment_spec.rb +2 -2
  105. data/spec/reek/source/object_source_spec.rb +1 -1
  106. data/spec/reek/source/reference_collector_spec.rb +2 -2
  107. data/spec/reek/source/sexp_formatter_spec.rb +2 -2
  108. data/spec/reek/source/source_code_spec.rb +2 -2
  109. data/spec/reek/source/tree_dresser_spec.rb +2 -2
  110. data/spec/reek/spec/should_reek_of_spec.rb +2 -2
  111. data/spec/reek/spec/should_reek_only_of_spec.rb +2 -2
  112. data/spec/reek/spec/should_reek_spec.rb +2 -2
  113. data/spec/samples/all_but_one_masked/masked.reek +1 -1
  114. data/spec/samples/clean_due_to_masking/masked.reek +1 -1
  115. data/spec/samples/config/allow_duplication.reek +2 -2
  116. data/spec/samples/inline_config/dirty.rb +2 -2
  117. data/spec/samples/mask_some/some.reek +1 -1
  118. data/spec/samples/masked_by_dotfile/dirty.rb +8 -0
  119. data/spec/samples/not_quite_masked/smelly.rb +3 -0
  120. data/spec/samples/overrides/masked/lower.reek +1 -1
  121. data/spec/samples/overrides/upper.reek +1 -1
  122. data/spec/spec_helper.rb +4 -9
  123. data/tasks/test.rake +0 -2
  124. metadata +253 -263
  125. data/lib/reek/smells/large_class.rb +0 -87
  126. data/lib/xp.reek +0 -66
  127. data/spec/gem/manifest_spec.rb +0 -22
  128. data/spec/spec.opts +0 -1
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')
1
+ require 'reek/examiner'
2
2
 
3
3
  module Reek
4
4
  module Cli
@@ -8,13 +8,13 @@ module Reek
8
8
  # text report format.
9
9
  #
10
10
  class ReekCommand
11
- def self.create(sources, report_class, config_files = [])
12
- new(report_class, sources, config_files)
11
+ def self.create(sources, reporter, config_files = [])
12
+ new(reporter, sources, config_files)
13
13
  end
14
14
 
15
- def initialize(report_class, sources, config_files = [])
15
+ def initialize(reporter, sources, config_files = [])
16
16
  @sources = sources
17
- @report_class = report_class
17
+ @reporter = reporter
18
18
  @config_files = config_files
19
19
  end
20
20
 
@@ -22,9 +22,8 @@ module Reek
22
22
  had_smells = false
23
23
  @sources.each do |source|
24
24
  examiner = Examiner.new(source, @config_files)
25
- rpt = @report_class.new(examiner)
26
25
  had_smells ||= examiner.smelly?
27
- view.output(rpt.report)
26
+ view.output @reporter.report(examiner)
28
27
  end
29
28
  if had_smells
30
29
  view.report_smells
@@ -1,38 +1,47 @@
1
1
  module Reek
2
2
  module Cli
3
-
4
3
  module ReportFormatter
5
- def header(desc, count)
6
- result = "#{desc} -- #{count} warning"
4
+ def self.format_list(warnings, formatter = SimpleWarningFormatter)
5
+ warnings.map do |warning|
6
+ " #{formatter.format warning}"
7
+ end.join("\n")
8
+ end
9
+
10
+ def self.header(examiner)
11
+ count = examiner.smells_count
12
+ result = "#{examiner.description} -- #{count} warning"
7
13
  result += 's' unless count == 1
8
14
  result
9
15
  end
16
+ end
10
17
 
11
- def format_list(warnings)
12
- warnings.map do |warning|
13
- " #{warning.context} #{warning.message} (#{warning.subclass})"
14
- end.join("\n")
18
+ module SimpleWarningFormatter
19
+ def self.format(warning)
20
+ "#{warning.context} #{warning.message} (#{warning.subclass})"
15
21
  end
22
+ end
16
23
 
17
- module_function :format_list
24
+ module WarningFormatterWithLineNumbers
25
+ def self.format(warning)
26
+ "#{warning.lines.inspect}:#{SimpleWarningFormatter.format(warning)}"
27
+ end
18
28
  end
19
29
 
20
30
  #
21
31
  # A report that lists every source, including those that have no smells.
22
32
  #
23
33
  class VerboseReport
24
-
25
- include ReportFormatter
26
-
27
- def initialize(examiner)
28
- @examiner = examiner
34
+ def initialize(warning_formatter = SimpleWarningFormatter, report_formatter = ReportFormatter)
35
+ @warning_formatter = warning_formatter
36
+ @report_formatter = report_formatter
29
37
  end
30
38
 
31
- def report
32
- warnings = @examiner.smells
33
- warning_count = warnings.length
34
- result = header(@examiner.description, warning_count)
35
- result += ":\n#{format_list(warnings)}" if warning_count > 0
39
+ def report(examiner)
40
+ result = @report_formatter.header examiner
41
+ if examiner.smelly?
42
+ formatted_list = @report_formatter.format_list examiner.smells, @warning_formatter
43
+ result += ":\n#{formatted_list}"
44
+ end
36
45
  result + "\n"
37
46
  end
38
47
  end
@@ -40,26 +49,13 @@ module Reek
40
49
  #
41
50
  # A report that lists a section for each source that has smells.
42
51
  #
43
- class QuietReport
44
-
45
- include ReportFormatter
46
-
47
- def initialize(examiner)
48
- @warnings = examiner.smells
49
- @smell_count = @warnings.length
50
- @desc = examiner.description
51
- end
52
-
53
- def report
54
- @smell_count > 0 ? "#{header(@desc, @smell_count)}:\n#{format_list(@warnings)}\n" : ''
55
- end
56
- end
57
-
58
- class ShowLineReport < VerboseReport
59
- def format_list(warnings)
60
- warnings.map do |warning|
61
- " #{warning.lines.inspect}:#{warning.context} #{warning.message} (#{warning.subclass})"
62
- end.join("\n")
52
+ class QuietReport < VerboseReport
53
+ def report(examiner)
54
+ if examiner.smelly?
55
+ super
56
+ else
57
+ ''
58
+ end
63
59
  end
64
60
  end
65
61
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'reek')
1
+ require 'reek'
2
2
 
3
3
  module Reek
4
4
  module Cli
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'examiner')
1
+ require 'reek/examiner'
2
2
 
3
3
  module Reek
4
4
  module Cli
@@ -1,8 +1,8 @@
1
1
  require 'sexp'
2
- require File.join(File.dirname(File.expand_path(__FILE__)), 'method_context')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'module_context')
4
- require File.join(File.dirname(File.expand_path(__FILE__)), 'stop_context')
5
- require File.join(File.dirname(File.expand_path(__FILE__)), 'singleton_method_context')
2
+ require 'reek/core/method_context'
3
+ require 'reek/core/module_context'
4
+ require 'reek/core/stop_context'
5
+ require 'reek/core/singleton_method_context'
6
6
 
7
7
  module Reek
8
8
  module Core
@@ -17,11 +17,11 @@ class Hash
17
17
  end
18
18
  self
19
19
  end
20
-
20
+
21
21
  def adopt(other)
22
22
  self.deep_copy.adopt!(other)
23
23
  end
24
-
24
+
25
25
  def deep_copy
26
26
  YAML::load(YAML::dump(self))
27
27
  end
@@ -1,5 +1,5 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'code_context')
2
- require File.join(File.dirname(File.expand_path(__FILE__)), 'object_refs')
1
+ require 'reek/core/code_context'
2
+ require 'reek/core/object_refs'
3
3
 
4
4
  module Reek
5
5
  module Core
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'code_context')
2
- require File.join(File.dirname(File.expand_path(__FILE__)), 'code_parser')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'sniffer')
4
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source', 'sexp_formatter')
1
+ require 'reek/core/code_context'
2
+ require 'reek/core/code_parser'
3
+ require 'reek/core/sniffer'
4
+ require 'reek/source/sexp_formatter'
5
5
 
6
6
  module Reek
7
7
  module Core
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'method_context')
1
+ require 'reek/core/method_context'
2
2
 
3
3
  module Reek
4
4
  module Core
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smells')
1
+ require 'reek/smells'
2
2
 
3
3
  module Reek
4
4
  module Core
@@ -10,18 +10,19 @@ module Reek
10
10
  Smells::Attribute,
11
11
  Smells::BooleanParameter,
12
12
  Smells::ClassVariable,
13
- Smells::ControlCouple,
13
+ Smells::ControlParameter,
14
14
  Smells::DataClump,
15
- Smells::Duplication,
15
+ Smells::DuplicateMethodCall,
16
16
  Smells::FeatureEnvy,
17
17
  Smells::IrresponsibleModule,
18
- Smells::LargeClass,
19
- Smells::LongMethod,
20
18
  Smells::LongParameterList,
21
19
  Smells::LongYieldList,
22
20
  Smells::NestedIterators,
23
21
  Smells::NilCheck,
24
- Smells::SimulatedPolymorphism,
22
+ Smells::RepeatedConditional,
23
+ Smells::TooManyInstanceVariables,
24
+ Smells::TooManyMethods,
25
+ Smells::TooManyStatements,
25
26
  Smells::UncommunicativeMethodName,
26
27
  Smells::UncommunicativeModuleName,
27
28
  Smells::UncommunicativeParameterName,
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'code_parser')
2
- require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_repository')
3
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source', 'config_file')
1
+ require 'reek/core/code_parser'
2
+ require 'reek/core/smell_repository'
3
+ require 'reek/source/config_file'
4
4
  require 'yaml'
5
- require File.join(File.dirname(File.expand_path(__FILE__)), 'hash_extensions')
5
+ require 'reek/core/hash_extensions'
6
6
 
7
7
  module Reek
8
8
  module Core
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'core', 'sniffer')
2
- require File.join(File.dirname(File.expand_path(__FILE__)), 'core', 'warning_collector')
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'source', 'source_repository')
1
+ require 'reek/core/sniffer'
2
+ require 'reek/core/warning_collector'
3
+ require 'reek/source/source_repository'
4
4
 
5
5
  module Reek
6
6
 
@@ -44,6 +44,13 @@ module Reek
44
44
  @smells
45
45
  end
46
46
 
47
+ #
48
+ # Returns the number of smells found in the source
49
+ #
50
+ def smells_count
51
+ @smells.length
52
+ end
53
+
47
54
  #
48
55
  # True if and only if there are code smells in the source.
49
56
  #
@@ -1,7 +1,5 @@
1
-
2
1
  module Reek
3
2
 
4
-
5
3
  #
6
4
  # Reports a warning that a smell has been found.
7
5
  # This object is essentially a DTO, and therefore contains a :reek:attribute or two.
@@ -1,24 +1,25 @@
1
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'attribute')
2
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'boolean_parameter')
3
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'class_variable')
4
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'control_couple')
5
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'data_clump')
6
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'duplication')
7
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'feature_envy')
8
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'irresponsible_module')
9
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'large_class')
10
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'long_method')
11
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'long_parameter_list')
12
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'long_yield_list')
13
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'nested_iterators')
14
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'nil_check')
15
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'simulated_polymorphism')
16
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'uncommunicative_method_name')
17
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'uncommunicative_module_name')
18
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'uncommunicative_parameter_name')
19
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'uncommunicative_variable_name')
20
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'unused_parameters')
21
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smells', 'utility_function')
1
+ require 'reek/smells/attribute'
2
+ require 'reek/smells/boolean_parameter'
3
+ require 'reek/smells/class_variable'
4
+ require 'reek/smells/control_parameter'
5
+ require 'reek/smells/data_clump'
6
+ require 'reek/smells/duplicate_method_call'
7
+ require 'reek/smells/feature_envy'
8
+ require 'reek/smells/irresponsible_module'
9
+ require 'reek/smells/long_parameter_list'
10
+ require 'reek/smells/long_yield_list'
11
+ require 'reek/smells/nested_iterators'
12
+ require 'reek/smells/nil_check'
13
+ require 'reek/smells/repeated_conditional'
14
+ require 'reek/smells/too_many_instance_variables'
15
+ require 'reek/smells/too_many_methods'
16
+ require 'reek/smells/too_many_statements'
17
+ require 'reek/smells/uncommunicative_method_name'
18
+ require 'reek/smells/uncommunicative_module_name'
19
+ require 'reek/smells/uncommunicative_parameter_name'
20
+ require 'reek/smells/uncommunicative_variable_name'
21
+ require 'reek/smells/unused_parameters'
22
+ require 'reek/smells/utility_function'
22
23
  # SMELL: Duplication -- all these should be found automagically
23
24
 
24
25
  module Reek
@@ -1,6 +1,6 @@
1
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
2
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
3
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'core', 'smell_configuration')
1
+ require 'reek/smells/smell_detector'
2
+ require 'reek/smell_warning'
3
+ require 'reek/core/smell_configuration'
4
4
 
5
5
  module Reek
6
6
  module Smells
@@ -33,10 +33,6 @@ module Reek
33
33
  super.adopt(Core::SmellConfiguration::ENABLED_KEY => false)
34
34
  end
35
35
 
36
- def initialize(source, config = Attribute.default_config)
37
- super(source, config)
38
- end
39
-
40
36
  #
41
37
  # Checks whether the given class declares any attributes.
42
38
  #
@@ -53,7 +49,7 @@ module Reek
53
49
  end
54
50
 
55
51
  private
56
-
52
+
57
53
  def attributes_in(module_ctx)
58
54
  result = Set.new
59
55
  attr_defn_methods = [:attr, :attr_reader, :attr_writer, :attr_accessor]
@@ -1,5 +1,5 @@
1
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
2
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
1
+ require 'reek/smells/smell_detector'
2
+ require 'reek/smell_warning'
3
3
 
4
4
  module Reek
5
5
  module Smells
@@ -1,6 +1,6 @@
1
1
  require 'set'
2
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
3
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
2
+ require 'reek/smells/smell_detector'
3
+ require 'reek/smell_warning'
4
4
 
5
5
  module Reek
6
6
  module Smells
@@ -17,6 +17,7 @@ module Reek
17
17
 
18
18
  SMELL_CLASS = self.name.split(/::/)[-1]
19
19
  SMELL_SUBCLASS = SMELL_CLASS
20
+
20
21
  VARIABLE_KEY = 'variable'
21
22
 
22
23
  def self.contexts # :nodoc:
@@ -1,5 +1,5 @@
1
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
2
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
1
+ require 'reek/smells/smell_detector'
2
+ require 'reek/smell_warning'
3
3
 
4
4
  module Reek
5
5
  module Smells
@@ -41,10 +41,10 @@ module Reek
41
41
  # that remains next to where the caller invokes it in
42
42
  # the source code.
43
43
  #
44
- class ControlCouple < SmellDetector
44
+ class ControlParameter < SmellDetector
45
45
 
46
- SMELL_CLASS = self.name.split(/::/)[-1]
47
- SMELL_SUBCLASS = 'ControlParameter'
46
+ SMELL_CLASS = 'ControlCouple'
47
+ SMELL_SUBCLASS = self.name.split(/::/)[-1]
48
48
  PARAMETER_KEY = 'parameter'
49
49
 
50
50
  #
@@ -1,15 +1,6 @@
1
- require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
2
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
3
- require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source')
4
-
5
- #
6
- # Extensions to +Array+ needed by Reek.
7
- #
8
- class Array
9
- def intersection
10
- self.inject { |res, elem| elem & res }
11
- end
12
- end
1
+ require 'reek/smells/smell_detector'
2
+ require 'reek/smell_warning'
3
+ require 'reek/source'
13
4
 
14
5
  module Reek
15
6
  module Smells
@@ -29,6 +20,7 @@ module Reek
29
20
  class DataClump < SmellDetector
30
21
 
31
22
  SMELL_CLASS = self.name.split(/::/)[-1]
23
+ SMELL_SUBCLASS = self.name.split(/::/)[-1]
32
24
 
33
25
  METHODS_KEY = 'methods'
34
26
  OCCURRENCES_KEY = 'occurrences'
@@ -58,15 +50,11 @@ module Reek
58
50
 
59
51
  def self.default_config
60
52
  super.adopt(
61
- MAX_COPIES_KEY => DEFAULT_MAX_COPIES,
62
- MIN_CLUMP_SIZE_KEY => DEFAULT_MIN_CLUMP_SIZE
53
+ MAX_COPIES_KEY => DEFAULT_MAX_COPIES,
54
+ MIN_CLUMP_SIZE_KEY => DEFAULT_MIN_CLUMP_SIZE
63
55
  )
64
56
  end
65
57
 
66
- def initialize(source, config = DataClump.default_config)
67
- super(source, config)
68
- end
69
-
70
58
  #
71
59
  # Checks the given class or module for multiple identical parameter sets.
72
60
  #
@@ -76,14 +64,14 @@ module Reek
76
64
  @max_copies = value(MAX_COPIES_KEY, ctx, DEFAULT_MAX_COPIES)
77
65
  @min_clump_size = value(MIN_CLUMP_SIZE_KEY, ctx, DEFAULT_MIN_CLUMP_SIZE)
78
66
  MethodGroup.new(ctx, @min_clump_size, @max_copies).clumps.map do |clump, methods|
79
- SmellWarning.new('DataClump', ctx.full_name,
67
+ SmellWarning.new(SMELL_CLASS, ctx.full_name,
80
68
  methods.map {|meth| meth.line},
81
69
  "takes parameters #{DataClump.print_clump(clump)} to #{methods.length} methods",
82
- @source, 'DataClump', {
83
- PARAMETERS_KEY => clump.map {|name| name.to_s},
84
- OCCURRENCES_KEY => methods.length,
85
- METHODS_KEY => methods.map {|meth| meth.name}
86
- })
70
+ @source, SMELL_SUBCLASS, {
71
+ PARAMETERS_KEY => clump.map {|name| name.to_s},
72
+ OCCURRENCES_KEY => methods.length,
73
+ METHODS_KEY => methods.map {|meth| meth.name}
74
+ })
87
75
  end
88
76
  end
89
77
 
@@ -98,10 +86,6 @@ module Reek
98
86
  # @private
99
87
  class MethodGroup
100
88
 
101
- def self.intersection_of_parameters_of(methods)
102
- methods.map {|meth| meth.arg_names}.intersection
103
- end
104
-
105
89
  def initialize(ctx, min_clump_size, max_copies)
106
90
  @min_clump_size = min_clump_size
107
91
  @max_copies = max_copies
@@ -114,7 +98,7 @@ module Reek
114
98
 
115
99
  def clumps_containing(method, methods, results)
116
100
  methods.each do |other_method|
117
- clump = [method.arg_names, other_method.arg_names].intersection
101
+ clump = method.arg_names & other_method.arg_names
118
102
  if clump.length >= @min_clump_size
119
103
  others = methods.select { |other| clump - other.arg_names == [] }
120
104
  results[clump] += [method] + others