reek 4.0.0.pre1 → 4.0.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +11 -2
  3. data/.gitignore +1 -0
  4. data/.travis.yml +1 -0
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +3 -0
  7. data/README.md +2 -0
  8. data/docs/Attribute.md +1 -1
  9. data/docs/Uncommunicative-Method-Name.md +32 -2
  10. data/docs/Uncommunicative-Module-Name.md +29 -2
  11. data/docs/Uncommunicative-Parameter-Name.md +30 -2
  12. data/features/configuration_files/accept_setting.feature +70 -0
  13. data/features/configuration_files/exclude_directives.feature +34 -0
  14. data/features/configuration_files/mix_accept_reject_setting.feature +81 -0
  15. data/features/configuration_files/reject_setting.feature +78 -0
  16. data/features/configuration_files/unused_private_method.feature +66 -0
  17. data/lib/reek/configuration/app_configuration.rb +0 -30
  18. data/lib/reek/context/method_context.rb +15 -1
  19. data/lib/reek/smells/uncommunicative_method_name.rb +8 -7
  20. data/lib/reek/smells/uncommunicative_module_name.rb +8 -8
  21. data/lib/reek/smells/uncommunicative_parameter_name.rb +9 -7
  22. data/lib/reek/smells/unused_private_method.rb +7 -2
  23. data/lib/reek/version.rb +1 -1
  24. data/reek.gemspec +3 -4
  25. data/spec/reek/configuration/app_configuration_spec.rb +6 -27
  26. data/spec/reek/smells/uncommunicative_method_name_spec.rb +72 -16
  27. data/spec/reek/smells/uncommunicative_module_name_spec.rb +60 -47
  28. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +55 -9
  29. data/spec/reek/smells/unused_parameters_spec.rb +9 -0
  30. data/spec/reek/smells/unused_private_method_spec.rb +38 -0
  31. data/spec/reek/smells/utility_function_spec.rb +3 -5
  32. data/spec/spec_helper.rb +28 -1
  33. metadata +11 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8309582de93065645810663cbed12c501ffe0b68
4
- data.tar.gz: 73712e80702d432edc320bb5531846d3eefcf266
3
+ metadata.gz: d3d1f1d919181f67b1404d126a1dd1e92b6b36e3
4
+ data.tar.gz: cd338514426fb1ea540fc73a0192fb7e492edcbc
5
5
  SHA512:
6
- metadata.gz: bce9a189c55a37b998dbe35a353fd3ab0ec8379a7c8e058712be3d8d3d5a2c0e111375ccb1b12f2146deea7225272a4cfcfe06c2e199d3d0aa75d8450a179cc7
7
- data.tar.gz: dc7cca14a3c083bd41ce51f6cfbbd1da3339bd70c53282fa1f1d3d73102a3f06fa5718af8c61a339bab10210e558bf626d50e315a822ae3f3168dfefb4b2ddd5
6
+ metadata.gz: 706c68a4e8ce046d345b4e6f6acdcbe767d47becb217e01b62c10e7029e3490b7e8f2f98c8fadfd52264e68f855da40d1243ed536206ce168fe35ebb4baea9cf
7
+ data.tar.gz: a94a1759d26ec2cf3da345116ebb55736eff62963b750f414b3387f189ee4b46f7413b872e9c2ccbe24bdeab9b46370cb7175487dadb92af4155a03cfb6a83d3
data/.codeclimate.yml CHANGED
@@ -1,7 +1,16 @@
1
- ---
2
1
  engines:
2
+ rubocop:
3
+ enabled: true
3
4
  reek:
4
5
  enabled: true
5
6
  ratings:
6
7
  paths:
7
- - "**.rb"
8
+ - lib/**/*
9
+ exclude_paths:
10
+ - coverage/
11
+ - docs/
12
+ - features/
13
+ - logo/
14
+ - pkg/
15
+ - spec/
16
+ - tmp/
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ tags
14
14
  .tags*
15
15
  .DS_Store
16
16
  .idea/
17
+ .rbenv-gemsets
data/.travis.yml CHANGED
@@ -5,6 +5,7 @@ bundler_args: --without debugging
5
5
  script:
6
6
  - bundle exec rake
7
7
  - bundle exec ataru check
8
+ - bundle exec mutant --include lib --require reek --use rspec --since master --jobs 4 "Reek*"
8
9
  rvm:
