reek 3.11 → 4.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.travis.yml +0 -1
  4. data/CHANGELOG.md +13 -1
  5. data/README.md +0 -1
  6. data/bin/code_climate_reek +1 -0
  7. data/bin/reek +1 -0
  8. data/docs/API.md +2 -2
  9. data/docs/RSpec-matchers.md +4 -7
  10. data/features/reports/json.feature +0 -4
  11. data/features/reports/yaml.feature +4 -8
  12. data/lib/reek.rb +1 -0
  13. data/lib/reek/ast/ast_node_class_map.rb +1 -0
  14. data/lib/reek/ast/node.rb +1 -0
  15. data/lib/reek/ast/object_refs.rb +2 -1
  16. data/lib/reek/ast/reference_collector.rb +1 -0
  17. data/lib/reek/ast/sexp_extensions.rb +1 -0
  18. data/lib/reek/ast/sexp_extensions/arguments.rb +1 -0
  19. data/lib/reek/ast/sexp_extensions/attribute_assignments.rb +1 -0
  20. data/lib/reek/ast/sexp_extensions/block.rb +1 -0
  21. data/lib/reek/ast/sexp_extensions/case.rb +1 -0
  22. data/lib/reek/ast/sexp_extensions/constant.rb +1 -0
  23. data/lib/reek/ast/sexp_extensions/if.rb +1 -0
  24. data/lib/reek/ast/sexp_extensions/literal.rb +1 -0
  25. data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -0
  26. data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
  27. data/lib/reek/ast/sexp_extensions/module.rb +1 -0
  28. data/lib/reek/ast/sexp_extensions/nested_assignables.rb +1 -0
  29. data/lib/reek/ast/sexp_extensions/self.rb +1 -0
  30. data/lib/reek/ast/sexp_extensions/send.rb +1 -0
  31. data/lib/reek/ast/sexp_extensions/super.rb +1 -0
  32. data/lib/reek/ast/sexp_extensions/symbols.rb +1 -0
  33. data/lib/reek/ast/sexp_extensions/variables.rb +1 -0
  34. data/lib/reek/ast/sexp_extensions/when.rb +1 -0
  35. data/lib/reek/ast/sexp_extensions/yield.rb +1 -0
  36. data/lib/reek/cli/application.rb +1 -0
  37. data/lib/reek/cli/command/base_command.rb +1 -0
  38. data/lib/reek/cli/command/report_command.rb +2 -1
  39. data/lib/reek/cli/command/todo_list_command.rb +2 -1
  40. data/lib/reek/cli/input.rb +1 -0
  41. data/lib/reek/cli/option_interpreter.rb +1 -0
  42. data/lib/reek/cli/options.rb +1 -0
  43. data/lib/reek/cli/silencer.rb +1 -0
  44. data/lib/reek/cli/warning_collector.rb +1 -0
  45. data/lib/reek/code_comment.rb +1 -0
  46. data/lib/reek/configuration/app_configuration.rb +1 -0
  47. data/lib/reek/configuration/configuration_file_finder.rb +1 -0
  48. data/lib/reek/configuration/configuration_validator.rb +1 -0
  49. data/lib/reek/configuration/default_directive.rb +1 -0
  50. data/lib/reek/configuration/directory_directives.rb +1 -0
  51. data/lib/reek/configuration/excluded_paths.rb +1 -0
  52. data/lib/reek/context/attribute_context.rb +1 -0
  53. data/lib/reek/context/class_context.rb +1 -0
  54. data/lib/reek/context/code_context.rb +1 -0
  55. data/lib/reek/context/ghost_context.rb +1 -0
  56. data/lib/reek/context/method_context.rb +1 -0
  57. data/lib/reek/context/module_context.rb +1 -0
  58. data/lib/reek/context/root_context.rb +1 -0
  59. data/lib/reek/context/send_context.rb +1 -0
  60. data/lib/reek/context/singleton_attribute_context.rb +1 -0
  61. data/lib/reek/context/singleton_method_context.rb +1 -0
  62. data/lib/reek/context/statement_counter.rb +1 -0
  63. data/lib/reek/context/visibility_tracker.rb +3 -2
  64. data/lib/reek/context_builder.rb +1 -0
  65. data/lib/reek/examiner.rb +2 -1
  66. data/lib/reek/rake/task.rb +1 -0
  67. data/lib/reek/report.rb +1 -0
  68. data/lib/reek/report/code_climate/code_climate_formatter.rb +2 -2
  69. data/lib/reek/report/formatter.rb +1 -0
  70. data/lib/reek/report/heading_formatter.rb +1 -0
  71. data/lib/reek/report/location_formatter.rb +1 -0
  72. data/lib/reek/report/report.rb +3 -3
  73. data/lib/reek/smells.rb +1 -0
  74. data/lib/reek/smells/attribute.rb +1 -0
  75. data/lib/reek/smells/boolean_parameter.rb +1 -4
  76. data/lib/reek/smells/class_variable.rb +1 -0
  77. data/lib/reek/smells/control_parameter.rb +7 -4
  78. data/lib/reek/smells/data_clump.rb +1 -0
  79. data/lib/reek/smells/duplicate_method_call.rb +5 -4
  80. data/lib/reek/smells/feature_envy.rb +1 -4
  81. data/lib/reek/smells/irresponsible_module.rb +1 -0
  82. data/lib/reek/smells/long_parameter_list.rb +1 -0
  83. data/lib/reek/smells/long_yield_list.rb +1 -4
  84. data/lib/reek/smells/module_initialize.rb +1 -0
  85. data/lib/reek/smells/nested_iterators.rb +2 -1
  86. data/lib/reek/smells/nil_check.rb +3 -4
  87. data/lib/reek/smells/prima_donna_method.rb +1 -0
  88. data/lib/reek/smells/repeated_conditional.rb +1 -4
  89. data/lib/reek/smells/smell_configuration.rb +1 -0
  90. data/lib/reek/smells/smell_detector.rb +2 -13
  91. data/lib/reek/smells/smell_repository.rb +1 -0
  92. data/lib/reek/smells/smell_warning.rb +4 -6
  93. data/lib/reek/smells/too_many_instance_variables.rb +1 -4
  94. data/lib/reek/smells/too_many_methods.rb +1 -4
  95. data/lib/reek/smells/too_many_statements.rb +1 -4
  96. data/lib/reek/smells/uncommunicative_method_name.rb +2 -5
  97. data/lib/reek/smells/uncommunicative_module_name.rb +2 -6
  98. data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -6
  99. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -4
  100. data/lib/reek/smells/unused_parameters.rb +1 -4
  101. data/lib/reek/smells/unused_private_method.rb +1 -0
  102. data/lib/reek/smells/utility_function.rb +1 -4
  103. data/lib/reek/source/source_code.rb +2 -1
  104. data/lib/reek/source/source_locator.rb +1 -0
  105. data/lib/reek/spec.rb +16 -23
  106. data/lib/reek/spec/should_reek.rb +3 -2
  107. data/lib/reek/spec/should_reek_of.rb +18 -15
  108. data/lib/reek/spec/should_reek_only_of.rb +6 -5
  109. data/lib/reek/spec/smell_matcher.rb +3 -7
  110. data/lib/reek/tree_dresser.rb +1 -0
  111. data/lib/reek/version.rb +2 -1
  112. data/reek.gemspec +1 -1
  113. data/spec/reek/examiner_spec.rb +8 -4
  114. data/spec/reek/report/code_climate_formatter_spec.rb +1 -1
  115. data/spec/reek/report/code_climate_report_spec.rb +2 -2
  116. data/spec/reek/report/html_report_spec.rb +1 -6
  117. data/spec/reek/report/json_report_spec.rb +0 -4
  118. data/spec/reek/report/yaml_report_spec.rb +0 -4
  119. data/spec/reek/smells/data_clump_spec.rb +2 -2
  120. data/spec/reek/smells/feature_envy_spec.rb +3 -3
  121. data/spec/reek/smells/nested_iterators_spec.rb +0 -1
  122. data/spec/reek/smells/prima_donna_method_spec.rb +0 -1
  123. data/spec/reek/smells/smell_detector_shared.rb +1 -5
  124. data/spec/reek/smells/too_many_methods_spec.rb +0 -1
  125. data/spec/reek/smells/uncommunicative_module_name_spec.rb +0 -1
  126. data/spec/reek/smells/unused_private_method_spec.rb +6 -4
  127. data/spec/reek/smells/utility_function_spec.rb +1 -1
  128. data/spec/reek/spec/should_reek_of_spec.rb +7 -3
  129. data/spec/reek/spec/smell_matcher_spec.rb +0 -4
  130. metadata +6 -6
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'yaml'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'pathname'
2
3
  require_relative './configuration_file_finder'
