reek 4.2.3 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +7 -6
- data/Gemfile +2 -2
- data/README.md +8 -15
- data/Rakefile +1 -1
- data/defaults.reek +1 -0
- data/features/command_line_interface/basic_usage.feature +8 -14
- data/features/command_line_interface/smell_selection.feature +4 -4
- data/features/command_line_interface/smells_count.feature +12 -14
- data/features/configuration_files/masking_smells.feature +31 -24
- data/features/configuration_loading.feature +15 -18
- data/features/programmatic_access.feature +7 -9
- data/features/rake_task/rake_task.feature +20 -24
- data/features/reports/json.feature +16 -28
- data/features/reports/reports.feature +56 -67
- data/features/reports/yaml.feature +13 -26
- data/features/samples.feature +3 -3
- data/features/step_definitions/sample_file_steps.rb +22 -156
- data/features/todo_list.feature +13 -14
- data/lib/reek/cli/options.rb +1 -1
- data/lib/reek/examiner.rb +45 -10
- data/lib/reek/smells/attribute.rb +3 -4
- data/lib/reek/smells/boolean_parameter.rb +2 -2
- data/lib/reek/smells/class_variable.rb +1 -1
- data/lib/reek/smells/control_parameter.rb +4 -4
- data/lib/reek/smells/data_clump.rb +2 -3
- data/lib/reek/smells/duplicate_method_call.rb +1 -1
- data/lib/reek/smells/feature_envy.rb +2 -2
- data/lib/reek/smells/irresponsible_module.rb +2 -3
- data/lib/reek/smells/long_parameter_list.rb +1 -1
- data/lib/reek/smells/long_yield_list.rb +1 -1
- data/lib/reek/smells/module_initialize.rb +1 -1
- data/lib/reek/smells/nested_iterators.rb +2 -2
- data/lib/reek/smells/nil_check.rb +1 -1
- data/lib/reek/smells/prima_donna_method.rb +5 -2
- data/lib/reek/smells/repeated_conditional.rb +1 -1
- data/lib/reek/smells/smell_detector.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -5
- data/lib/reek/smells/subclassed_from_core_class.rb +3 -3
- data/lib/reek/smells/too_many_constants.rb +1 -1
- data/lib/reek/smells/too_many_instance_variables.rb +1 -1
- data/lib/reek/smells/too_many_methods.rb +1 -1
- data/lib/reek/smells/too_many_statements.rb +1 -1
- data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
- data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
- data/lib/reek/smells/unused_parameters.rb +1 -1
- data/lib/reek/smells/unused_private_method.rb +1 -1
- data/lib/reek/smells/utility_function.rb +2 -3
- data/lib/reek/spec/should_reek_of.rb +14 -1
- data/lib/reek/version.rb +1 -1
- data/samples/checkstyle.xml +7 -0
- data/samples/clean.rb +6 -0
- data/samples/configuration/.reek +0 -0
- data/samples/configuration/corrupt.reek +1 -0
- data/samples/configuration/empty.reek +0 -0
- data/samples/configuration/full_configuration.reek +9 -0
- data/{spec/samples/configuration/simple_configuration.reek → samples/configuration/full_mask.reek} +2 -2
- data/samples/configuration/non_public_modifiers_mask.reek +3 -0
- data/samples/configuration/partial_mask.reek +3 -0
- data/samples/configuration/with_excluded_paths.reek +4 -0
- data/{spec/samples → samples}/exceptions.reek +0 -0
- data/{spec/samples → samples}/inline.rb +0 -0
- data/{spec/samples → samples}/optparse.rb +0 -0
- data/samples/paths.rb +4 -0
- data/{spec/samples → samples}/redcloth.rb +0 -0
- data/samples/smelly.rb +7 -0
- data/samples/smelly_with_inline_mask.rb +8 -0
- data/samples/smelly_with_modifiers.rb +12 -0
- data/{spec/samples → samples}/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -0
- data/{spec/samples → samples}/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -0
- data/{spec/samples → samples}/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -0
- data/{spec/samples → samples}/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb +0 -0
- data/{spec/samples → samples}/source_with_hidden_directories/uncommunicative_parameter_name.rb +0 -0
- data/{spec/samples → samples}/source_with_non_ruby_files/gibberish +0 -0
- data/{spec/samples → samples}/source_with_non_ruby_files/python_source.py +0 -0
- data/{spec/samples → samples}/source_with_non_ruby_files/uncommunicative_parameter_name.rb +0 -0
- data/spec/reek/cli/application_spec.rb +1 -1
- data/spec/reek/cli/command/report_command_spec.rb +2 -5
- data/spec/reek/configuration/app_configuration_spec.rb +10 -8
- data/spec/reek/configuration/configuration_file_finder_spec.rb +24 -17
- data/spec/reek/examiner_spec.rb +84 -5
- data/spec/reek/report/json_report_spec.rb +1 -3
- data/spec/reek/report/xml_report_spec.rb +2 -3
- data/spec/reek/report/yaml_report_spec.rb +0 -2
- data/spec/reek/smells/attribute_spec.rb +21 -10
- data/spec/reek/smells/boolean_parameter_spec.rb +13 -12
- data/spec/reek/smells/class_variable_spec.rb +4 -4
- data/spec/reek/smells/control_parameter_spec.rb +25 -18
- data/spec/reek/smells/data_clump_spec.rb +5 -5
- data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
- data/spec/reek/smells/feature_envy_spec.rb +8 -2
- data/spec/reek/smells/irresponsible_module_spec.rb +16 -14
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -1
- data/spec/reek/smells/long_yield_list_spec.rb +5 -2
- data/spec/reek/smells/nested_iterators_spec.rb +37 -13
- data/spec/reek/smells/nil_check_spec.rb +50 -53
- data/spec/reek/smells/prima_donna_method_spec.rb +9 -1
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +4 -4
- data/spec/reek/smells/too_many_statements_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
- data/spec/reek/smells/utility_function_spec.rb +12 -8
- data/spec/reek/source/source_locator_spec.rb +5 -1
- data/spec/reek/spec/should_reek_of_spec.rb +20 -13
- data/spec/reek/spec/should_reek_spec.rb +6 -11
- data/spec/spec_helper.rb +2 -2
- metadata +28 -36
- data/spec/samples/all_but_one_masked/clean_one.rb +0 -7
- data/spec/samples/all_but_one_masked/dirty.rb +0 -8
- data/spec/samples/all_but_one_masked/masked.reek +0 -9
- data/spec/samples/checkstyle.xml +0 -13
- data/spec/samples/clean_due_to_masking/clean_one.rb +0 -7
- data/spec/samples/clean_due_to_masking/clean_three.rb +0 -7
- data/spec/samples/clean_due_to_masking/clean_two.rb +0 -7
- data/spec/samples/clean_due_to_masking/dirty_one.rb +0 -7
- data/spec/samples/clean_due_to_masking/dirty_two.rb +0 -7
- data/spec/samples/clean_due_to_masking/masked.reek +0 -11
- data/spec/samples/configuration/full_configuration.reek +0 -9
- data/spec/samples/configuration/with_excluded_paths.reek +0 -4
- data/spec/samples/masked_by_dotfile/.reek +0 -9
- data/spec/samples/masked_by_dotfile/dirty.rb +0 -8
- data/spec/samples/no_config_file/dirty.rb +0 -8
- data/spec/samples/three_clean_files/clean_one.rb +0 -7
- data/spec/samples/three_clean_files/clean_three.rb +0 -7
- data/spec/samples/three_clean_files/clean_two.rb +0 -7
- data/spec/samples/two_smelly_files/dirty_one.rb +0 -8
- data/spec/samples/two_smelly_files/dirty_two.rb +0 -8
data/features/todo_list.feature
CHANGED
|
@@ -10,15 +10,14 @@ Feature:
|
|
|
10
10
|
- get rid of the todo file
|
|
11
11
|
|
|
12
12
|
Scenario: Generate a proper todo file that disables all found smells
|
|
13
|
-
Given
|
|
13
|
+
Given the smelly file 'smelly.rb'
|
|
14
14
|
When I run reek smelly.rb
|
|
15
15
|
Then the exit status indicates smells
|
|
16
16
|
And it reports:
|
|
17
17
|
"""
|
|
18
|
-
smelly.rb --
|
|
19
|
-
[4
|
|
20
|
-
[
|
|
21
|
-
[3]:UncommunicativeMethodName: Smelly#m has the name 'm' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
|
|
18
|
+
smelly.rb -- 2 warnings:
|
|
19
|
+
[4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
|
|
20
|
+
[5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
|
22
21
|
"""
|
|
23
22
|
When I run reek --todo smelly.rb
|
|
24
23
|
Then it succeeds
|
|
@@ -31,28 +30,28 @@ Feature:
|
|
|
31
30
|
And the file ".todo.reek" should contain:
|
|
32
31
|
"""
|
|
33
32
|
---
|
|
34
|
-
DuplicateMethodCall:
|
|
35
|
-
exclude:
|
|
36
|
-
- Smelly#m
|
|
37
33
|
UncommunicativeMethodName:
|
|
38
34
|
exclude:
|
|
39
|
-
- Smelly#
|
|
35
|
+
- Smelly#x
|
|
36
|
+
UncommunicativeVariableName:
|
|
37
|
+
exclude:
|
|
38
|
+
- Smelly#x
|
|
40
39
|
"""
|
|
41
40
|
When I run reek -c .todo.reek smelly.rb
|
|
42
41
|
Then it succeeds
|
|
43
42
|
|
|
44
43
|
Scenario: Respects a configuration file
|
|
45
|
-
Given
|
|
46
|
-
And a configuration file
|
|
47
|
-
When I run reek -c
|
|
44
|
+
Given the smelly file 'smelly.rb'
|
|
45
|
+
And a configuration file 'partial_mask.reek'
|
|
46
|
+
When I run reek -c partial_mask.reek --todo smelly.rb
|
|
48
47
|
Then it succeeds
|
|
49
48
|
And a file named ".todo.reek" should exist
|
|
50
49
|
And the file ".todo.reek" should contain:
|
|
51
50
|
"""
|
|
52
51
|
---
|
|
53
|
-
|
|
52
|
+
UncommunicativeVariableName:
|
|
54
53
|
exclude:
|
|
55
|
-
- Smelly#
|
|
54
|
+
- Smelly#x
|
|
56
55
|
"""
|
|
57
56
|
|
|
58
57
|
Scenario: Reacts appropiately when there are no smells
|
data/lib/reek/cli/options.rb
CHANGED
data/lib/reek/examiner.rb
CHANGED
|
@@ -10,8 +10,21 @@ module Reek
|
|
|
10
10
|
#
|
|
11
11
|
# @public
|
|
12
12
|
#
|
|
13
|
-
# :reek:TooManyInstanceVariables: { max_instance_variables:
|
|
13
|
+
# :reek:TooManyInstanceVariables: { max_instance_variables: 7 }
|
|
14
14
|
class Examiner
|
|
15
|
+
INCOMPREHENSIBLE_SOURCE_TEMPLATE = <<-EOS.freeze
|
|
16
|
+
!!!
|
|
17
|
+
Source %s can not be processed by Reek.
|
|
18
|
+
This is most likely a Reek bug.
|
|
19
|
+
It would be great if you could report this back to the Reek team
|
|
20
|
+
by opening up a corresponding issue at https://github.com/troessner/reek/issues
|
|
21
|
+
Make sure to include the source in question, the Reek version
|
|
22
|
+
and the original exception below.
|
|
23
|
+
|
|
24
|
+
Original exception:
|
|
25
|
+
%s
|
|
26
|
+
!!!
|
|
27
|
+
EOS
|
|
15
28
|
#
|
|
16
29
|
# Creates an Examiner which scans the given +source+ for code smells.
|
|
17
30
|
#
|
|
@@ -28,13 +41,13 @@ module Reek
|
|
|
28
41
|
# @public
|
|
29
42
|
def initialize(source,
|
|
30
43
|
filter_by_smells: [],
|
|
31
|
-
configuration: Configuration::AppConfiguration.default
|
|
44
|
+
configuration: Configuration::AppConfiguration.default,
|
|
45
|
+
smell_repository_class: Smells::SmellRepository)
|
|
32
46
|
@source = Source::SourceCode.from(source)
|
|
33
47
|
@collector = CLI::WarningCollector.new
|
|
34
|
-
@smell_types =
|
|
35
|
-
@smell_repository =
|
|
36
|
-
|
|
37
|
-
run
|
|
48
|
+
@smell_types = smell_repository_class.eligible_smell_types(filter_by_smells)
|
|
49
|
+
@smell_repository = smell_repository_class.new(smell_types: @smell_types,
|
|
50
|
+
configuration: configuration.directive_for(description))
|
|
38
51
|
end
|
|
39
52
|
|
|
40
53
|
# FIXME: Should be named "origin"
|
|
@@ -51,6 +64,7 @@ module Reek
|
|
|
51
64
|
#
|
|
52
65
|
# @public
|
|
53
66
|
def smells
|
|
67
|
+
run
|
|
54
68
|
@smells ||= collector.warnings
|
|
55
69
|
end
|
|
56
70
|
|
|
@@ -74,14 +88,35 @@ module Reek
|
|
|
74
88
|
|
|
75
89
|
attr_reader :collector, :source, :smell_repository
|
|
76
90
|
|
|
91
|
+
# Runs the Examiner on the given source to scan for code smells
|
|
92
|
+
# and returns the corresponding Examiner instance.
|
|
93
|
+
#
|
|
94
|
+
# In case one of the smell detectors raises an exception we probably hit a Reek bug.
|
|
95
|
+
# So we catch the exception here, let the user know something went wrong
|
|
96
|
+
# and continue with the analysis.
|
|
97
|
+
#
|
|
98
|
+
# @return an instance of Examiner
|
|
99
|
+
#
|
|
100
|
+
# :reek:TooManyStatements: { max_statements: 6 }
|
|
77
101
|
def run
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
@run ||= begin
|
|
103
|
+
syntax_tree = source.syntax_tree
|
|
104
|
+
return self unless syntax_tree
|
|
105
|
+
begin
|
|
106
|
+
examine syntax_tree
|
|
107
|
+
rescue StandardError => exception
|
|
108
|
+
$stderr.puts format(INCOMPREHENSIBLE_SOURCE_TEMPLATE, source.origin, exception.inspect)
|
|
109
|
+
else
|
|
110
|
+
smell_repository.report_on(collector)
|
|
111
|
+
end
|
|
112
|
+
self
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def examine(syntax_tree)
|
|
80
117
|
ContextBuilder.new(syntax_tree).context_tree.each do |element|
|
|
81
118
|
smell_repository.examine(element)
|
|
82
119
|
end
|
|
83
|
-
|
|
84
|
-
smell_repository.report_on(collector)
|
|
85
120
|
end
|
|
86
121
|
end
|
|
87
122
|
end
|
|
@@ -30,13 +30,12 @@ module Reek
|
|
|
30
30
|
#
|
|
31
31
|
# @return [Array<SmellWarning>]
|
|
32
32
|
#
|
|
33
|
-
def
|
|
34
|
-
attributes_in(ctx).map do |
|
|
33
|
+
def sniff(ctx)
|
|
34
|
+
attributes_in(ctx).map do |_attribute, line|
|
|
35
35
|
smell_warning(
|
|
36
36
|
context: ctx,
|
|
37
37
|
lines: [line],
|
|
38
|
-
message: 'is a writable attribute'
|
|
39
|
-
parameters: { name: attribute.to_s })
|
|
38
|
+
message: 'is a writable attribute')
|
|
40
39
|
end
|
|
41
40
|
end
|
|
42
41
|
|
|
@@ -20,7 +20,7 @@ module Reek
|
|
|
20
20
|
# @return [Array<SmellWarning>]
|
|
21
21
|
#
|
|
22
22
|
# :reek:FeatureEnvy
|
|
23
|
-
def
|
|
23
|
+
def sniff(ctx)
|
|
24
24
|
ctx.default_assignments.select do |_param, value|
|
|
25
25
|
[:true, :false].include?(value.type)
|
|
26
26
|
end.map do |parameter, _value|
|
|
@@ -28,7 +28,7 @@ module Reek
|
|
|
28
28
|
context: ctx,
|
|
29
29
|
lines: [ctx.exp.line],
|
|
30
30
|
message: "has boolean parameter '#{parameter}'",
|
|
31
|
-
parameters: {
|
|
31
|
+
parameters: { parameter: parameter.to_s })
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -50,14 +50,14 @@ module Reek
|
|
|
50
50
|
# @return [Array<SmellWarning>]
|
|
51
51
|
#
|
|
52
52
|
# :reek:FeatureEnvy
|
|
53
|
-
def
|
|
53
|
+
def sniff(ctx)
|
|
54
54
|
ControlParameterCollector.new(ctx).control_parameters.map do |control_parameter|
|
|
55
|
-
|
|
55
|
+
argument = control_parameter.name.to_s
|
|
56
56
|
smell_warning(
|
|
57
57
|
context: ctx,
|
|
58
58
|
lines: control_parameter.lines,
|
|
59
|
-
message: "is controlled by argument #{
|
|
60
|
-
parameters: {
|
|
59
|
+
message: "is controlled by argument #{argument}",
|
|
60
|
+
parameters: { argument: argument })
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
@@ -51,7 +51,7 @@ module Reek
|
|
|
51
51
|
# @return [Array<SmellWarning>]
|
|
52
52
|
#
|
|
53
53
|
# :reek:FeatureEnvy
|
|
54
|
-
def
|
|
54
|
+
def sniff(ctx)
|
|
55
55
|
max_copies = value(MAX_COPIES_KEY, ctx)
|
|
56
56
|
min_clump_size = value(MIN_CLUMP_SIZE_KEY, ctx)
|
|
57
57
|
MethodGroup.new(ctx, min_clump_size, max_copies).clumps.map do |clump, methods|
|
|
@@ -63,8 +63,7 @@ module Reek
|
|
|
63
63
|
"to #{methods_length} methods",
|
|
64
64
|
parameters: {
|
|
65
65
|
parameters: clump.map(&:to_s),
|
|
66
|
-
count: methods_length
|
|
67
|
-
methods: methods.map(&:name)
|
|
66
|
+
count: methods_length
|
|
68
67
|
})
|
|
69
68
|
end
|
|
70
69
|
end
|
|
@@ -42,14 +42,14 @@ module Reek
|
|
|
42
42
|
#
|
|
43
43
|
# @return [Array<SmellWarning>]
|
|
44
44
|
#
|
|
45
|
-
def
|
|
45
|
+
def sniff(ctx)
|
|
46
46
|
return [] unless ctx.references_self?
|
|
47
47
|
envious_receivers(ctx).map do |name, lines|
|
|
48
48
|
smell_warning(
|
|
49
49
|
context: ctx,
|
|
50
50
|
lines: lines,
|
|
51
51
|
message: "refers to #{name} more than self (maybe move it to another class?)",
|
|
52
|
-
parameters: { name: name.to_s
|
|
52
|
+
parameters: { name: name.to_s })
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
@@ -19,14 +19,13 @@ module Reek
|
|
|
19
19
|
#
|
|
20
20
|
# @return [Array<SmellWarning>]
|
|
21
21
|
#
|
|
22
|
-
def
|
|
22
|
+
def sniff(ctx)
|
|
23
23
|
return [] if descriptive?(ctx) || ctx.namespace_module?
|
|
24
24
|
expression = ctx.exp
|
|
25
25
|
[smell_warning(
|
|
26
26
|
context: ctx,
|
|
27
27
|
lines: [expression.line],
|
|
28
|
-
message: 'has no descriptive comment'
|
|
29
|
-
parameters: { name: expression.name })]
|
|
28
|
+
message: 'has no descriptive comment')]
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
private
|
|
@@ -26,7 +26,7 @@ module Reek
|
|
|
26
26
|
#
|
|
27
27
|
# :reek:FeatureEnvy
|
|
28
28
|
# :reek:DuplicateMethodCall: { max_calls: 2 }
|
|
29
|
-
def
|
|
29
|
+
def sniff(ctx)
|
|
30
30
|
max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, ctx)
|
|
31
31
|
ctx.local_nodes(:yield).select do |yield_node|
|
|
32
32
|
yield_node.args.length > max_allowed_params
|
|
@@ -41,7 +41,7 @@ module Reek
|
|
|
41
41
|
#
|
|
42
42
|
# @return [Array<SmellWarning>]
|
|
43
43
|
#
|
|
44
|
-
def
|
|
44
|
+
def sniff(ctx)
|
|
45
45
|
configure_ignore_iterators ctx
|
|
46
46
|
violations = find_violations ctx
|
|
47
47
|
|
|
@@ -51,7 +51,7 @@ module Reek
|
|
|
51
51
|
context: ctx,
|
|
52
52
|
lines: lines,
|
|
53
53
|
message: "contains iterators nested #{depth} deep",
|
|
54
|
-
parameters: {
|
|
54
|
+
parameters: { depth: depth })
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
@@ -9,7 +9,7 @@ module Reek
|
|
|
9
9
|
#
|
|
10
10
|
# See {file:docs/Nil-Check.md} for details.
|
|
11
11
|
class NilCheck < SmellDetector
|
|
12
|
-
def
|
|
12
|
+
def sniff(ctx)
|
|
13
13
|
call_node_finder = NodeFinder.new(ctx, :send, NilCallNodeDetector)
|
|
14
14
|
case_node_finder = NodeFinder.new(ctx, :when, NilWhenNodeDetector)
|
|
15
15
|
smelly_nodes = call_node_finder.smelly_nodes + case_node_finder.smelly_nodes
|
|
@@ -29,7 +29,7 @@ module Reek
|
|
|
29
29
|
[:class]
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def
|
|
32
|
+
def sniff(ctx)
|
|
33
33
|
ctx.node_instance_methods.map do |method_sexp|
|
|
34
34
|
check_for_smells(method_sexp, ctx)
|
|
35
35
|
end.compact
|
|
@@ -38,6 +38,7 @@ module Reek
|
|
|
38
38
|
private
|
|
39
39
|
|
|
40
40
|
# :reek:FeatureEnvy
|
|
41
|
+
# :reek:TooManyStatements: { max_statements: 6 }
|
|
41
42
|
def check_for_smells(method_sexp, ctx)
|
|
42
43
|
return unless method_sexp.ends_with_bang?
|
|
43
44
|
|
|
@@ -47,10 +48,12 @@ module Reek
|
|
|
47
48
|
|
|
48
49
|
return if version_without_bang
|
|
49
50
|
|
|
51
|
+
name = method_sexp.name
|
|
50
52
|
smell_warning(
|
|
51
53
|
context: ctx,
|
|
52
54
|
lines: [ctx.exp.line],
|
|
53
|
-
message: "has prima donna method `#{
|
|
55
|
+
message: "has prima donna method `#{name}`",
|
|
56
|
+
parameters: { name: name })
|
|
54
57
|
end
|
|
55
58
|
end
|
|
56
59
|
end
|
|
@@ -48,7 +48,7 @@ module Reek
|
|
|
48
48
|
#
|
|
49
49
|
# :reek:TooManyStatements: { max_statements: 6 }
|
|
50
50
|
# :reek:DuplicateMethodCall: { max_calls: 2 }
|
|
51
|
-
def
|
|
51
|
+
def sniff(ctx)
|
|
52
52
|
max_identical_ifs = value(MAX_IDENTICAL_IFS_KEY, ctx)
|
|
53
53
|
conditional_counts(ctx).select do |_key, lines|
|
|
54
54
|
lines.length > max_identical_ifs
|
|
@@ -45,7 +45,7 @@ module Reek
|
|
|
45
45
|
|
|
46
46
|
# @public
|
|
47
47
|
def eql?(other)
|
|
48
|
-
(self <=> other)
|
|
48
|
+
(self <=> other).zero?
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def report_on(listener)
|
|
@@ -53,12 +53,13 @@ module Reek
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# @public
|
|
56
|
-
def
|
|
56
|
+
def to_hash
|
|
57
57
|
stringified_params = Hash[parameters.map { |key, val| [key.to_s, val] }]
|
|
58
|
-
|
|
59
|
-
merge(stringified_params)
|
|
58
|
+
base_hash.merge(stringified_params)
|
|
60
59
|
end
|
|
61
60
|
|
|
61
|
+
alias yaml_hash to_hash
|
|
62
|
+
|
|
62
63
|
def base_message
|
|
63
64
|
"#{smell_type}: #{context} #{message}"
|
|
64
65
|
end
|
|
@@ -75,7 +76,7 @@ module Reek
|
|
|
75
76
|
|
|
76
77
|
private
|
|
77
78
|
|
|
78
|
-
def
|
|
79
|
+
def base_hash
|
|
79
80
|
{
|
|
80
81
|
'context' => context,
|
|
81
82
|
'lines' => lines,
|
|
@@ -26,17 +26,17 @@ module Reek
|
|
|
26
26
|
# class Foo < Bar; end;
|
|
27
27
|
#
|
|
28
28
|
# @return [Array<SmellWarning>]
|
|
29
|
-
def
|
|
29
|
+
def sniff(ctx)
|
|
30
30
|
superclass = ctx.exp.superclass
|
|
31
31
|
|
|
32
32
|
return [] unless superclass
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
sniff_superclass(ctx, superclass.name)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
|
-
def
|
|
39
|
+
def sniff_superclass(ctx, superclass_name)
|
|
40
40
|
return [] unless CORE_CLASSES.include?(superclass_name)
|
|
41
41
|
|
|
42
42
|
[build_smell_warning(ctx, superclass_name)]
|