reek 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -21
- data/.travis.yml +1 -0
- data/.yardopts +3 -6
- data/CHANGELOG +6 -0
- data/CONTRIBUTING.md +8 -3
- data/README.md +94 -42
- data/config/defaults.reek +0 -1
- data/docs/API.md +50 -0
- data/docs/Attribute.md +43 -0
- data/docs/Basic-Smell-Options.md +44 -0
- data/docs/Boolean-Parameter.md +52 -0
- data/docs/Class-Variable.md +40 -0
- data/docs/Code-Smells.md +34 -0
- data/docs/Command-Line-Options.md +84 -0
- data/docs/Configuration-Files.md +38 -0
- data/docs/Control-Couple.md +22 -0
- data/docs/Control-Parameter.md +29 -0
- data/docs/Data-Clump.md +44 -0
- data/docs/Duplicate-Method-Call.md +49 -0
- data/docs/Feature-Envy.md +29 -0
- data/docs/How-reek-works-internally.md +44 -0
- data/docs/Irresponsible-Module.md +39 -0
- data/docs/Large-Class.md +20 -0
- data/docs/Long-Parameter-List.md +38 -0
- data/docs/Long-Yield-List.md +36 -0
- data/docs/Module-Initialize.md +62 -0
- data/docs/Nested-Iterators.md +38 -0
- data/docs/Nil-Check.md +39 -0
- data/docs/Prima-Donna-Method.md +53 -0
- data/docs/RSpec-matchers.md +133 -0
- data/docs/Rake-Task.md +58 -0
- data/docs/Reek-Driven-Development.md +45 -0
- data/docs/Repeated-Conditional.md +44 -0
- data/docs/Simulated-Polymorphism.md +16 -0
- data/docs/Smell-Suppression.md +32 -0
- data/docs/Too-Many-Instance-Variables.md +43 -0
- data/docs/Too-Many-Methods.md +55 -0
- data/docs/Too-Many-Statements.md +50 -0
- data/docs/Uncommunicative-Method-Name.md +24 -0
- data/docs/Uncommunicative-Module-Name.md +23 -0
- data/docs/Uncommunicative-Name.md +16 -0
- data/docs/Uncommunicative-Parameter-Name.md +24 -0
- data/docs/Uncommunicative-Variable-Name.md +24 -0
- data/docs/Unused-Parameters.md +27 -0
- data/docs/Utility-Function.md +46 -0
- data/docs/Versioning-Policy.md +7 -0
- data/docs/YAML-Reports.md +111 -0
- data/docs/yard_plugin.rb +14 -0
- data/features/command_line_interface/options.feature +1 -0
- data/features/programmatic_access.feature +1 -1
- data/features/samples.feature +3 -3
- data/lib/reek.rb +2 -2
- data/lib/reek/cli/input.rb +2 -2
- data/lib/reek/cli/option_interpreter.rb +2 -0
- data/lib/reek/cli/options.rb +10 -4
- data/lib/reek/cli/reek_command.rb +2 -2
- data/lib/reek/cli/report/report.rb +60 -0
- data/lib/reek/cli/silencer.rb +13 -0
- data/lib/reek/{source → core}/ast_node.rb +1 -1
- data/lib/reek/{source → core}/ast_node_class_map.rb +10 -11
- data/lib/reek/{source → core}/code_comment.rb +1 -1
- data/lib/reek/core/code_context.rb +1 -1
- data/lib/reek/core/examiner.rb +85 -0
- data/lib/reek/core/method_context.rb +1 -1
- data/lib/reek/core/module_context.rb +2 -2
- data/lib/reek/core/reference_collector.rb +31 -0
- data/lib/reek/core/singleton_method_context.rb +0 -4
- data/lib/reek/core/smell_repository.rb +4 -2
- data/lib/reek/{source → core}/tree_dresser.rb +1 -1
- data/lib/reek/{source → sexp}/sexp_extensions.rb +5 -5
- data/lib/reek/sexp/sexp_formatter.rb +29 -0
- data/lib/reek/sexp/sexp_node.rb +91 -0
- data/lib/reek/smells.rb +4 -2
- data/lib/reek/smells/attribute.rb +35 -7
- data/lib/reek/smells/boolean_parameter.rb +1 -1
- data/lib/reek/smells/class_variable.rb +1 -1
- data/lib/reek/smells/control_parameter.rb +1 -1
- data/lib/reek/smells/data_clump.rb +1 -1
- data/lib/reek/smells/duplicate_method_call.rb +12 -4
- data/lib/reek/smells/feature_envy.rb +1 -1
- data/lib/reek/smells/irresponsible_module.rb +3 -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 +1 -1
- data/lib/reek/smells/nil_check.rb +3 -2
- data/lib/reek/smells/prima_donna_method.rb +18 -11
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_detector.rb +5 -1
- data/lib/reek/smells/smell_warning.rb +99 -0
- 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/utility_function.rb +3 -16
- data/lib/reek/source/source_code.rb +31 -13
- data/lib/reek/source/source_locator.rb +16 -17
- data/lib/reek/source/source_repository.rb +10 -11
- data/lib/reek/spec/should_reek.rb +2 -2
- data/lib/reek/spec/should_reek_of.rb +2 -2
- data/lib/reek/spec/should_reek_only_of.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +3 -4
- data/spec/factories/factories.rb +1 -1
- data/spec/gem/yard_spec.rb +1 -1
- data/spec/quality/reek_source_spec.rb +2 -2
- data/spec/reek/cli/html_report_spec.rb +3 -3
- data/spec/reek/cli/json_report_spec.rb +3 -3
- data/spec/reek/cli/{option_interperter_spec.rb → option_interpreter_spec.rb} +1 -1
- data/spec/reek/cli/options_spec.rb +19 -0
- data/spec/reek/cli/text_report_spec.rb +7 -7
- data/spec/reek/cli/xml_report_spec.rb +34 -0
- data/spec/reek/cli/yaml_report_spec.rb +3 -3
- data/spec/reek/configuration/app_configuration_spec.rb +1 -1
- data/spec/reek/configuration/configuration_file_finder_spec.rb +22 -1
- data/spec/reek/{source → core}/code_comment_spec.rb +14 -14
- data/spec/reek/core/code_context_spec.rb +1 -1
- data/spec/reek/{examiner_spec.rb → core/examiner_spec.rb} +12 -12
- data/spec/reek/core/method_context_spec.rb +27 -22
- data/spec/reek/core/module_context_spec.rb +2 -2
- data/spec/reek/core/object_refs_spec.rb +1 -1
- data/spec/reek/{source → core}/object_source_spec.rb +1 -1
- data/spec/reek/{source → core}/reference_collector_spec.rb +25 -16
- data/spec/reek/core/singleton_method_context_spec.rb +12 -2
- data/spec/reek/core/smell_configuration_spec.rb +1 -1
- data/spec/reek/core/smell_repository_spec.rb +12 -1
- data/spec/reek/core/stop_context_spec.rb +1 -1
- data/spec/reek/core/tree_dresser_spec.rb +16 -0
- data/spec/reek/core/tree_walker_spec.rb +3 -3
- data/spec/reek/core/warning_collector_spec.rb +6 -6
- data/spec/reek/{source → sexp}/sexp_extensions_spec.rb +8 -8
- data/spec/reek/{source → sexp}/sexp_formatter_spec.rb +11 -5
- data/spec/reek/{source → sexp}/sexp_node_spec.rb +3 -3
- data/spec/reek/smells/attribute_spec.rb +89 -85
- data/spec/reek/smells/behaves_like_variable_detector.rb +1 -1
- data/spec/reek/smells/boolean_parameter_spec.rb +1 -1
- data/spec/reek/smells/class_variable_spec.rb +1 -1
- data/spec/reek/smells/control_parameter_spec.rb +1 -1
- data/spec/reek/smells/data_clump_spec.rb +2 -2
- data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
- data/spec/reek/smells/feature_envy_spec.rb +2 -2
- data/spec/reek/smells/irresponsible_module_spec.rb +1 -1
- data/spec/reek/smells/long_parameter_list_spec.rb +2 -2
- data/spec/reek/smells/long_yield_list_spec.rb +1 -1
- data/spec/reek/smells/module_initialize_spec.rb +1 -1
- data/spec/reek/smells/nested_iterators_spec.rb +2 -2
- data/spec/reek/smells/nil_check_spec.rb +1 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +1 -1
- data/spec/reek/smells/repeated_conditional_spec.rb +1 -1
- data/spec/reek/smells/smell_detector_shared.rb +2 -2
- data/spec/reek/{smell_warning_spec.rb → smells/smell_warning_spec.rb} +7 -7
- 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 +4 -4
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +1 -1
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +1 -1
- data/spec/reek/smells/unused_parameters_spec.rb +1 -1
- data/spec/reek/smells/utility_function_spec.rb +1 -1
- data/spec/reek/source/source_code_spec.rb +1 -1
- data/spec/reek/spec/should_reek_of_spec.rb +1 -1
- data/spec/reek/spec/should_reek_only_of_spec.rb +1 -1
- data/spec/reek/spec/should_reek_spec.rb +1 -1
- data/spec/samples/checkstyle.xml +2 -0
- data/spec/spec_helper.rb +15 -3
- metadata +68 -38
- data/.ruby-gemset +0 -1
- data/lib/reek/examiner.rb +0 -79
- data/lib/reek/smell_warning.rb +0 -87
- data/lib/reek/source/reference_collector.rb +0 -27
- data/lib/reek/source/sexp_formatter.rb +0 -22
- data/lib/reek/source/sexp_node.rb +0 -79
- data/spec/reek/source/tree_dresser_spec.rb +0 -16
data/docs/Attribute.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Attribute
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
A class that publishes a getter or setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
Given:
|
10
|
+
|
11
|
+
```Ruby
|
12
|
+
class Klass
|
13
|
+
attr_accessor :dummy
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
`reek` would emit the following warning:
|
18
|
+
|
19
|
+
```
|
20
|
+
reek test.rb
|
21
|
+
|
22
|
+
test.rb -- 1 warning:
|
23
|
+
[2]:Klass declares the attribute dummy (Attribute)
|
24
|
+
```
|
25
|
+
|
26
|
+
## Support in Reek
|
27
|
+
|
28
|
+
Right now this smell is disabled by default since it is highly subjective.
|
29
|
+
|
30
|
+
When this detector is enabled it raises a warning for every `attr`, `attr_reader`, `attr_writer` and `attr_accessor` -- including those that are private.
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
If you want to enable it you can do so by placing
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
Attribute:
|
38
|
+
enabled: true
|
39
|
+
```
|
40
|
+
|
41
|
+
in your reek configuration file.
|
42
|
+
|
43
|
+
`Attribute` supports only the [Basic Smell Options](Basic-Smell-Options.md).
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Basic Smell Options
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Every smell detector in Reek offers at least the following configuration options:
|
6
|
+
|
7
|
+
| Option | Value | Effect |
|
8
|
+
| ---------------|-------------|---------|
|
9
|
+
| `enabled` | Boolean | Determines whether the smell detector is active. Defaults to `true` |
|
10
|
+
| `exclude` | an array of strings or regular expressions | Ignores any context whose full description (see <strong>%c</strong> in [Command-Line Options](Command-Line-Options.md)) matches any element of this array. |
|
11
|
+
|
12
|
+
The file `config/defaults.reek` (shipped with the Reek gem) lists any default exclusions for each smell.
|
13
|
+
|
14
|
+
## Examples
|
15
|
+
|
16
|
+
<u>An easy one:</u>
|
17
|
+
|
18
|
+
To stop Reek reporting smells in any method called `write` you might create a configuration file containing this:
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
ControlCouple:
|
22
|
+
exclude:
|
23
|
+
- write
|
24
|
+
```
|
25
|
+
|
26
|
+
Or a little more sophisticated using a ruby regex like this:
|
27
|
+
|
28
|
+
```yaml
|
29
|
+
ControlCouple:
|
30
|
+
exclude:
|
31
|
+
- !ruby/regexp /write/
|
32
|
+
```
|
33
|
+
|
34
|
+
<u>A more sophisticated one:</u>
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
FeatureEnvy:
|
38
|
+
exclude:
|
39
|
+
- "MyModel#do_things"
|
40
|
+
- "MyHelper"
|
41
|
+
- "ApplicationController#respond"
|
42
|
+
```
|
43
|
+
|
44
|
+
This would not report FeatureEnvy for the instance method `MyModel#do_things`, the whole module `MyHelper` and the `respond` instance method of `ApplicationController`
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Boolean Parameter
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
`Boolean Parameter` is a special case of [Control Couple](Control-Couple.md), where a method parameter is defaulted
|
6
|
+
to true or false. A _Boolean Parameter_ effectively permits a method's caller
|
7
|
+
to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.
|
8
|
+
|
9
|
+
## Example
|
10
|
+
|
11
|
+
Given
|
12
|
+
|
13
|
+
```Ruby
|
14
|
+
class Dummy
|
15
|
+
def hit_the_switch(switch = true)
|
16
|
+
if switch
|
17
|
+
puts 'Hitting the switch'
|
18
|
+
# do other things...
|
19
|
+
else
|
20
|
+
puts 'Not hitting the switch'
|
21
|
+
# do other things...
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
`reek` would emit the following warning:
|
28
|
+
|
29
|
+
```
|
30
|
+
test.rb -- 3 warnings:
|
31
|
+
[1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
|
32
|
+
[2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)
|
33
|
+
```
|
34
|
+
|
35
|
+
Note that both smells are reported, `Boolean Parameter` and `Control Parameter`.
|
36
|
+
|
37
|
+
## Getting rid of the smell
|
38
|
+
|
39
|
+
This is highly dependant on your exact architecture, but looking at the example above what you could do is:
|
40
|
+
|
41
|
+
* Move everything in the `if` branch into a separate method
|
42
|
+
* Move everything in the `else` branch into a separate method
|
43
|
+
* Get rid of the `hit_the_switch` method alltogether
|
44
|
+
* Make the decision what method to call in the initial caller of `hit_the_switch`
|
45
|
+
|
46
|
+
## Current support in Reek
|
47
|
+
|
48
|
+
Reek can only detect a Boolean parameter when it has a default initializer like in the example above.
|
49
|
+
|
50
|
+
## Configuration
|
51
|
+
|
52
|
+
`Boolean Parameter` supports the [Basic Smell Options](Basic-Smell-Options.md).
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Class Variable
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Class variables form part of the global runtime state, and as such make it easy for one part of the system to accidentally or inadvertently depend on another part of the system. So the system becomes more prone to problems where changing something over here breaks something over there. In particular, class variables can make it hard to set up tests (because the context of the test includes all global state).
|
6
|
+
|
7
|
+
For a detailed explanation, check out [this article](http://4thmouse.com/index.php/2011/03/20/why-class-variables-in-ruby-are-a-bad-idea/)
|
8
|
+
|
9
|
+
## Example
|
10
|
+
|
11
|
+
Given
|
12
|
+
|
13
|
+
```Ruby
|
14
|
+
class Dummy
|
15
|
+
@@class_variable = :whatever
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
`reek` would emit the following warning:
|
20
|
+
|
21
|
+
```
|
22
|
+
reek test.rb
|
23
|
+
|
24
|
+
test.rb -- 1 warning:
|
25
|
+
[2]:Dummy declares the class variable @@class_variable (ClassVariable)
|
26
|
+
```
|
27
|
+
|
28
|
+
## Getting rid of the smell
|
29
|
+
|
30
|
+
You can use class-instance variable to mitigate the problem (as also suggested in the linked article above):
|
31
|
+
|
32
|
+
```Ruby
|
33
|
+
class Dummy
|
34
|
+
@class_variable = :whatever
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Configuration
|
39
|
+
|
40
|
+
`Class Variable` supports the [Basic Smell Options](Basic-Smell-Options.md).
|
data/docs/Code-Smells.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Code Smells
|
2
|
+
|
3
|
+
Smells are indicators of where your code might be hard to read, maintain or evolve, rather than things that are specifically _wrong_. Naturally this means that Reek is looking towards your code's future (and that can make its reports seem somewhat subjective, of course).
|
4
|
+
|
5
|
+
Reek currently includes checks for the following smells:
|
6
|
+
|
7
|
+
* [Attribute](Attribute.md) (disabled by default)
|
8
|
+
* [Class Variable](Class-Variable.md)
|
9
|
+
* [Control Couple](Control-Couple.md), including
|
10
|
+
* [Boolean Parameter](Boolean-Parameter.md)
|
11
|
+
* [Control Parameter](Control-Parameter.md)
|
12
|
+
* [Data Clump](Data-Clump.md)
|
13
|
+
* [Duplicate Method Call](Duplicate-Method-Call.md)
|
14
|
+
* [Irresponsible Module](Irresponsible-Module.md)
|
15
|
+
* [Large Class](Large-Class.md), including
|
16
|
+
* [Too Many Instance Variables](Too-Many-Instance-Variables.md)
|
17
|
+
* [Too Many Methods](Too-Many-Methods.md)
|
18
|
+
* [Long Parameter List](Long-Parameter-List.md), and its special case [Long Yield List](Long-Yield-List.md)
|
19
|
+
* Low Cohesion, including
|
20
|
+
* [Feature Envy](Feature-Envy.md)
|
21
|
+
* [Utility Function](Utility-Function.md)
|
22
|
+
* [Module Initialize](Module-Initialize.md)
|
23
|
+
* [Nested Iterators](Nested-Iterators.md)
|
24
|
+
* [Prima-Donna-Method](Prima-Donna-Method.md)
|
25
|
+
* [Simulated Polymorphism](Simulated-Polymorphism.md), including
|
26
|
+
* [Nil Check](Nil-Check.md)
|
27
|
+
* [Repeated Conditional](Repeated-Conditional.md)
|
28
|
+
* [Too Many Statements](Too-Many-Statements.md)
|
29
|
+
* [Uncommunicative Name](Uncommunicative-Name.md), including
|
30
|
+
* [Uncommunicative Method Name](Uncommunicative-Method-Name.md)
|
31
|
+
* [Uncommunicative Module Name](Uncommunicative-Module-Name.md)
|
32
|
+
* [Uncommunicative Parameter Name](Uncommunicative-Parameter-Name.md)
|
33
|
+
* [Uncommunicative Variable Name](Uncommunicative-Variable-Name.md)
|
34
|
+
* [Unused Parameters](Unused-Parameters.md)
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Command Line Options
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
reek follows standard Unix convention for passing arguments.
|
6
|
+
|
7
|
+
Check out
|
8
|
+
|
9
|
+
```Bash
|
10
|
+
reek -h
|
11
|
+
```
|
12
|
+
|
13
|
+
for details.
|
14
|
+
|
15
|
+
## Telling Reek Which Code to Check
|
16
|
+
|
17
|
+
Probably the most standard use case would be to check all ruby files in the lib directory:
|
18
|
+
|
19
|
+
```Bash
|
20
|
+
reek lib/*.rb
|
21
|
+
```
|
22
|
+
|
23
|
+
In general, if any command-line argument is a directory, Reek searches that directory and all sub-directories for Ruby source files. Thus
|
24
|
+
|
25
|
+
```Bash
|
26
|
+
reek lib
|
27
|
+
```
|
28
|
+
|
29
|
+
would be equivalent to
|
30
|
+
|
31
|
+
```Bash
|
32
|
+
reek lib/**/*.rb
|
33
|
+
```
|
34
|
+
|
35
|
+
Occasionally you may want to quickly check a code snippet without going to the trouble of creating a file to hold it. You can pass the snippet directly to Reek's standard input:
|
36
|
+
|
37
|
+
```Bash
|
38
|
+
echo "def x() true end" | reek
|
39
|
+
```
|
40
|
+
|
41
|
+
## Output options
|
42
|
+
|
43
|
+
### Output smell's line number
|
44
|
+
|
45
|
+
By passing in a "-n" flag to the _reek_ command, the output will suppress the line numbers:
|
46
|
+
|
47
|
+
```Bash
|
48
|
+
$ reek -n mess.rb
|
49
|
+
```
|
50
|
+
|
51
|
+
```
|
52
|
+
mess.rb -- 2 warnings:
|
53
|
+
x doesn't depend on instance state (UtilityFunction)
|
54
|
+
x has the name 'x' (UncommunicativeMethodName)
|
55
|
+
```
|
56
|
+
|
57
|
+
Otherwise line numbers will be shown as default at the beginning of each warning in square brackets:
|
58
|
+
|
59
|
+
```Bash
|
60
|
+
$ reek mess.rb
|
61
|
+
```
|
62
|
+
|
63
|
+
```
|
64
|
+
mess.rb -- 2 warnings:
|
65
|
+
[2]:x doesn't depend on instance state (UtilityFunction)
|
66
|
+
[2]:x has the name 'x' (UncommunicativeMethodName)
|
67
|
+
```
|
68
|
+
|
69
|
+
### Enable the ultra-verbose mode
|
70
|
+
|
71
|
+
_reek_ has a ultra-verbose mode which you might find helpful as a beginner. "ultra-verbose" just means that behind each warning a helpful link will be displayed which leads directly to the corresponding _reek_ wiki page.
|
72
|
+
This mode can be enabled via the "-U" or "--ultra-verbose" flag.
|
73
|
+
|
74
|
+
So for instance, if your test file would smell of _ClassVariable_, this is what the _reek_ output would look like:
|
75
|
+
|
76
|
+
```Bash
|
77
|
+
reek -U test.rb
|
78
|
+
```
|
79
|
+
```
|
80
|
+
test.rb -- 1 warning:
|
81
|
+
[2]:Dummy declares the class variable @@class_variable (ClassVariable) [https://github.com/troessner/reek/wiki/Class-Variable]
|
82
|
+
```
|
83
|
+
|
84
|
+
Note the link at the end.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Configuration Files
|
2
|
+
|
3
|
+
## Configuration loading
|
4
|
+
|
5
|
+
Configuring `reek` via configuration file is by far the most powerful way.
|
6
|
+
|
7
|
+
There are 3 ways of passing `reek` a configuration file:
|
8
|
+
|
9
|
+
1. Using the cli "-c" switch (see [Command Line Options](Command-Line-Options.md))
|
10
|
+
2. Having a file ending with .reek either in your current working directory or in a parent directory (more on that later)
|
11
|
+
3. Having a file ending with .reek in your HOME directory
|
12
|
+
|
13
|
+
The order in which `reek` tries to find such a configuration file is exactly like above: First `reek` checks if we have given it a configuration file explicitly via CLI. Then it checks the current working directory for a file and if it can't find one, it traverses up the directories until it hits the root directory. And lastly, it checks your HOME directory.
|
14
|
+
|
15
|
+
As soon as `reek` detects a configuration file it stops searching immediately, meaning that from `reek`'s point of view there exists one configuration file and one configuration only regardless of how many ".reek" files you might have on your filesystem.
|
16
|
+
|
17
|
+
## Configuration options
|
18
|
+
|
19
|
+
The first thing you probably want to check out are the [Basic Smell Options](Basic-Smell-Options.md) which are supported by every smell type.
|
20
|
+
Certain smell types offer a configuration that goes beyond that of the basic smell options - for instance [Data Clump](Data-Clump.md).
|
21
|
+
All options that go beyond the [Basic Smell Options](Basic-Smell-Options.md) should be documented in the corresponding smell type wiki page but if you want to get a quick and full overview over all possible configurations you can always check out [the default.reek file in this repository](https://github.com/troessner/reek/blob/master/config/defaults.reek).
|
22
|
+
|
23
|
+
Here's an excerpt of a `reek` configuration file from a commercial project:
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
---
|
27
|
+
IrresponsibleModule:
|
28
|
+
enabled: false
|
29
|
+
NestedIterators:
|
30
|
+
exclude:
|
31
|
+
- "ActiveModelErrorAdder#self.run" # should be refactored
|
32
|
+
- "BookingRequests::Transfer#remote_validation"
|
33
|
+
- "BookingRequestsController#vehicle_options" # respond_to block
|
34
|
+
- "Content::Base#self.expose_fields" # unavoidable due to metaprogramming
|
35
|
+
DataClump:
|
36
|
+
max_copies: 3
|
37
|
+
min_clump_size: 3
|
38
|
+
```
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Control Couple
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Control coupling occurs when a method or block checks the value of a parameter in order to decide which execution path to take. The offending parameter is often called a `Control Couple`.
|
6
|
+
|
7
|
+
Control Coupling is a kind of duplication, because the calling method already knows which path should be taken.
|
8
|
+
|
9
|
+
Control Coupling reduces the code's flexibility by creating a dependency between the caller and callee: any change to the possible values of the controlling parameter must be reflected on both sides of the call. A `Control Couple` also reveals a loss of simplicity: the called method probably has more than one responsibility, because it includes at least two different code paths.
|
10
|
+
|
11
|
+
You can find a good write-up regarding this problem [here](http://solnic.eu/2012/04/11/get-rid-of-that-code-smell-control-couple.html).
|
12
|
+
|
13
|
+
## Current Support in reek
|
14
|
+
|
15
|
+
`reek` warns about control coupling when:
|
16
|
+
|
17
|
+
* [Control-Parameter](Control-Parameter.md) - a method parameter or block parameter is the tested value in a conditional statement (as in the example below); or
|
18
|
+
* [Boolean-Parameter](Boolean-Parameter.md) - a method parameter is defaulted to `true` or `false`.
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
Control Couple supports the [Basic Smell Options](Basic-Smell-Options.md).
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Control Parameter
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
`Control Parameter` is a special case of [Control Couple](Control-Couple.md)
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
A simple example would be the "quoted" parameter in the following method:
|
10
|
+
|
11
|
+
```Ruby
|
12
|
+
def write(quoted)
|
13
|
+
if quoted
|
14
|
+
write_quoted @value
|
15
|
+
else
|
16
|
+
write_unquoted @value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "write_quoted" / "write_unquoted" in the initial caller of "write".
|
22
|
+
|
23
|
+
## Current Support in reek
|
24
|
+
|
25
|
+
`reek` warns about control coupling when a method parameter or block parameter is the tested value in a conditional statement.
|
26
|
+
|
27
|
+
## Configuration
|
28
|
+
|
29
|
+
Control Couple supports the [Basic Smell Options](Basic-Smell-Options.md).
|
data/docs/Data-Clump.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Data Clump
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
In general, a `Data Clump` occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.
|
6
|
+
|
7
|
+
The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.
|
8
|
+
|
9
|
+
## Example
|
10
|
+
|
11
|
+
Given
|
12
|
+
|
13
|
+
```Ruby
|
14
|
+
class Dummy
|
15
|
+
def x(y1,y2); end
|
16
|
+
def y(y1,y2); end
|
17
|
+
def z(y1,y2); end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
`reek` would emit the following warning:
|
22
|
+
|
23
|
+
```
|
24
|
+
test.rb -- 1 warning:
|
25
|
+
[2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)
|
26
|
+
```
|
27
|
+
|
28
|
+
A possible way to fix this problem (quoting from [Martin Fowler](http://martinfowler.com/bliki/DataClump.html)):
|
29
|
+
|
30
|
+
>> The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.
|
31
|
+
|
32
|
+
## Current Support in Reek
|
33
|
+
|
34
|
+
`reek` looks for a group of two or more parameters with the same names that are expected by three or more methods of a class.
|
35
|
+
|
36
|
+
## Configuration
|
37
|
+
|
38
|
+
Reek's Data Clump detector offers the [Basic Smell Options](Basic-Smell-Options.md), plus:
|
39
|
+
|
40
|
+
| Option | Value | Effect |
|
41
|
+
| ---------------|-------------|---------|
|
42
|
+
| max_copies | integer | The maximum number of methods that are permitted to take the same group of parameters. Defaults to 2 |
|
43
|
+
| min_clump_size | integer | The smallest number of parameters that can be reported as a clump. Defaults to 2 |
|
44
|
+
|