forked from troessner/reek
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,693 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Attribute | ||
|
||
## Introduction | ||
|
||
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. | ||
|
||
## Example | ||
|
||
Given: | ||
|
||
```Ruby | ||
class Klass | ||
attr_accessor :dummy | ||
end | ||
``` | ||
|
||
`reek` would emit the following warning: | ||
|
||
``` | ||
reek test.rb | ||
test.rb -- 1 warning: | ||
[2]:Klass declares the attribute dummy (Attribute) | ||
``` | ||
|
||
## Support in Reek | ||
|
||
Right now this smell is disabled by default since it is highly subjective. | ||
|
||
When this detector is enabled it raises a warning for every `attr`, `attr_reader`, `attr_writer` and `attr_accessor` -- including those that are private. | ||
|
||
## Configuration | ||
|
||
If you want to enable it you can do so by placing | ||
|
||
```yaml | ||
Attribute: | ||
enabled: true | ||
``` | ||
in your reek configuration file. | ||
`Attribute` supports only the [Basic Smell Options](Basic-Smell-Options.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Basic Smell Options | ||
|
||
## Introduction | ||
|
||
Every smell detector in Reek offers at least the following configuration options: | ||
|
||
| Option | Value | Effect | | ||
| ---------------|-------------|---------| | ||
| `enabled` | Boolean | Determines whether the smell detector is active. Defaults to `true` | | ||
| `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. | | ||
|
||
The file `config/defaults.reek` (shipped with the Reek gem) lists any default exclusions for each smell. | ||
|
||
## Examples | ||
|
||
<u>An easy one:</u> | ||
|
||
To stop Reek reporting smells in any method called `write` you might create a configuration file containing this: | ||
|
||
```yaml | ||
ControlCouple: | ||
exclude: | ||
- write | ||
``` | ||
Or a little more sophisticated using a ruby regex like this: | ||
```yaml | ||
ControlCouple: | ||
exclude: | ||
- !ruby/regexp /write/ | ||
``` | ||
<u>A more sophisticated one:</u> | ||
```yaml | ||
FeatureEnvy: | ||
exclude: | ||
- "MyModel#do_things" | ||
- "MyHelper" | ||
- "ApplicationController#respond" | ||
``` | ||
This would not report FeatureEnvy for the instance method `MyModel#do_things`, the whole module `MyHelper` and the `respond` instance method of `ApplicationController` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Boolean Parameter | ||
|
||
## Introduction | ||
|
||
`Boolean Parameter` is a special case of [Control Couple](Control-Couple.md), where a method parameter is defaulted | ||
to true or false. A _Boolean Parameter_ effectively permits a method's caller | ||
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. | ||
|
||
## Example | ||
|
||
Given | ||
|
||
```Ruby | ||
class Dummy | ||
def hit_the_switch(switch = true) | ||
if switch | ||
puts 'Hitting the switch' | ||
# do other things... | ||
else | ||
puts 'Not hitting the switch' | ||
# do other things... | ||
end | ||
end | ||
end | ||
``` | ||
|
||
`reek` would emit the following warning: | ||
|
||
``` | ||
test.rb -- 3 warnings: | ||
[1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter) | ||
[2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter) | ||
``` | ||
|
||
Note that both smells are reported, `Boolean Parameter` and `Control Parameter`. | ||
|
||
## Getting rid of the smell | ||
|
||
This is highly dependant on your exact architecture, but looking at the example above what you could do is: | ||
|
||
* Move everything in the `if` branch into a separate method | ||
* Move everything in the `else` branch into a separate method | ||
* Get rid of the `hit_the_switch` method alltogether | ||
* Make the decision what method to call in the initial caller of `hit_the_switch` | ||
|
||
## Current support in Reek | ||
|
||
Reek can only detect a Boolean parameter when it has a default initializer like in the example above. | ||
|
||
## Configuration | ||
|
||
`Boolean Parameter` supports the [Basic Smell Options](Basic-Smell-Options.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Class Variable | ||
|
||
## Introduction | ||
|
||
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). | ||
|
||
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/) | ||
|
||
## Example | ||
|
||
Given | ||
|
||
```Ruby | ||
class Dummy | ||
@@class_variable = :whatever | ||
end | ||
``` | ||
|
||
`reek` would emit the following warning: | ||
|
||
``` | ||
reek test.rb | ||
test.rb -- 1 warning: | ||
[2]:Dummy declares the class variable @@class_variable (ClassVariable) | ||
``` | ||
|
||
## Getting rid of the smell | ||
|
||
You can use class-instance variable to mitigate the problem (as also suggested in the linked article above): | ||
|
||
```Ruby | ||
class Dummy | ||
@class_variable = :whatever | ||
end | ||
``` | ||
|
||
## Configuration | ||
|
||
`Class Variable` supports the [Basic Smell Options](Basic-Smell-Options.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Code Smells | ||
|
||
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). | ||
|
||
Reek currently includes checks for the following smells: | ||
|
||
* [Attribute](Attribute.md) (disabled by default) | ||
* [Class Variable](Class-Variable.md) | ||
* [Control Couple](Control-Couple.md), including | ||
* [Boolean Parameter](Boolean-Parameter.md) | ||
* [Control Parameter](Control-Parameter.md) | ||
* [Data Clump](Data-Clump.md) | ||
* [Duplicate Method Call](Duplicate-Method-Call.md) | ||
* [Irresponsible Module](Irresponsible-Module.md) | ||
* [Large Class](Large-Class.md), including | ||
* [Too Many Instance Variables](Too-Many-Instance-Variables.md) | ||
* [Too Many Methods](Too-Many-Methods.md) | ||
* [Long Parameter List](Long-Parameter-List.md), and its special case [Long Yield List](Long-Yield-List.md) | ||
* Low Cohesion, including | ||
* [Feature Envy](Feature-Envy.md) | ||
* [Utility Function](Utility-Function.md) | ||
* [Module Initialize](Module-Initialize.md) | ||
* [Nested Iterators](Nested-Iterators.md) | ||
* [Prima-Donna-Method](Prima-Donna-Method.md) | ||
* [Simulated Polymorphism](Simulated-Polymorphism.md), including | ||
* [Nil Check](Nil-Check.md) | ||
* [Repeated Conditional](Repeated-Conditional.md) | ||
* [Too Many Statements](Too-Many-Statements.md) | ||
* [Uncommunicative Name](Uncommunicative-Name.md), including | ||
* [Uncommunicative Method Name](Uncommunicative-Method-Name.md) | ||
* [Uncommunicative Module Name](Uncommunicative-Module-Name.md) | ||
* [Uncommunicative Parameter Name](Uncommunicative-Parameter-Name.md) | ||
* [Uncommunicative Variable Name](Uncommunicative-Variable-Name.md) | ||
* [Unused Parameters](Unused-Parameters.md) |
Oops, something went wrong.