reek 3.11 → 4.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +13 -1
- data/README.md +0 -1
- data/bin/code_climate_reek +1 -0
- data/bin/reek +1 -0
- data/docs/API.md +2 -2
- data/docs/RSpec-matchers.md +4 -7
- data/features/reports/json.feature +0 -4
- data/features/reports/yaml.feature +4 -8
- data/lib/reek.rb +1 -0
- data/lib/reek/ast/ast_node_class_map.rb +1 -0
- data/lib/reek/ast/node.rb +1 -0
- data/lib/reek/ast/object_refs.rb +2 -1
- data/lib/reek/ast/reference_collector.rb +1 -0
- data/lib/reek/ast/sexp_extensions.rb +1 -0
- data/lib/reek/ast/sexp_extensions/arguments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/attribute_assignments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/block.rb +1 -0
- data/lib/reek/ast/sexp_extensions/case.rb +1 -0
- data/lib/reek/ast/sexp_extensions/constant.rb +1 -0
- data/lib/reek/ast/sexp_extensions/if.rb +1 -0
- data/lib/reek/ast/sexp_extensions/literal.rb +1 -0
- data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -0
- data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
- data/lib/reek/ast/sexp_extensions/module.rb +1 -0
- data/lib/reek/ast/sexp_extensions/nested_assignables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/self.rb +1 -0
- data/lib/reek/ast/sexp_extensions/send.rb +1 -0
- data/lib/reek/ast/sexp_extensions/super.rb +1 -0
- data/lib/reek/ast/sexp_extensions/symbols.rb +1 -0
- data/lib/reek/ast/sexp_extensions/variables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/when.rb +1 -0
- data/lib/reek/ast/sexp_extensions/yield.rb +1 -0
- data/lib/reek/cli/application.rb +1 -0
- data/lib/reek/cli/command/base_command.rb +1 -0
- data/lib/reek/cli/command/report_command.rb +2 -1
- data/lib/reek/cli/command/todo_list_command.rb +2 -1
- data/lib/reek/cli/input.rb +1 -0
- data/lib/reek/cli/option_interpreter.rb +1 -0
- data/lib/reek/cli/options.rb +1 -0
- data/lib/reek/cli/silencer.rb +1 -0
- data/lib/reek/cli/warning_collector.rb +1 -0
- data/lib/reek/code_comment.rb +1 -0
- data/lib/reek/configuration/app_configuration.rb +1 -0
- data/lib/reek/configuration/configuration_file_finder.rb +1 -0
- data/lib/reek/configuration/configuration_validator.rb +1 -0
- data/lib/reek/configuration/default_directive.rb +1 -0
- data/lib/reek/configuration/directory_directives.rb +1 -0
- data/lib/reek/configuration/excluded_paths.rb +1 -0
- data/lib/reek/context/attribute_context.rb +1 -0
- data/lib/reek/context/class_context.rb +1 -0
- data/lib/reek/context/code_context.rb +1 -0
- data/lib/reek/context/ghost_context.rb +1 -0
- data/lib/reek/context/method_context.rb +1 -0
- data/lib/reek/context/module_context.rb +1 -0
- data/lib/reek/context/root_context.rb +1 -0
- data/lib/reek/context/send_context.rb +1 -0
- data/lib/reek/context/singleton_attribute_context.rb +1 -0
- data/lib/reek/context/singleton_method_context.rb +1 -0
- data/lib/reek/context/statement_counter.rb +1 -0
- data/lib/reek/context/visibility_tracker.rb +3 -2
- data/lib/reek/context_builder.rb +1 -0
- data/lib/reek/examiner.rb +2 -1
- data/lib/reek/rake/task.rb +1 -0
- data/lib/reek/report.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_formatter.rb +2 -2
- data/lib/reek/report/formatter.rb +1 -0
- data/lib/reek/report/heading_formatter.rb +1 -0
- data/lib/reek/report/location_formatter.rb +1 -0
- data/lib/reek/report/report.rb +3 -3
- data/lib/reek/smells.rb +1 -0
- data/lib/reek/smells/attribute.rb +1 -0
- data/lib/reek/smells/boolean_parameter.rb +1 -4
- data/lib/reek/smells/class_variable.rb +1 -0
- data/lib/reek/smells/control_parameter.rb +7 -4
- data/lib/reek/smells/data_clump.rb +1 -0
- data/lib/reek/smells/duplicate_method_call.rb +5 -4
- data/lib/reek/smells/feature_envy.rb +1 -4
- data/lib/reek/smells/irresponsible_module.rb +1 -0
- data/lib/reek/smells/long_parameter_list.rb +1 -0
- data/lib/reek/smells/long_yield_list.rb +1 -4
- data/lib/reek/smells/module_initialize.rb +1 -0
- data/lib/reek/smells/nested_iterators.rb +2 -1
- data/lib/reek/smells/nil_check.rb +3 -4
- data/lib/reek/smells/prima_donna_method.rb +1 -0
- data/lib/reek/smells/repeated_conditional.rb +1 -4
- data/lib/reek/smells/smell_configuration.rb +1 -0
- data/lib/reek/smells/smell_detector.rb +2 -13
- data/lib/reek/smells/smell_repository.rb +1 -0
- data/lib/reek/smells/smell_warning.rb +4 -6
- data/lib/reek/smells/too_many_instance_variables.rb +1 -4
- data/lib/reek/smells/too_many_methods.rb +1 -4
- data/lib/reek/smells/too_many_statements.rb +1 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +2 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +2 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -6
- data/lib/reek/smells/uncommunicative_variable_name.rb +1 -4
- data/lib/reek/smells/unused_parameters.rb +1 -4
- data/lib/reek/smells/unused_private_method.rb +1 -0
- data/lib/reek/smells/utility_function.rb +1 -4
- data/lib/reek/source/source_code.rb +2 -1
- data/lib/reek/source/source_locator.rb +1 -0
- data/lib/reek/spec.rb +16 -23
- data/lib/reek/spec/should_reek.rb +3 -2
- data/lib/reek/spec/should_reek_of.rb +18 -15
- data/lib/reek/spec/should_reek_only_of.rb +6 -5
- data/lib/reek/spec/smell_matcher.rb +3 -7
- data/lib/reek/tree_dresser.rb +1 -0
- data/lib/reek/version.rb +2 -1
- data/reek.gemspec +1 -1
- data/spec/reek/examiner_spec.rb +8 -4
- data/spec/reek/report/code_climate_formatter_spec.rb +1 -1
- data/spec/reek/report/code_climate_report_spec.rb +2 -2
- data/spec/reek/report/html_report_spec.rb +1 -6
- data/spec/reek/report/json_report_spec.rb +0 -4
- data/spec/reek/report/yaml_report_spec.rb +0 -4
- data/spec/reek/smells/data_clump_spec.rb +2 -2
- data/spec/reek/smells/feature_envy_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +0 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +0 -1
- data/spec/reek/smells/smell_detector_shared.rb +1 -5
- data/spec/reek/smells/too_many_methods_spec.rb +0 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +0 -1
- data/spec/reek/smells/unused_private_method_spec.rb +6 -4
- data/spec/reek/smells/utility_function_spec.rb +1 -1
- data/spec/reek/spec/should_reek_of_spec.rb +7 -3
- data/spec/reek/spec/smell_matcher_spec.rb +0 -4
- metadata +6 -6
data/lib/reek/code_comment.rb
CHANGED
@@ -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
|
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
|
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
|
data/lib/reek/context_builder.rb
CHANGED
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
|
data/lib/reek/rake/task.rb
CHANGED
data/lib/reek/report.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/reek/report/report.rb
CHANGED
@@ -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
|
169
|
+
def show
|
169
170
|
template_path = Pathname.new("#{__dir__}/html_report.html.erb")
|
170
|
-
|
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 '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_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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -92,7 +93,7 @@ module Reek
|
|
92
93
|
#
|
93
94
|
# @return [Array<Iterator>]
|
94
95
|
#
|
95
|
-
def scout(parent
|
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
|