3
4
  require_relative './configuration_validator'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'pathname'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Configuration
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Configuration
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative './configuration_validator'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative './configuration_validator'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'module_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../code_comment'
2
3
  require_relative '../ast/object_refs'
3
4
  require_relative 'statement_counter'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
  require_relative 'singleton_method_context'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
  require_relative 'attribute_context'
3
4
  require_relative 'method_context'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
  require_relative 'method_context'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'code_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'attribute_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'method_context'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../ast/node'
2
3
 
3
4
  module Reek
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Context
3
4
  # Responsible for tracking visibilities in regards to CodeContexts.
@@ -18,7 +19,7 @@ module Reek
18
19
  # @param visibility [Symbol]
19
20
  # @param names [Array<Symbol>]
20
21
  #
21
- def track_visibility(children: raise, visibility: raise, names: raise)
22
+ def track_visibility(children:, visibility:, names:)
22
23
  return unless VISIBILITY_MODIFIERS.include? visibility
23
24
  if names.any?
24
25
  children.each do |child|
@@ -40,7 +41,7 @@ module Reek
40
41
  # @param visibility [Symbol]
41
42
  # @param names [Array<Symbol>]
42
43
  #
43
- def track_singleton_visibility(children: raise, visibility: raise, names: raise)
44
+ def track_singleton_visibility(children:, visibility:, names:)
44
45
  return if names.empty?