9
10
  - 2.1
10
11
  - 2.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 4.0.0 (2016-03-21)
4
+
5
+ * (troessner) Fix disabling UnusedPrivateMethod via `exclude` in configuration.
6
+ * (troessner) Fix `accept` and `reject` configuration handling.
7
+ * (troessner) Fix UnusedParameter detector for lvasgn.
8
+ * (troessner) Remove deprecated method `from_map` from `AppConfiguration`.
9
+ The successor is `AppConfiguration.from_hash`.
10
+
3
11
  ## 4.0.0.pre1 (2016-03-01)
4
12
 
5
13
  * First pre-release for Reek 4.
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ group :development do
12
12
  gem 'rubocop', '~> 0.37.0'
13
13
  gem 'yard', '~> 0.8.7'
14
14
  gem 'simplecov', '~> 0.11.1'
15
+ gem 'mutant-rspec', '~> 0.8.8'
15
16
 
16
17
  platforms :mri do
17
18
  gem 'redcarpet', '~> 3.3.1'
@@ -19,6 +20,8 @@ group :development do
19
20
  end
20
21
 
21
22
  group :debugging do
23
+ # Fixing https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X#option-4-using-a-pure-ruby-readline-implementation
24
+ gem 'rb-readline', '~> 0.5.3'
22
25
  gem 'pry'
23
26
  platforms :mri do
24
27
  gem 'pry-byebug'
