reek 4.4.1 → 4.4.2
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 +46 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -1
- data/docs/Duplicate-Method-Call.md +96 -0
- data/docs/How-To-Write-New-Detectors.md +16 -0
- data/docs/Large-Class.md +2 -1
- data/docs/Simulated-Polymorphism.md +1 -1
- data/features/configuration_via_source_comments/erroneous_source_comments.feature +39 -0
- data/lib/reek/ast/node.rb +4 -0
- data/lib/reek/code_comment.rb +11 -3
- data/lib/reek/context/code_context.rb +3 -1
- data/lib/reek/context/module_context.rb +1 -1
- data/lib/reek/errors.rb +32 -0
- data/lib/reek/examiner.rb +6 -1
- data/lib/reek/rake/task.rb +0 -2
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/class_variable.rb +2 -2
- data/lib/reek/smells/instance_variable_assumption.rb +1 -1
- data/lib/reek/smells/prima_donna_method.rb +18 -17
- data/lib/reek/smells/smell_detector.rb +19 -2
- data/lib/reek/smells/unused_private_method.rb +1 -1
- data/lib/reek/spec/should_reek_of.rb +2 -0
- data/lib/reek/version.rb +1 -1
- data/spec/factories/factories.rb +11 -0
- data/spec/quality/reek_source_spec.rb +1 -1
- data/spec/reek/ast/node_spec.rb +40 -0
- data/spec/reek/ast/object_refs_spec.rb +20 -59
- data/spec/reek/ast/sexp_extensions_spec.rb +16 -19
- data/spec/reek/cli/application_spec.rb +25 -25
- data/spec/reek/cli/command/report_command_spec.rb +1 -2
- data/spec/reek/cli/command/todo_list_command_spec.rb +1 -1
- data/spec/reek/cli/options_spec.rb +7 -5
- data/spec/reek/code_comment_spec.rb +74 -44
- data/spec/reek/configuration/default_directive_spec.rb +3 -3
- data/spec/reek/configuration/directory_directives_spec.rb +10 -10
- data/spec/reek/configuration/excluded_paths_spec.rb +2 -2
- data/spec/reek/context/code_context_spec.rb +22 -26
- data/spec/reek/context/ghost_context_spec.rb +1 -1
- data/spec/reek/context/method_context_spec.rb +13 -7
- data/spec/reek/context/module_context_spec.rb +4 -4
- data/spec/reek/context/root_context_spec.rb +1 -1
- data/spec/reek/context_builder_spec.rb +34 -38
- data/spec/reek/examiner_spec.rb +43 -22
- data/spec/reek/rake/task_spec.rb +3 -3
- data/spec/reek/report/code_climate_formatter_spec.rb +42 -40
- data/spec/reek/report/code_climate_report_spec.rb +1 -1
- data/spec/reek/report/html_report_spec.rb +1 -1
- data/spec/reek/report/json_report_spec.rb +1 -1
- data/spec/reek/report/location_formatter_spec.rb +18 -16
- data/spec/reek/report/text_report_spec.rb +12 -8
- data/spec/reek/report/xml_report_spec.rb +1 -1
- data/spec/reek/report/yaml_report_spec.rb +1 -1
- data/spec/reek/report_spec.rb +4 -4
- data/spec/reek/smells/attribute_spec.rb +7 -10
- data/spec/reek/smells/boolean_parameter_spec.rb +14 -20
- data/spec/reek/smells/class_variable_spec.rb +6 -5
- data/spec/reek/smells/control_parameter_spec.rb +3 -2
- data/spec/reek/smells/data_clump_spec.rb +3 -6
- data/spec/reek/smells/duplicate_method_call_spec.rb +10 -14
- data/spec/reek/smells/feature_envy_spec.rb +34 -25
- data/spec/reek/smells/instance_variable_assumption_spec.rb +6 -9
- data/spec/reek/smells/irresponsible_module_spec.rb +3 -6
- data/spec/reek/smells/long_parameter_list_spec.rb +5 -7
- data/spec/reek/smells/long_yield_list_spec.rb +3 -6
- data/spec/reek/smells/manual_dispatch_spec.rb +3 -6
- data/spec/reek/smells/nested_iterators_spec.rb +10 -8
- data/spec/reek/smells/nil_check_spec.rb +2 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -8
- data/spec/reek/smells/smell_configuration_spec.rb +3 -3
- data/spec/reek/smells/smell_detector_spec.rb +10 -0
- data/spec/reek/smells/smell_repository_spec.rb +6 -6
- data/spec/reek/smells/smell_warning_spec.rb +35 -39
- data/spec/reek/smells/subclassed_from_core_class_spec.rb +5 -5
- data/spec/reek/smells/too_many_constants_spec.rb +10 -10
- data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
- data/spec/reek/smells/too_many_methods_spec.rb +1 -1
- data/spec/reek/smells/too_many_statements_spec.rb +3 -6
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +9 -6
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +6 -9
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +20 -24
- data/spec/reek/smells/unused_parameters_spec.rb +35 -24
- data/spec/reek/smells/unused_private_method_spec.rb +25 -33
- data/spec/reek/smells/utility_function_spec.rb +27 -14
- data/spec/reek/source/source_code_spec.rb +6 -6
- data/spec/reek/source/source_locator_spec.rb +34 -17
- data/spec/reek/spec/should_reek_of_spec.rb +17 -12
- data/spec/reek/spec/should_reek_only_of_spec.rb +5 -5
- data/spec/reek/spec/should_reek_spec.rb +3 -3
- data/spec/reek/tree_dresser_spec.rb +6 -4
- data/spec/spec_helper.rb +3 -0
- data/tasks/rubocop.rake +9 -3
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9726cb15a47090a670c986a90860b2ba22826416
|
|
4
|
+
data.tar.gz: 61c5759684ec24d5d0e7bd1e4d2e035a5263d25f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee0920b75d4b8be3d47940587f97aea414a0eb9faa83b2871d1d8627021c155674e108746a74588357f576b0d2783c59fadb40eae2d1972493eeb873e268b5af
|
|
7
|
+
data.tar.gz: 235a55cefe8256fb4d20529f10e1db0c3f4719641cd34c1c8e8d7b20d6c4e86fe07ae541990c92c4f22f838c2fe2476c9ce48b1a7145af2d74c735867d4940b0
|
data/.rubocop.yml
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
1
4
|
AllCops:
|
|
2
5
|
Exclude:
|
|
3
6
|
- 'samples/**/*'
|
|
@@ -23,6 +26,49 @@ Metrics/LineLength:
|
|
|
23
26
|
Metrics/ParameterLists:
|
|
24
27
|
CountKeywordArgs: false
|
|
25
28
|
|
|
29
|
+
# FIXME: Update specs to avoid offenses
|
|
30
|
+
RSpec/AnyInstance:
|
|
31
|
+
Exclude:
|
|
32
|
+
- 'spec/reek/cli/application_spec.rb'
|
|
33
|
+
|
|
34
|
+
# This file does not test a class
|
|
35
|
+
RSpec/DescribeClass:
|
|
36
|
+
Exclude:
|
|
37
|
+
- 'spec/quality/reek_source_spec.rb'
|
|
38
|
+
|
|
39
|
+
# Our examples are large because we have source literals in them
|
|
40
|
+
RSpec/ExampleLength:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
# FIXME: Split up files to avoid offenses
|
|
44
|
+
RSpec/MultipleDescribes:
|
|
45
|
+
Exclude:
|
|
46
|
+
- 'spec/reek/ast/sexp_extensions_spec.rb'
|
|
47
|
+
- 'spec/reek/report/location_formatter_spec.rb'
|
|
48
|
+
|
|
49
|
+
# FIXME: Update specs to avoid offenses
|
|
50
|
+
RSpec/MultipleExpectations:
|
|
51
|
+
Exclude:
|
|
52
|
+
- 'spec/reek/cli/application_spec.rb'
|
|
53
|
+
- 'spec/reek/code_comment_spec.rb'
|
|
54
|
+
- 'spec/reek/configuration/app_configuration_spec.rb'
|
|
55
|
+
- 'spec/reek/context/module_context_spec.rb'
|
|
56
|
+
- 'spec/reek/context_builder_spec.rb'
|
|
57
|
+
- 'spec/reek/examiner_spec.rb'
|
|
58
|
+
- 'spec/reek/spec/should_reek_of_spec.rb'
|
|
59
|
+
|
|
60
|
+
# FIXME: Update specs to avoid offenses
|
|
61
|
+
RSpec/NestedGroups:
|
|
62
|
+
Exclude:
|
|
63
|
+
- 'spec/reek/cli/application_spec.rb'
|
|
64
|
+
|
|
65
|
+
# FIXME: Update specs to avoid offenses
|
|
66
|
+
RSpec/VerifiedDoubles:
|
|
67
|
+
Exclude:
|
|
68
|
+
- 'spec/reek/context/code_context_spec.rb'
|
|
69
|
+
- 'spec/reek/context/method_context_spec.rb'
|
|
70
|
+
- 'spec/reek/context/module_context_spec.rb'
|
|
71
|
+
|
|
26
72
|
Style/AccessorMethodName:
|
|
27
73
|
Exclude:
|
|
28
74
|
- 'lib/reek/context/visibility_tracker.rb'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -10,11 +10,15 @@ group :development do
|
|
|
10
10
|
gem 'mutant-rspec', '~> 0.8.8'
|
|
11
11
|
gem 'rake', '~> 11.1'
|
|
12
12
|
gem 'rspec', '~> 3.0'
|
|
13
|
-
gem 'rubocop', '~> 0.42.0'
|
|
14
13
|
gem 'simplecov', '~> 0.12.0'
|
|
15
14
|
gem 'yard', '~> 0.9.5'
|
|
16
15
|
gem 'activesupport', '~> 4.2'
|
|
17
16
|
|
|
17
|
+
if RUBY_VERSION >= '2.3'
|
|
18
|
+
gem 'rubocop', '~> 0.42.0'
|
|
19
|
+
gem 'rubocop-rspec', '~> 1.7'
|
|
20
|
+
end
|
|
21
|
+
|
|
18
22
|
platforms :mri do
|
|
19
23
|
gem 'redcarpet', '~> 3.3.1'
|
|
20
24
|
end
|
|
@@ -51,3 +51,99 @@ Reek's Duplicate Method Call detector currently offers the [Basic Smell Options]
|
|
|
51
51
|
Option | Value | Effect
|
|
52
52
|
-------|-------|-------
|
|
53
53
|
`max_calls` | integer | The maximum number of duplicate calls allowed within a method. Defaults to 1.
|
|
54
|
+
`allow_calls` | an array of strings or regular expressions | Ignores any context who matches it |
|
|
55
|
+
|
|
56
|
+
## Example configuration
|
|
57
|
+
|
|
58
|
+
### Adjusting `max_calls`
|
|
59
|
+
|
|
60
|
+
Imagine code like this:
|
|
61
|
+
|
|
62
|
+
```Ruby
|
|
63
|
+
class Alfa
|
|
64
|
+
def bravo
|
|
65
|
+
charlie.delta
|
|
66
|
+
charlie.delta
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This would report:
|
|
72
|
+
|
|
73
|
+
>>
|
|
74
|
+
src.rb -- 1 warning:
|
|
75
|
+
[4, 5]:DuplicateMethodCall: Alfa#bravo calls 'charlie.delta' 2 times
|
|
76
|
+
|
|
77
|
+
If you want to allow those double calls here you can disable it in 2 different ways:
|
|
78
|
+
|
|
79
|
+
1.) Via source code comment:
|
|
80
|
+
|
|
81
|
+
```Ruby
|
|
82
|
+
class Alfa
|
|
83
|
+
# :reek:DuplicateMethodCall { max_calls: 2 }
|
|
84
|
+
def bravo
|
|
85
|
+
charlie.delta
|
|
86
|
+
charlie.delta
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
2.) Via configuration file:
|
|
92
|
+
|
|
93
|
+
```Yaml
|
|
94
|
+
DuplicateMethodCall:
|
|
95
|
+
max_calls: 2
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Note though that the latter way will set `max_calls` to 2 for all instances
|
|
99
|
+
of the smell detector which might not be what you want - in this case
|
|
100
|
+
you'll have to use source code comments.
|
|
101
|
+
|
|
102
|
+
### Adjusting `allow_calls`
|
|
103
|
+
|
|
104
|
+
Imagine code like this:
|
|
105
|
+
|
|
106
|
+
```Ruby
|
|
107
|
+
class Alfa
|
|
108
|
+
def bravo
|
|
109
|
+
charlie.delta
|
|
110
|
+
charlie.delta
|
|
111
|
+
echo.foxtrot
|
|
112
|
+
echo.foxtrot
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This would report:
|
|
118
|
+
|
|
119
|
+
>>
|
|
120
|
+
src.rb -- 2 warnings:
|
|
121
|
+
[4, 5]:DuplicateMethodCall: Alfa#bravo calls charlie.delta 2 times
|
|
122
|
+
[6, 7]:DuplicateMethodCall: Alfa#bravo calls echo.foxtrot 2 times
|
|
123
|
+
|
|
124
|
+
So let's say you're ok with the `echo.foxtrot` calls you can stop reporting them like this:
|
|
125
|
+
|
|
126
|
+
1.) Via source code comment:
|
|
127
|
+
|
|
128
|
+
```Ruby
|
|
129
|
+
class Alfa
|
|
130
|
+
# :reek:DuplicateMethodCall { allow_calls: ['echo.foxtrot'] }
|
|
131
|
+
def bravo
|
|
132
|
+
charlie.delta
|
|
133
|
+
charlie.delta
|
|
134
|
+
echo.foxtrot
|
|
135
|
+
echo.foxtrot
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
2.) Via configuration file:
|
|
141
|
+
|
|
142
|
+
```Yaml
|
|
143
|
+
DuplicateMethodCall:
|
|
144
|
+
allow_calls:
|
|
145
|
+
- 'echo.foxtrot'
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Note though that the latter way will allow those calls across your source code which might not be what you want.
|
|
149
|
+
In this case you'll have to use source code comments.
|
|
@@ -59,6 +59,20 @@ module Reek
|
|
|
59
59
|
end
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
For your detector to be properly loaded you need to require it in `lib/reek/smells.rb` as well.
|
|
63
|
+
|
|
64
|
+
### defaults.reek
|
|
65
|
+
|
|
66
|
+
After you ran
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
bundle exec rake
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
for the first time with your shiny new detector in place the `defaults.reek`
|
|
73
|
+
file should have been updated automatically. Make sure you don't forget to check
|
|
74
|
+
in those changes as well.
|
|
75
|
+
|
|
62
76
|
### Documentation
|
|
63
77
|
|
|
64
78
|
* Above every `SmellDetector::sniff` method it should be documented what the expected AST is
|
|
@@ -66,6 +80,8 @@ end
|
|
|
66
80
|
take any arbitrary existing smell detector documentation page as template (since
|
|
67
81
|
they all have the same structure already)
|
|
68
82
|
* The detector should be listed under [Code Smells](docs/Code-Smells.md)
|
|
83
|
+
* Depending on what your detector does it might make sense to add it to other doc pages as
|
|
84
|
+
well e.g. [Simulated Polymorphism](docs/Simulated-Polymorphism.md)
|
|
69
85
|
|
|
70
86
|
### Rspec examples
|
|
71
87
|
|
data/docs/Large-Class.md
CHANGED
|
@@ -9,7 +9,8 @@ size of the corresponding instance of `Class`.)
|
|
|
9
9
|
|
|
10
10
|
## Current Support in Reek
|
|
11
11
|
|
|
12
|
-
Reek offers
|
|
12
|
+
Reek offers three checks in this category.
|
|
13
13
|
|
|
14
|
+
* [Too Many Constants](Too-Many-Constants.md)
|
|
14
15
|
* [Too Many Instance Variables](Too-Many-Instance-Variables.md)
|
|
15
16
|
* [Too Many Methods](Too-Many-Methods.md)
|
|
@@ -13,4 +13,4 @@ Conditional code is hard to read and understand, because the reader must hold mo
|
|
|
13
13
|
|
|
14
14
|
## Current Support in Reek
|
|
15
15
|
|
|
16
|
-
Reek checks for [Repeated Conditional](Repeated-Conditional.md) and for [Nil Check](Nil-Check.md).
|
|
16
|
+
Reek checks for [Manual Dispatch](Manual-Dispatch.md), [Repeated Conditional](Repeated-Conditional.md) and for [Nil Check](Nil-Check.md).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Feature: Erroneous source comments are handled properly
|
|
2
|
+
Erroneous source comments should be handled in a way that is intuitive and helpful
|
|
3
|
+
for the user. Reek should neither crash nor silently swallow it.
|
|
4
|
+
If there is something wrong - no matter how small it is - Reek should report it back
|
|
5
|
+
to the user right away so the user can actually do something about it.
|
|
6
|
+
If a user tries to deactivate an unknown smell detector (e.g. because he made a typo)
|
|
7
|
+
we should just skip this file and tell the user about it so he can fix it and then
|
|
8
|
+
re-run Reek.
|
|
9
|
+
|
|
10
|
+
Scenario: Unknown smell detector
|
|
11
|
+
Given a file named "bad_detector.rb" with:
|
|
12
|
+
"""
|
|
13
|
+
# Test class
|
|
14
|
+
# :reek:UnknownDetectorName
|
|
15
|
+
def x
|
|
16
|
+
end
|
|
17
|
+
"""
|
|
18
|
+
When I run reek bad_detector.rb
|
|
19
|
+
Then it reports the error "Error: You are trying to configure an unknown smell detector 'UnknownDetectorName'"
|
|
20
|
+
|
|
21
|
+
Scenario: One good file, one bad file
|
|
22
|
+
Given a file named "bad_detector.rb" with:
|
|
23
|
+
"""
|
|
24
|
+
# Test class
|
|
25
|
+
# :reek:UnknownDetectorName
|
|
26
|
+
def x
|
|
27
|
+
end
|
|
28
|
+
"""
|
|
29
|
+
Given the smelly file 'smelly.rb'
|
|
30
|
+
When I run reek bad_detector.rb smelly.rb
|
|
31
|
+
Then it reports the error "Error: You are trying to configure an unknown smell detector 'UnknownDetectorName'"
|
|
32
|
+
And the exit status indicates smells
|
|
33
|
+
And it reports:
|
|
34
|
+
"""
|
|
35
|
+
smelly.rb -- 2 warnings:
|
|
36
|
+
[4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
|
|
37
|
+
[5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
|
38
|
+
2 total warnings
|
|
39
|
+
"""
|
data/lib/reek/ast/node.rb
CHANGED
data/lib/reek/code_comment.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require 'yaml'
|
|
3
|
+
require_relative 'smells/smell_detector'
|
|
4
|
+
require_relative 'errors'
|
|
3
5
|
|
|
4
6
|
module Reek
|
|
5
7
|
#
|
|
@@ -25,14 +27,20 @@ module Reek
|
|
|
25
27
|
|
|
26
28
|
#
|
|
27
29
|
# @param comment [String] - the original comment as found in the source code
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
+
# @param line [Integer] - start of the expression the comment belongs to
|
|
31
|
+
# @param source [String] - Path to source file or "string"
|
|
30
32
|
#
|
|
31
|
-
def initialize(comment)
|
|
33
|
+
def initialize(comment:, line: nil, source: nil)
|
|
32
34
|
@original_comment = comment
|
|
33
35
|
@config = Hash.new { |hash, key| hash[key] = {} }
|
|
34
36
|
|
|
35
37
|
@original_comment.scan(CONFIGURATION_REGEX) do |detector, _option_string, options|
|
|
38
|
+
unless Smells::SmellDetector.valid_detector?(detector)
|
|
39
|
+
raise BadDetectorInCommentError, detector: detector,
|
|
40
|
+
source: source,
|
|
41
|
+
line: line,
|
|
42
|
+
original_comment: @original_comment
|
|
43
|
+
end
|
|
36
44
|
@config.merge! detector => YAML.load(options || DISABLE_DETECTOR_CONFIGURATION)
|
|
37
45
|
end
|
|
38
46
|
end
|
|
@@ -161,7 +161,9 @@ module Reek
|
|
|
161
161
|
attr_reader :refs
|
|
162
162
|
|
|
163
163
|
def configuration_via_code_commment
|
|
164
|
-
@configuration_via_code_commment ||= CodeComment.new(full_comment
|
|
164
|
+
@configuration_via_code_commment ||= CodeComment.new(comment: full_comment,
|
|
165
|
+
line: exp.line,
|
|
166
|
+
source: exp.source).config
|
|
165
167
|
end
|
|
166
168
|
|
|
167
169
|
def full_comment
|
|
@@ -64,7 +64,7 @@ module Reek
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def descriptively_commented?
|
|
67
|
-
CodeComment.new(exp.leading_comment).descriptive?
|
|
67
|
+
CodeComment.new(comment: exp.leading_comment).descriptive?
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
# A namespace module is a module (or class) that is only there for namespacing
|
data/lib/reek/errors.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Reek
|
|
3
|
+
# Gets raised when trying to configure a detector which is unknown to us.
|
|
4
|
+
# This might happen for multiple reasons. The users might have a typo in
|
|
5
|
+
# his comment or he might use a detector that does not exist anymore.
|
|
6
|
+
class BadDetectorInCommentError < RuntimeError
|
|
7
|
+
UNKNOWN_SMELL_DETECTOR_MESSAGE = <<-EOS.freeze
|
|
8
|
+
|
|
9
|
+
Error: You are trying to configure an unknown smell detector '%s' in one
|
|
10
|
+
of your source code comments.
|
|
11
|
+
The source is '%s' and the comment belongs to the expression starting in line %d.
|
|
12
|
+
Here's the original comment:
|
|
13
|
+
|
|
14
|
+
%s
|
|
15
|
+
|
|
16
|
+
Please see the Reek docs for:
|
|
17
|
+
* how to configure Reek via source code comments: https://github.com/troessner/reek/blob/master/docs/Smell-Suppression.md
|
|
18
|
+
* what smell detectors are available: https://github.com/troessner/reek/blob/master/docs/Code-Smells.md
|
|
19
|
+
Update the offensive comment (or remove it if no longer applicable) and re-run Reek.
|
|
20
|
+
|
|
21
|
+
EOS
|
|
22
|
+
|
|
23
|
+
def initialize(detector:, source:, line:, original_comment:)
|
|
24
|
+
message = format(UNKNOWN_SMELL_DETECTOR_MESSAGE,
|
|
25
|
+
detector,
|
|
26
|
+
source,
|
|
27
|
+
line,
|
|
28
|
+
original_comment)
|
|
29
|
+
super message
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/reek/examiner.rb
CHANGED
|
@@ -96,12 +96,17 @@ module Reek
|
|
|
96
96
|
# and continue with the analysis.
|
|
97
97
|
#
|
|
98
98
|
# @return [Array<SmellWarning>] the smells found in the source
|
|
99
|
+
#
|
|
100
|
+
# :reek:TooManyStatements { max_statements: 8 }
|
|
99
101
|
def run
|
|
100
102
|
return [] unless syntax_tree
|
|
101
103
|
begin
|
|
102
104
|
examine_tree
|
|
105
|
+
rescue BadDetectorInCommentError => exception
|
|
106
|
+
warn exception
|
|
107
|
+
[]
|
|
103
108
|
rescue StandardError => exception
|
|
104
|
-
|
|
109
|
+
warn format(INCOMPREHENSIBLE_SOURCE_TEMPLATE, origin, exception.inspect)
|
|
105
110
|
[]
|
|
106
111
|
end
|
|
107
112
|
end
|
data/lib/reek/rake/task.rb
CHANGED
|
@@ -40,13 +40,13 @@ module Reek
|
|
|
40
40
|
#
|
|
41
41
|
# :reek:TooManyStatements: { max_statements: 7 }
|
|
42
42
|
# :reek:FeatureEnvy
|
|
43
|
-
def class_variables_in(
|
|
43
|
+
def class_variables_in(exp)
|
|
44
44
|
result = Hash.new { |hash, key| hash[key] = [] }
|
|
45
45
|
collector = proc do |cvar_node|
|
|
46
46
|
result[cvar_node.name].push(cvar_node.line)
|
|
47
47
|
end
|
|
48
48
|
[:cvar, :cvasgn, :cvdecl].each do |stmt_type|
|
|
49
|
-
|
|
49
|
+
exp.each_node(stmt_type, [:class, :module], &collector)
|
|
50
50
|
end
|
|
51
51
|
result
|
|
52
52
|
end
|