45
46
  visibility = VISIBILITY_MAP[visibility]
46
47
  return unless visibility
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'context/attribute_context'
2
3
  require_relative 'context/class_context'
3
4
  require_relative 'context/ghost_context'
data/lib/reek/examiner.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'context_builder'
2
3
  require_relative 'source/source_code'
3
4
  require_relative 'cli/warning_collector'
@@ -26,7 +27,7 @@ module Reek
26
27
  #
27
28
  # @public
28
29
  def initialize(source,
29
- filter_by_smells = [],
30
+ filter_by_smells: [],
30
31
  configuration: Configuration::AppConfiguration.default)
31
32
  @source = Source::SourceCode.from(source)
32
33
  @collector = CLI::WarningCollector.new
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rake'
4
5
  require 'rake/tasklib'
data/lib/reek/report.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'report/report'
2
3
  require_relative 'report/formatter'
3
4
  require_relative 'report/heading_formatter'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'codeclimate_engine'
2
3
 
3
4
  module Reek
@@ -27,11 +28,10 @@ module Reek
27
28
  end
28
29
 
29
30
  def check_name
30
- [warning.smell_category, warning.smell_type].join('/')
31
+ warning.smell_type
31
32
  end
32
33
 
33
34
  def categories
34
- # TODO: provide mappings for Reek's smell categories
35
35
  ['Complexity']
36
36
  end
37
37
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'location_formatter'
2
3
  require_relative 'code_climate/code_climate_formatter'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Report
3
4
  module HeadingFormatter
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Report
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'json'
2
3
  require 'pathname'
3
4
  require 'rainbow'
@@ -165,10 +166,9 @@ module Reek
165
166
  require 'erb'
166
167
 
167
168
  # @public
168
- def show(target_path: Pathname.new('reek.html'))
169
+ def show
169
170
  template_path = Pathname.new("#{__dir__}/html_report.html.erb")
170
- File.write target_path, ERB.new(template_path.read).result(binding)
171
- puts 'HTML file saved'
171
+ puts ERB.new(template_path.read).result(binding)
172
172
  end
173
173
  end
174
174
 
data/lib/reek/smells.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smells/attribute'
2
3
  require_relative 'smells/boolean_parameter'
3
4
  require_relative 'smells/class_variable'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_configuration'
2
3
  require_relative 'smell_detector'
3
4
  require_relative 'smell_warning'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -13,10 +14,6 @@ module Reek
13
14
  #
14
15
  # See {file:docs/Boolean-Parameter.md} for details.
15
16
  class BooleanParameter < SmellDetector
16
- def self.smell_category
17
- 'ControlCouple'
18
- end
19
-
20
17
  #
21
18
  # Checks whether the given method has any Boolean parameters.
22
19
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
  require_relative 'smell_detector'
3
4
  require_relative 'smell_warning'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -42,10 +43,6 @@ module Reek
42
43
  #