data/README.md CHANGED
@@ -9,6 +9,8 @@
9
9
  [![Gem Version](https://badge.fury.io/rb/reek.svg)](https://badge.fury.io/rb/reek)
10
10
  [![Dependency Status](https://gemnasium.com/troessner/reek.png)](https://gemnasium.com/troessner/reek)
11
11
  [![Inline docs](https://inch-ci.org/github/troessner/reek.png)](https://inch-ci.org/github/troessner/reek)
12
+ [![Code Climate](https://codeclimate.com/github/troessner/reek/badges/gpa.svg)](https://codeclimate.com/github/troessner/reek)
13
+ [![codebeat](https://codebeat.co/badges/42fed4ff-3e55-4aed-8ecc-409b4aa539b3)](https://codebeat.co/projects/github-com-troessner-reek)
12
14
 
13
15
  ## Quickstart
14
16
 
data/docs/Attribute.md CHANGED
@@ -24,7 +24,7 @@ Reek would emit the following warning:
24
24
  reek test.rb
25
25
 
26
26
  test.rb -- 1 warning:
27
- [2]:Klass declares the writable attribute dummy (Attribute)
27
+ [2]:Attribute: Klass#dummy is a writable attribute
28
28
  ```
29
29
 
30
30
  ## Support in Reek
@@ -20,5 +20,35 @@ Reek's Uncommunicative Method Name detector supports the [Basic Smell Options](B
20
20
 
21
21
  | Option | Value | Effect |
22
22
  | ---------------|-------------|---------|
23
- | `reject` | array of regular expressions | The set of regular expressions that Reek uses to check for bad names. Defaults to `[/^[a-z]$/, /[0-9]$/, /[A-Z]/]`. |
24
- | `accept` | array of strings or regular expressions | Name that will be accepted (not reported) even if they match one of the `reject` expressions. |
23
+ | `reject` | array of regular expressions or strings | The set of patterns / names that Reek uses to check for bad names. Defaults to `[/^[a-z]$/, /[0-9]$/, /[A-Z]/]`. |
24
+ | `accept` | array of regular expressions or strings | The set of patterns / names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
25
+
26
+ An example configuration could look like this:
27
+
28
+ ```Yaml
29
+ ---
30
+ UncommunicativeMethodName:
31
+ accept:
32
+ - !ruby/regexp /x/
33
+ - meth1
34
+ reject:
35
+ - !ruby/regexp /helper/
36
+ - foobar
37
+ ```
38
+
39
+ Applying a configuration to a source file like this:
40
+
41
+ ```Ruby
42
+ def x; end # Should not be reported
43
+ def meth1; end # Should not be reported
44
+ def foobar; end # Should be reported
45
+ def awesome_helper; end # Should be reported
46
+ ```
47
+
48
+ Reek would report:
49
+
50
+ ```
51
+ smelly.rb -- 2 warnings:
52
+ [4]:UncommunicativeMethodName: awesome_helper has the name 'awesome_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
53
+ [3]:UncommunicativeMethodName: foobar has the name 'foobar' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
54
+ ```
@@ -19,5 +19,32 @@ Reek's `Uncommunicative Module Name` detector supports the [Basic Smell Options]
19
19
 
20
20
  | Option | Value | Effect |
21
21
  | ---------------|-------------|---------|
22
- | `reject` | array of regular expressions | The set of regular expressions that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/]`. |
23
- | `accept` | array of names as strings | List of names that will be accepted (not reported) even if they match one of the `reject` expressions. Empty by default.|
22
+ | `reject` | array of regular expressions or strings | The set of patterns / names that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/]`. |
23
+ | `accept` | array of regular expressions or strings | The set of patterns / names that Reek will accept (and not report) even if they match one of the `reject` expressions. Empty by default.|
24
+
25
+ An example configuration could look like this:
26
+
27
+ ```Yaml
28
+ ---
29
+ UncommunicativeModuleName:
30
+ accept:
31
+ - !ruby/regexp /lassy/
32
+ - M
33
+ reject:
34
+ - !ruby/regexp /Helper/
35
+ ```
36
+
37
+ Applying a configuration to a source file like this:
38
+
39
+ ```Ruby
40
+ class Classy1; end # Should not be reported
41
+ class M; end # Should not be reported
42
+ class BaseHelper; end # Should be reported
43
+ ```
44
+
45
+ Reek would report:
46
+
47
+ ```
48
+ smelly.rb -- 1 warning:
49
+ [3]:UncommunicativeModuleName: BaseHelper has the name 'BaseHelper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Module-Name.md]
50
+ ```
@@ -20,5 +20,33 @@ Reek's Uncommunicative Parameter Name detector supports the [Basic Smell Options
20
20
 
21
21
  | Option | Value | Effect |
22
22
  | ---------------|-------------|---------|
23
- | `reject` | array of regular expressions | The set of regular expressions that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/, /[A-Z]/]@. |
24
- | `accept` | array of strings or regular expressions | Name that will be accepted (not reported) even if they match one of the `reject` expressions. |
23
+ | `reject` | array of regular expressions or strings | The set of patterns / names that Reek uses to check for bad names. Defaults to `[/^.$/, /[0-9]$/, /[A-Z]/, /^_/]. |
24
+ | `accept` | array of regular expressions or strings | The set of patterns / names that Reek will accept (and not report) even if they match one of the `reject` expressions. |
25
+
26
+
27
+ An example configuration could look like this:
28
+
29
+ ```Yaml
30
+ ---
31
+ UncommunicativeParameterName:
32
+ accept:
33
+ - !ruby/regexp /x/
34
+ - arg1
35
+ reject:
36
+ - !ruby/regexp /foobar/
37
+ ```
38
+
39
+ Applying a configuration to a source file like this:
40
+
41
+ ```Ruby
42
+ def omg(x); x; end # Should not be reported
43
+ def omg(arg1); arg1; end # Should not be reported
44
+ def omg(foobar); foobar; end # Should be reported
45
+ ```
46
+
47
+ Reek would report:
48
+
49
+ ```
50
+ smelly.rb -- 1 warning:
51
+ [3]:UncommunicativeParameterName: omg has the parameter name 'foobar' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
52
+ ```
@@ -0,0 +1,70 @@
1
+ Feature: `accept` configuration setting
2
+ In order to have a more fine-grained control over what Reek reports
3
+ As a user
4
+ I want to be able to accept specific patterns and names to exclude them from reporting
5
+
6
+ Scenario: Accept names as list and as single item
7
+ Given a file named "config.reek" with:
8
+ """
9
+ ---
10
+ UncommunicativeMethodName:
11
+ accept:
12
+ - m1
13
+ - m2
14
+ UncommunicativeParameterName:
15
+ accept:
16
+ - a1
17
+ - a2
18
+ UncommunicativeModuleName:
19
+ accept: C1
20
+ """
21
+ And a file named "smelly.rb" with:
22
+ """
23
+ # Should not report UncommunicativeModuleName
24
+ class C1
25
+ # Should not report UncommunicativeMethodName and UncommunicativeParameterName
26
+ def m1(a1); a1; end
27
+ # Should not report UncommunicativeMethodName and UncommunicativeParameterName
28
+ def m2(a2); a2; end
29
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
30
+ def m3(a3); a3; end
31
+ end
32
+ """
33
+ When I run `reek -c config.reek smelly.rb`
34
+ Then it reports:
35
+ """
36
+ smelly.rb -- 2 warnings:
37
+ [8]:UncommunicativeMethodName: C1#m3 has the name 'm3' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
38
+ [8]:UncommunicativeParameterName: C1#m3 has the parameter name 'a3' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
39
+ """
40
+
41
+ Scenario: Accept regexes as list and as single item
42
+ Given a file named "config.reek" with:
43
+ """
44
+ ---
45
+ UncommunicativeMethodName:
46
+ accept:
47
+ - !ruby/regexp /oobar/
48
+ UncommunicativeParameterName:
49
+ accept:
50
+ - !ruby/regexp /ola/
51
+ UncommunicativeModuleName:
52
+ accept: !ruby/regexp /lassy/
53
+ """
54
+ And a file named "smelly.rb" with:
55
+ """
56
+ # Should not report UncommunicativeModuleName
57
+ class Classy1
58
+ # Should not report UncommunicativeMethodName and UncommunicativeParameterName
59
+ def foobar1(hola1); hola1; end
60
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
61
+ def m2(a2); a2; end
62
+ end
63
+ """
64
+ When I run `reek -c config.reek smelly.rb`
65
+ Then it reports:
66
+ """
67
+ smelly.rb -- 2 warnings:
68
+ [6]:UncommunicativeMethodName: Classy1#m2 has the name 'm2' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
69
+ [6]:UncommunicativeParameterName: Classy1#m2 has the parameter name 'a2' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
70
+ """
@@ -0,0 +1,34 @@
1
+ Feature: Exclude directives
2
+ In order to have a more fine-grained control over what Reek reports
3
+ As a user
4
+ I want to be able to exclude specific contexts from reporting
5
+
6
+ Scenario: Exclude multiple contexts
7
+ Given a file named "config.reek" with:
8
+ """
9
+ ---
10
+ UncommunicativeMethodName:
11
+ exclude:
12
+ - "Smelly#x"
13
+ UnusedPrivateMethod:
14
+ enabled: true
15
+ exclude:
16
+ - "Smelly#foobar"
17
+ """
18
+ And a file named "smelly.rb" with:
19
+ """
20
+ class Smelly
21
+ # Should report IrresponsibleModule
22
+ def foo(arg); end # Should report UnusedParameter
23
+ def x; end # Should not report UncommunicativeMethodName
24
+ private
25
+ def foobar; end # Should not report UnusedPrivateMethod
26
+ end
27
+ """
28
+ When I run `reek -c config.reek smelly.rb`
29
+ Then it reports:
30
+ """
31
+ smelly.rb -- 2 warnings:
32
+ [1]:IrresponsibleModule: Smelly has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
33
+ [3]:UnusedParameters: Smelly#foo has unused parameter 'arg' [https://github.com/troessner/reek/blob/master/docs/Unused-Parameters.md]
34
+ """
@@ -0,0 +1,81 @@
1
+ Feature: Mix `accept` and `reject` configuration settings
2
+ In order to have a more fine-grained control over what Reek reports
3
+ As a user
4
+ I want to be able to mix the `accept` and `reject` setting
5
+
6
+ Scenario: UncommunicativeMethodName
7
+ Given a file named "config.reek" with:
8
+ """
9
+ ---
10
+ UncommunicativeMethodName:
11
+ accept:
12
+ - !ruby/regexp /x/
13
+ - meth1
14
+ reject:
15
+ - !ruby/regexp /helper/
16
+ - foobar
17
+ """
18
+ And a file named "smelly.rb" with:
19
+ """
20
+ def x; end # Should not be reported
21
+ def meth1; end # Should not be reported
22
+ def foobar; end # Should be reported
23
+ def awesome_helper; end # Should be reported
24
+ """
25
+ When I run `reek -c config.reek smelly.rb`
26
+ Then it reports:
27
+ """
28
+ smelly.rb -- 2 warnings:
29
+ [4]:UncommunicativeMethodName: awesome_helper has the name 'awesome_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
30
+ [3]:UncommunicativeMethodName: foobar has the name 'foobar' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
31
+ """
32
+
33
+ Scenario: UncommunicativeModuleName
34
+ Given a file named "config.reek" with:
35
+ """
36
+ ---
37
+ IrresponsibleModule:
38
+ enabled: false
39
+ UncommunicativeModuleName:
40
+ accept:
41
+ - !ruby/regexp /lassy/
42
+ - M
43
+ reject:
44
+ - !ruby/regexp /Helper/
45
+ """
46
+ And a file named "smelly.rb" with:
47
+ """
48
+ class Classy1; end # Should not be reported
49
+ class M; end # Should not be reported
50
+ class BaseHelper; end # Should be reported
51
+ """
52
+ When I run `reek -c config.reek smelly.rb`
53
+ Then it reports:
54
+ """
55
+ smelly.rb -- 1 warning:
56
+ [3]:UncommunicativeModuleName: BaseHelper has the name 'BaseHelper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Module-Name.md]
57
+ """
58
+
59
+ Scenario: UncommunicativeParameterName
60
+ Given a file named "config.reek" with:
61
+ """
62
+ ---
63
+ UncommunicativeParameterName:
64
+ accept:
65
+ - !ruby/regexp /x/
66
+ - arg1
67
+ reject:
68
+ - !ruby/regexp /foobar/
69
+ """
70
+ And a file named "smelly.rb" with:
71
+ """
72
+ def omg(x); x; end # Should not be reported
73
+ def omg(arg1); arg1; end # Should not be reported
74
+ def omg(foobar); foobar; end # Should be reported
75
+ """
76
+ When I run `reek -c config.reek smelly.rb`
77
+ Then it reports:
78
+ """
79
+ smelly.rb -- 1 warning:
80
+ [3]:UncommunicativeParameterName: omg has the parameter name 'foobar' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
81
+ """
@@ -0,0 +1,78 @@
1
+ Feature: `reject` configuration setting
2
+ In order to have a more fine-grained control over what Reek reports
3
+ As a user
4
+ I want to be able to reject specific patterns and names to include them into reporting
5
+
6
+ Scenario: reject names as list and as single item
7
+ Given a file named "config.reek" with:
8
+ """
9
+ ---
10
+ UncommunicativeMethodName:
11
+ reject:
12
+ - awesome_helper
13
+ - little_helper
14
+ UncommunicativeParameterName:
15
+ reject:
16
+ - solid_argument
17
+ - nifty_argument
18
+ UncommunicativeModuleName:
19
+ reject: Dummy
20
+ """
21
+ And a file named "smelly.rb" with:
22
+ """
23
+ # Should report UncommunicativeModuleName
24
+ class Dummy
25
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
26
+ def awesome_helper(solid_argument); solid_argument; end
27
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
28
+ def little_helper(nifty_argument); nifty_argument; end
29
+ # Should not report UncommunicativeMethodName and UncommunicativeParameterName
30
+ def meth(argument); argument; end
31
+ end
32
+ """
33
+ When I run `reek -c config.reek smelly.rb`
34
+ Then it reports:
35
+ """
36
+ smelly.rb -- 5 warnings:
37
+ [4]:UncommunicativeMethodName: Dummy#awesome_helper has the name 'awesome_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
38
+ [6]:UncommunicativeMethodName: Dummy#little_helper has the name 'little_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
39
+ [2]:UncommunicativeModuleName: Dummy has the name 'Dummy' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Module-Name.md]
40
+ [4]:UncommunicativeParameterName: Dummy#awesome_helper has the parameter name 'solid_argument' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
41
+ [6]:UncommunicativeParameterName: Dummy#little_helper has the parameter name 'nifty_argument' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
42
+ """
43
+
44
+ Scenario: reject regexes as list and as single item
45
+ Given a file named "config.reek" with:
46
+ """
47
+ ---
48
+ UncommunicativeMethodName:
49
+ reject: !ruby/regexp /helper/
50
+ UncommunicativeParameterName:
51
+ reject:
52
+ - !ruby/regexp /solid/
53
+ - !ruby/regexp /nifty/
54
+ UncommunicativeModuleName:
55
+ reject: !ruby/regexp /ummy/
56
+ """
57
+ And a file named "smelly.rb" with:
58
+ """
59
+ # Should report UncommunicativeModuleName
60
+ class Dummy
61
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
62
+ def awesome_helper(solid_argument); solid_argument; end
63
+ # Should report UncommunicativeMethodName and UncommunicativeParameterName
64
+ def little_helper(nifty_argument); nifty_argument; end
65
+ # Should not report UncommunicativeMethodName and UncommunicativeParameterName
66
+ def meth(argument); argument; end
67
+ end
68
+ """
69
+ When I run `reek -c config.reek smelly.rb`
70
+ Then it reports:
71
+ """
72
+ smelly.rb -- 5 warnings:
73
+ [4]:UncommunicativeMethodName: Dummy#awesome_helper has the name 'awesome_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
74
+ [6]:UncommunicativeMethodName: Dummy#little_helper has the name 'little_helper' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
75
+ [2]:UncommunicativeModuleName: Dummy has the name 'Dummy' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Module-Name.md]
76
+ [4]:UncommunicativeParameterName: Dummy#awesome_helper has the parameter name 'solid_argument' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
77
+ [6]:UncommunicativeParameterName: Dummy#little_helper has the parameter name 'nifty_argument' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md]
78
+ """
@@ -0,0 +1,66 @@
1
+ Feature: Unused Private Method detector
2
+ This detector is a little special in the sense that it takes class contexts but analyzes
3
+ methods (and thus, is configured in regards to methods) so we need to make sure
4
+ that our configuration handling still works.
5
+
6
+ Scenario: Differentiate between contexts when excluding them
7
+ Given a file named "config.reek" with:
8
+ """
9
+ ---
10
+ IrresponsibleModule:
11
+ enabled: false
12
+ UnusedPrivateMethod:
13
+ enabled: true
14
+ exclude:
15
+ - "Outer::Awesome#foobar"
16
+ """
17
+ And a file named "sample.rb" with:
18
+ """
19
+ module Outer
20
+ class Smelly
21
+ private
22
+ def foobar; end # Should report UnusedPrivateMethod
23
+ end
24
+ class Awesome
25
+ private
26
+ def foobar; end # Should not report UnusedPrivateMethod
27
+ end
28
+ end
29
+ """
30
+ When I run `reek -c config.reek sample.rb`
31
+ Then it reports:
32
+ """
33
+ sample.rb -- 1 warning:
34
+ [4]:UnusedPrivateMethod: Outer::Smelly has the unused private instance method `foobar` [https://github.com/troessner/reek/blob/master/docs/Unused-Private-Method.md]
35
+ """
36
+
37
+ Scenario: Use regexes for excluding contexts
38
+ Given a file named "config.reek" with:
39
+ """
40
+ ---
41
+ IrresponsibleModule:
42
+ enabled: false
43
+ UnusedPrivateMethod:
44
+ enabled: true
45
+ exclude:
46
+ - !ruby/regexp /(.*)wesome#foo(.*)/
47
+ """
48
+ And a file named "sample.rb" with:
49
+ """
50
+ module Outer
51
+ class Smelly
52
+ private
53
+ def foobar; end # Should report UnusedPrivateMethod
54
+ end
55
+ class Awesome
56
+ private
57
+ def foobar; end # Should not report UnusedPrivateMethod
58
+ end
59
+ end
60
+ """
61
+ When I run `reek -c config.reek sample.rb`
62
+ Then it reports:
63
+ """
64
+ sample.rb -- 1 warning:
65
+ [4]:UnusedPrivateMethod: Outer::Smelly has the unused private instance method `foobar` [https://github.com/troessner/reek/blob/master/docs/Unused-Private-Method.md]
66
+ """
@@ -29,36 +29,6 @@ module Reek
29
29
  end
30
30
  end
31
31
 
32
- # Instantiate a configuration by passing everything in.
33
- #
34
- # @deprecated This method will be removed in Reek 4.0.
35
- #
36
- # @param [Hash] map a hash with three possible keys representing
37
- # different types of directives.
38
- # @option map [Hash] :directory_directives Directory specific configuration
39
- # for instance:
40
- # { Pathname("spec/samples/three_clean_files/") =>
41
- # { Reek::Smells::UtilityFunction => { "enabled" => false } } }
42
- # @option map [Hash] :default_directive Default configuration
43
- # for instance:
44
- # { Reek::Smells::IrresponsibleModule => { "enabled" => false } }
45
- # @option map [Array] :excluded_paths list of paths to exclude from analysis
46
- # for instance:
47
- # [ Pathname('spec/samples/two_smelly_files') ]
48
- #
49
- # @return [AppConfiguration]
50
- #
51
- # @public
52
- def self.from_map(map = {})
53
- allocate.tap do |instance|
54
- instance.instance_eval do
55
- load_values map.fetch(:directory_directives, {})
56
- load_values map.fetch(:default_directive, {})
57
- load_values EXCLUDE_PATHS_KEY => map.fetch(:excluded_paths, [])
58
- end
59
- end
60
- end
61
-
62
32
  # Instantiate a configuration by passing everything in.
63
33
  #
64
34
  # Loads the configuration from a hash of the form that is loaded from a
@@ -21,7 +21,21 @@ module Reek
21
21
  end
22
22
 
23
23
  def uses_param?(param)
24
- local_nodes(:lvar).find { |node| node.var_name == param.to_sym }
24
+ # local_nodes(:lvasgn) catches:
25
+ # def foo(bar); bar += 1; end
26
+ # In this example there is no `lvar` node present.
27
+ #
28
+ # local_nodes(:lvar) catches:
29
+ # def foo(bar); other(bar); end
30
+ # def foo(bar); tmp = other(bar); tmp[0]; end
31
+ #
32
+ # Note that in the last example the `lvar` node for `bar` is part of an `lvasgn` node for `tmp`.
33
+ # This means that if we would just search for [:lvar, :lvasgn]
34
+ # (e.g. via Reek::AST::Node#find_nodes) this would fail for this example since we would
35
+ # stop at the `lvasgn` and not detect the contained `lvar`.
36
+ # Hence we first get all `lvar` nodes followed by all `lvasgn` nodes.
37
+ #
38
+ (local_nodes(:lvar) + local_nodes(:lvasgn)).find { |node| node.var_name == param.to_sym }
25
39
  end
26
40
 
27
41
  # :reek:FeatureEnvy
@@ -16,18 +16,19 @@ module Reek
16
16
  # Currently +UncommunicativeMethodName+ checks for
17
17
  # * 1-character names
18
18
  # * names ending with a number
19
+ # * names containing a capital letter (assuming camelCase)
19
20
  #
20
21
  # See {file:docs/Uncommunicative-Method-Name.md} for details.
21
22
  class UncommunicativeMethodName < SmellDetector
22
23
  REJECT_KEY = 'reject'.freeze
23
24
  ACCEPT_KEY = 'accept'.freeze
24
25
  DEFAULT_REJECT_PATTERNS = [/^[a-z]$/, /[0-9]$/, /[A-Z]/].freeze
25
- DEFAULT_ACCEPT_NAMES = [].freeze
26
+ DEFAULT_ACCEPT_PATTERNS = [].freeze
26
27
 
27
28
  def self.default_config
28
29
  super.merge(
29
30
  REJECT_KEY => DEFAULT_REJECT_PATTERNS,
30
- ACCEPT_KEY => DEFAULT_ACCEPT_NAMES
31
+ ACCEPT_KEY => DEFAULT_ACCEPT_PATTERNS
31
32
  )
32
33
  end
33
34
 
@@ -50,16 +51,16 @@ module Reek
50
51
  private
51
52
 
52
53
  def acceptable_name?(name:, context:)
53
- accept_names(context).any? { |accept_name| name == accept_name } ||
54
- reject_patterns(context).none? { |pattern| name.match pattern }
54
+ accept_patterns(context).any? { |accept_pattern| name.match accept_pattern } ||
55
+ reject_patterns(context).none? { |reject_pattern| name.match reject_pattern }
55
56
  end
56
57
 
57
58
  def reject_patterns(context)
58
- value(REJECT_KEY, context, DEFAULT_REJECT_PATTERNS)
59
+ Array value(REJECT_KEY, context, DEFAULT_REJECT_PATTERNS)
59
60
  end
60
61
 
61
- def accept_names(context)
62
- value(ACCEPT_KEY, context, DEFAULT_ACCEPT_NAMES)
62
+ def accept_patterns(context)
63
+ Array value(ACCEPT_KEY, context, DEFAULT_ACCEPT_PATTERNS)
63
64
  end
64
65
  end
65
66
  end