43
44
  # See {file:docs/Control-Parameter.md} for details.
44
45
  class ControlParameter < SmellDetector
45
- def self.smell_category
46
- 'ControlCouple'
47
- end
48
-
49
46
  #
50
47
  # Checks whether the given method chooses its execution path
51
48
  # by testing the value of one of its parameters.
@@ -90,6 +87,8 @@ module Reek
90
87
  attr_reader :occurences, :param
91
88
  end
92
89
 
90
+ private_constant :FoundControlParameter
91
+
93
92
  # Finds cases of ControlParameter in a particular node for a particular parameter
94
93
  class ControlParameterFinder
95
94
  CONDITIONAL_NODE_TYPES = [:if, :case, :and, :or].freeze
@@ -166,6 +165,8 @@ module Reek
166
165
  end
167
166
  end
168
167
 
168
+ private_constant :ControlParameterFinder
169
+
169
170
  #
170
171
  # Collects all control parameters in a given context.
171
172
  #
@@ -192,6 +193,8 @@ module Reek
192
193
  ControlParameterFinder.new(context.exp, param).find_matches
193
194
  end
194
195
  end
196
+
197
+ private_constant :ControlParameterCollector
195
198
  end
196
199
  end
197
200
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -29,10 +30,6 @@ module Reek
29
30
  ALLOW_CALLS_KEY = 'allow_calls'.freeze
30
31
  DEFAULT_ALLOW_CALLS = [].freeze
31
32
 
32
- def self.smell_category
33
- 'Duplication'
34
- end
35
-
36
33
  def self.default_config
37
34
  super.merge(
38
35
  MAX_ALLOWED_CALLS_KEY => DEFAULT_MAX_CALLS,
@@ -89,6 +86,8 @@ module Reek
89
86
  attr_reader :call_node, :occurences
90
87
  end
91
88
 
89
+ private_constant :FoundCall
90
+
92
91
  # Collects all calls in a given context
93
92
  class CallCollector
94
93
  attr_reader :context
@@ -139,6 +138,8 @@ module Reek
139
138
  allow_calls.any? { |allow| /#{allow}/ =~ method }
140
139
  end
141
140
  end
141
+
142
+ private_constant :CallCollector
142
143
  end
143
144
  end
144
145
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -35,10 +36,6 @@ module Reek
35
36
  #
36
37
  # See {file:docs/Feature-Envy.md} for details.
37
38
  class FeatureEnvy < SmellDetector
38
- def self.smell_category
39
- 'LowCohesion'
40
- end
41
-
42
39
  #
43
40
  # Checks whether the given +context+ includes any code fragment that
44
41
  # might "belong" on another class.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_configuration'
2
3
  require_relative 'smell_detector'
3
4
  require_relative 'smell_warning'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -14,10 +15,6 @@ module Reek
14
15
  MAX_ALLOWED_PARAMS_KEY = 'max_params'.freeze
15
16
  DEFAULT_MAX_ALLOWED_PARAMS = 3
16
17
 
17
- def self.smell_category
18
- 'LongParameterList'
19
- end
20
-
21
18
  def self.default_config
22
19
  super.merge MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS
23
20
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -92,7 +93,7 @@ module Reek
92
93
  #
93
94
  # @return [Array<Iterator>]
94
95
  #
95
- def scout(parent: raise, exp: raise, depth: raise)
96
+ def scout(parent:, exp:, depth:)
96
97
  return [Iterator.new(parent, depth)] unless exp
97
98
  iterators = exp.find_nodes([:block])
98
99
  return [Iterator.new(parent, depth)] if iterators.empty?
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -8,10 +9,6 @@ module Reek
8
9
  #
9
10
  # See {file:docs/Nil-Check.md} for details.
10
11
  class NilCheck < SmellDetector
11
- def self.smell_category
12
- 'SimulatedPolymorphism'
13
- end
14
-
15
12
  def inspect(ctx)
16
13
  call_node_finder = NodeFinder.new(ctx, :send, NilCallNodeDetector)
17
14
  case_node_finder = NodeFinder.new(ctx, :when, NilWhenNodeDetector)
@@ -45,6 +42,8 @@ module Reek
45
42
  attr_reader :detector, :nodes
46
43
  end
47
44
 
45
+ private_constant :NodeFinder
46
+
48
47
  # Detect 'call' nodes which perform a nil check.
49
48
  module NilCallNodeDetector
50
49
  module_function
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4