reek 6.1.0 → 6.2.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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +4 -0
- data/.github/workflows/ruby.yml +7 -7
- data/.rubocop.yml +2 -10
- data/CHANGELOG.md +69 -0
- data/CONTRIBUTING.md +7 -10
- data/Gemfile +7 -6
- data/README.md +28 -28
- data/bin/code_climate_reek +54 -5
- data/lib/reek/ast/sexp_extensions/arguments.rb +9 -0
- data/lib/reek/ast/sexp_extensions/send.rb +21 -6
- data/lib/reek/cli/command/todo_list_command.rb +2 -2
- data/lib/reek/cli/options.rb +5 -5
- data/lib/reek/{report/code_climate → code_climate}/code_climate_configuration.rb +1 -1
- data/lib/reek/{report/code_climate → code_climate}/code_climate_configuration.yml +41 -41
- data/lib/reek/{report/code_climate → code_climate}/code_climate_fingerprint.rb +2 -2
- data/lib/reek/{report/code_climate → code_climate}/code_climate_formatter.rb +1 -1
- data/lib/reek/{report/code_climate → code_climate}/code_climate_report.rb +3 -3
- data/lib/reek/code_comment.rb +3 -3
- data/lib/reek/configuration/app_configuration.rb +5 -5
- data/lib/reek/configuration/configuration_converter.rb +1 -1
- data/lib/reek/configuration/configuration_file_finder.rb +5 -4
- data/lib/reek/configuration/default_directive.rb +1 -1
- data/lib/reek/configuration/directory_directives.rb +1 -1
- data/lib/reek/configuration/excluded_paths.rb +1 -1
- data/lib/reek/configuration/schema.rb +177 -0
- data/lib/reek/configuration/schema_validator.rb +12 -13
- data/lib/reek/context/attribute_context.rb +1 -1
- data/lib/reek/context/method_context.rb +1 -1
- data/lib/reek/context/module_context.rb +4 -0
- data/lib/reek/context/send_context.rb +7 -1
- data/lib/reek/documentation_link.rb +3 -5
- data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +2 -2
- data/lib/reek/errors/bad_detector_in_comment_error.rb +2 -2
- data/lib/reek/errors/encoding_error.rb +1 -1
- data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +2 -2
- data/lib/reek/errors/incomprehensible_source_error.rb +1 -1
- data/lib/reek/errors/legacy_comment_separator_error.rb +2 -2
- data/lib/reek/errors/syntax_error.rb +1 -1
- data/lib/reek/rake/task.rb +5 -5
- data/lib/reek/smell_detectors/class_variable.rb +2 -2
- data/lib/reek/smell_detectors/control_parameter_helpers/candidate.rb +6 -6
- data/lib/reek/smell_detectors/control_parameter_helpers/control_parameter_finder.rb +1 -1
- data/lib/reek/smell_detectors/duplicate_method_call.rb +5 -5
- data/lib/reek/smell_detectors/instance_variable_assumption.rb +8 -8
- data/lib/reek/smell_detectors/nested_iterators.rb +4 -3
- data/lib/reek/smell_detectors/unused_private_method.rb +3 -2
- data/lib/reek/spec/should_reek_of.rb +7 -7
- data/lib/reek/spec.rb +1 -1
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +4 -3
- metadata +30 -16
- data/lib/reek/configuration/schema.yml +0 -210
- /data/lib/reek/{report/code_climate.rb → code_climate.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c025e0e50af37b8dc3c118f97752c18155f59d48c08332961527d24b2e8f50c
|
|
4
|
+
data.tar.gz: e681b629a371e90fcfeb0f8f62669e3d26ba7a4c8ba34322cda546424be9c71a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 304af91b9ff40fc9385991e130ae3cd28b928d4ac8bd896693edbd802c0b414a261c9ecf4bf3a5290590516ae97596a7fe39ed0cc0a388916f443201ff99c604
|
|
7
|
+
data.tar.gz: 4e7267ff76b9c9d99f996245245b9157bbae85927bf22f146883715254c7bc013821e9b7786500daf410344b1ef0a81fb61165979e5d2a74059bd06deeb656d4
|
data/.github/dependabot.yml
CHANGED
data/.github/workflows/ruby.yml
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
name: CI
|
|
6
6
|
|
|
7
|
-
on:
|
|
7
|
+
"on":
|
|
8
8
|
push:
|
|
9
|
-
branches: [
|
|
9
|
+
branches: [master]
|
|
10
10
|
pull_request:
|
|
11
|
-
branches: [
|
|
11
|
+
branches: [master]
|
|
12
12
|
schedule:
|
|
13
13
|
- cron: '16 4 12 * *'
|
|
14
14
|
|
|
@@ -22,10 +22,10 @@ jobs:
|
|
|
22
22
|
|
|
23
23
|
strategy:
|
|
24
24
|
matrix:
|
|
25
|
-
ruby: [
|
|
25
|
+
ruby: ["3.0", "3.1", "3.2", "jruby-9.4", "3.3"]
|
|
26
26
|
|
|
27
27
|
steps:
|
|
28
|
-
- uses: actions/checkout@
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
29
|
- name: Set up Ruby
|
|
30
30
|
uses: ruby/setup-ruby@v1
|
|
31
31
|
with:
|
|
@@ -47,11 +47,11 @@ jobs:
|
|
|
47
47
|
runs-on: ubuntu-latest
|
|
48
48
|
|
|
49
49
|
steps:
|
|
50
|
-
- uses: actions/checkout@
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
51
|
- name: Set up Ruby
|
|
52
52
|
uses: ruby/setup-ruby@v1
|
|
53
53
|
with:
|
|
54
|
-
ruby-version:
|
|
54
|
+
ruby-version: "3.3"
|
|
55
55
|
bundler-cache: true
|
|
56
56
|
- name: Run RuboCop
|
|
57
57
|
run: bundle exec rubocop -P
|
data/.rubocop.yml
CHANGED
|
@@ -12,7 +12,7 @@ AllCops:
|
|
|
12
12
|
Exclude:
|
|
13
13
|
- 'samples/**/*'
|
|
14
14
|
NewCops: enable
|
|
15
|
-
TargetRubyVersion:
|
|
15
|
+
TargetRubyVersion: 3.0
|
|
16
16
|
|
|
17
17
|
# Tables are nice
|
|
18
18
|
Layout/HashAlignment:
|
|
@@ -48,7 +48,7 @@ Layout/MultilineOperationIndentation:
|
|
|
48
48
|
Lint/AmbiguousBlockAssociation:
|
|
49
49
|
Enabled: false
|
|
50
50
|
|
|
51
|
-
# Some of our source examples include interpolation
|
|
51
|
+
# Some of our source examples include interpolation explicitly.
|
|
52
52
|
Lint/InterpolationCheck:
|
|
53
53
|
Exclude:
|
|
54
54
|
- 'spec/**/*'
|
|
@@ -80,14 +80,6 @@ RSpec/DescribeClass:
|
|
|
80
80
|
RSpec/ExampleLength:
|
|
81
81
|
Enabled: false
|
|
82
82
|
|
|
83
|
-
# rubocop-rspec expects a CodeClimate namespace to go with the code_climate directory.
|
|
84
|
-
RSpec/FilePath:
|
|
85
|
-
Exclude:
|
|
86
|
-
- 'spec/reek/report/code_climate/code_climate_configuration_spec.rb'
|
|
87
|
-
- 'spec/reek/report/code_climate/code_climate_fingerprint_spec.rb'
|
|
88
|
-
- 'spec/reek/report/code_climate/code_climate_formatter_spec.rb'
|
|
89
|
-
- 'spec/reek/report/code_climate/code_climate_report_spec.rb'
|
|
90
|
-
|
|
91
83
|
# Allow and/or for control flow only
|
|
92
84
|
Style/AndOr:
|
|
93
85
|
EnforcedStyle: conditionals
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Change log
|
|
2
2
|
|
|
3
|
+
## 6.2.0 (2023-12-31)
|
|
4
|
+
|
|
5
|
+
### Features and bugfixes
|
|
6
|
+
|
|
7
|
+
* Code Climate: add config `target_ruby_version` to support different versions
|
|
8
|
+
of Ruby syntax ([#1694] by [dantevvp])
|
|
9
|
+
* Treat `Data.define` as a class definition ([#1725] by [mvz])
|
|
10
|
+
* Fix Instance Variable Assumption false positive ([#1737] by [JuanVqz])
|
|
11
|
+
* Add `Tempfile.create` to ignored iterators list ([#1747] by [mateusdeap])
|
|
12
|
+
* Improve configuration schema validation. This also replaces the kwalify
|
|
13
|
+
dependency with dry-schema ([#1749] by [fbuys])
|
|
14
|
+
|
|
15
|
+
### Dependencies
|
|
16
|
+
|
|
17
|
+
* Add missing dependency rexml ([#1703] by [tricknotes])
|
|
18
|
+
* Drop support for Ruby 2.6 and 2.7 ([#1716] and [#1755] by [mvz])
|
|
19
|
+
* Add support for Ruby 3.3 ([#1756] and [#1755] by [mvz])
|
|
20
|
+
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
* Fix the badges in our README ([#1711] by [troessner])
|
|
24
|
+
* Remove non working link in CONTRIBUTING.md ([#1738] by [JuanVqz])
|
|
25
|
+
* Add downloads badge ([#1750] by [troessner])
|
|
26
|
+
|
|
27
|
+
### Internal
|
|
28
|
+
|
|
29
|
+
* Rename Code Climate related classes ([#1735] by [mvz])
|
|
30
|
+
* Fix `cucumber_opts` warning ([#1736] by [JuanVqz])
|
|
31
|
+
* Fix editor highlighting for fenced code blocks in documentation ([#1745] by [JuanVqz])
|
|
32
|
+
|
|
33
|
+
[JuanVqz]: https://github.com/JuanVqz
|
|
34
|
+
[dantevvp]: https://github.com/dantevvp
|
|
35
|
+
[fbuys]: https://github.com/fbuys
|
|
36
|
+
[mateusdeap]: https://github.com/mateusdeap
|
|
37
|
+
[mvz]: https://github.com/mvz
|
|
38
|
+
[tricknotes]: https://github.com/tricknotes
|
|
39
|
+
[troessner]: https://github.com/troessner
|
|
40
|
+
|
|
41
|
+
[#1694]: https://github.com/troessner/reek/pull/1694
|
|
42
|
+
[#1703]: https://github.com/troessner/reek/pull/1703
|
|
43
|
+
[#1711]: https://github.com/troessner/reek/pull/1711
|
|
44
|
+
[#1725]: https://github.com/troessner/reek/pull/1725
|
|
45
|
+
[#1735]: https://github.com/troessner/reek/pull/1735
|
|
46
|
+
[#1736]: https://github.com/troessner/reek/pull/1736
|
|
47
|
+
[#1737]: https://github.com/troessner/reek/pull/1737
|
|
48
|
+
[#1738]: https://github.com/troessner/reek/pull/1738
|
|
49
|
+
[#1745]: https://github.com/troessner/reek/pull/1745
|
|
50
|
+
[#1749]: https://github.com/troessner/reek/pull/1749
|
|
51
|
+
[#1747]: https://github.com/troessner/reek/pull/1747
|
|
52
|
+
[#1750]: https://github.com/troessner/reek/pull/1750
|
|
53
|
+
[#1756]: https://github.com/troessner/reek/pull/1756
|
|
54
|
+
[#1755]: https://github.com/troessner/reek/pull/1755
|
|
55
|
+
|
|
56
|
+
## 6.1.4 (2023-01-13)
|
|
57
|
+
|
|
58
|
+
* (mvz) Update parser dependency to the 3.2.x series
|
|
59
|
+
|
|
60
|
+
## 6.1.3 (2022-12-29)
|
|
61
|
+
|
|
62
|
+
* (gonubana) Allow failing safely when trying to recursively find a configuration
|
|
63
|
+
|
|
64
|
+
## 6.1.2 (2022-11-21)
|
|
65
|
+
|
|
66
|
+
* (mvz) Add support for keyword nil arguments
|
|
67
|
+
|
|
68
|
+
## 6.1.1 (2022-04-20)
|
|
69
|
+
|
|
70
|
+
* (ydah) UnusedPrivateMethod to be detect use of methods via `Method#to_proc`
|
|
71
|
+
|
|
3
72
|
## 6.1.0 (2022-01-14)
|
|
4
73
|
|
|
5
74
|
* (mvz) Drop support for Ruby 2.4 and 2.5
|
data/CONTRIBUTING.md
CHANGED
|
@@ -62,11 +62,8 @@ demonstrate that your fix was needed.
|
|
|
62
62
|
|
|
63
63
|
Reek uses [Rspec](http://rspec.info/) for unit and functional testing.
|
|
64
64
|
|
|
65
|
-
We're trying to follow [betterspecs](http://betterspecs.org/).
|
|
66
|
-
|
|
67
|
-
[shared examples](https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples)
|
|
68
|
-
because we find them rather harming than helpful. You can find an excellent
|
|
69
|
-
cheat sheet on how to write idiomatic Rspec
|
|
65
|
+
We're trying to follow [betterspecs](http://betterspecs.org/).
|
|
66
|
+
You can find an excellent cheat sheet on how to write idiomatic Rspec
|
|
70
67
|
[here](http://www.rubypigeon.com/posts/rspec-core-cheat-sheet).
|
|
71
68
|
|
|
72
69
|
We do not use the popular "foo" / "bar" naming when it comes to the question
|
|
@@ -74,7 +71,7 @@ We do not use the popular "foo" / "bar" naming when it comes to the question
|
|
|
74
71
|
[military alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet) in
|
|
75
72
|
ascending order which means that we would write this
|
|
76
73
|
|
|
77
|
-
```
|
|
74
|
+
```ruby
|
|
78
75
|
class Foo
|
|
79
76
|
def bar(baz)
|
|
80
77
|
baz.quux
|
|
@@ -84,7 +81,7 @@ end
|
|
|
84
81
|
|
|
85
82
|
rather like this:
|
|
86
83
|
|
|
87
|
-
```
|
|
84
|
+
```ruby
|
|
88
85
|
class Alfa
|
|
89
86
|
def bravo(charlie)
|
|
90
87
|
charlie.delta
|
|
@@ -142,7 +139,7 @@ Once you’re happy with your feature / fix – or want to
|
|
|
142
139
|
share it as a work-in-progress and request comments – once
|
|
143
140
|
again make sure all of the tests pass. This will also run
|
|
144
141
|
[RuboCop](https://github.com/bbatsov/rubocop) – fix any
|
|
145
|
-
|
|
142
|
+
offenses RuboCop finds (or discuss them in the pull request):
|
|
146
143
|
|
|
147
144
|
```
|
|
148
145
|
bundle exec rake
|
|
@@ -202,11 +199,11 @@ In this example we assume the current version is 5.3.1 and you want to update to
|
|
|
202
199
|
* Update the version in `lib/reek/version.rb`
|
|
203
200
|
* List all relevant changes in `CHANGELOG.md`
|
|
204
201
|
* Update the version number in our cucumber features, otherwise the build will fail. You can do this quite easily via
|
|
205
|
-
```
|
|
202
|
+
```bash
|
|
206
203
|
find features/ -type f -exec sed -i '' 's/v5.3.1/v5.3.2/g' {} +
|
|
207
204
|
```
|
|
208
205
|
* Push the branch, create a pull request, have it reviewed and merged
|
|
209
206
|
* Pull the latest master and then do a
|
|
210
|
-
```
|
|
207
|
+
```bash
|
|
211
208
|
bundle exec rake release
|
|
212
209
|
```
|
data/Gemfile
CHANGED
|
@@ -5,18 +5,19 @@ gemspec
|
|
|
5
5
|
ruby RUBY_VERSION
|
|
6
6
|
|
|
7
7
|
group :development do
|
|
8
|
-
gem 'aruba', '~> 2.
|
|
8
|
+
gem 'aruba', '~> 2.1'
|
|
9
|
+
gem 'bigdecimal', '>= 2.0.0', '< 4.0'
|
|
9
10
|
gem 'codeclimate-engine-rb', '~> 0.4.0'
|
|
10
|
-
gem 'cucumber', '
|
|
11
|
+
gem 'cucumber', '~> 9.0'
|
|
11
12
|
gem 'kramdown', '~> 2.1'
|
|
12
13
|
gem 'kramdown-parser-gfm', '~> 1.0'
|
|
13
14
|
gem 'rake', '~> 13.0'
|
|
14
15
|
gem 'rspec', '~> 3.0'
|
|
15
16
|
gem 'rspec-benchmark', '~> 0.6.0'
|
|
16
|
-
gem 'rubocop', '~> 1.
|
|
17
|
-
gem 'rubocop-performance', '~> 1.
|
|
18
|
-
gem 'rubocop-rspec', '~> 2.
|
|
19
|
-
gem 'simplecov',
|
|
17
|
+
gem 'rubocop', '~> 1.59.0'
|
|
18
|
+
gem 'rubocop-performance', '~> 1.20.0'
|
|
19
|
+
gem 'rubocop-rspec', '~> 2.25.0'
|
|
20
|
+
gem 'simplecov', '>= 0.18.0', '< 0.23.0'
|
|
20
21
|
gem 'yard', '~> 0.9.5'
|
|
21
22
|
|
|
22
23
|
platforms :mri do
|
data/README.md
CHANGED
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
|
|
36
36
|
## Overview
|
|
37
37
|
|
|
38
|
-
*
|
|
38
|
+
* 
|
|
39
|
+
* 
|
|
39
40
|
* [](https://badge.fury.io/rb/reek)
|
|
40
|
-
* 
|
|
41
|
-
* 
|
|
41
|
+
* 
|
|
42
|
+
* 
|
|
42
43
|
* [](https://inch-ci.org/github/troessner/reek)
|
|
43
44
|
* [](https://codeclimate.com/github/troessner/reek)
|
|
44
45
|
* [](https://codebeat.co/projects/github-com-troessner-reek)
|
|
45
|
-
|
|
46
|
-
* 
|
|
46
|
+
|
|
47
47
|
|
|
48
48
|
## Quickstart
|
|
49
49
|
|
|
@@ -56,13 +56,13 @@ or [that one](https://troessner.svbtle.com/the-latest-and-greatest-additions-to-
|
|
|
56
56
|
|
|
57
57
|
Install it via rubygems:
|
|
58
58
|
|
|
59
|
-
```
|
|
59
|
+
```bash
|
|
60
60
|
gem install reek
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
and run it like this:
|
|
64
64
|
|
|
65
|
-
```
|
|
65
|
+
```bash
|
|
66
66
|
reek [options] [dir_or_source_file]*
|
|
67
67
|
```
|
|
68
68
|
|
|
@@ -70,7 +70,7 @@ reek [options] [dir_or_source_file]*
|
|
|
70
70
|
|
|
71
71
|
Imagine a source file `demo.rb` containing:
|
|
72
72
|
|
|
73
|
-
```
|
|
73
|
+
```ruby
|
|
74
74
|
# Smelly class
|
|
75
75
|
class Smelly
|
|
76
76
|
# This will reek of UncommunicativeMethodName
|
|
@@ -111,7 +111,7 @@ language and business logic.
|
|
|
111
111
|
That said, an example might help you get going. Have a look at this sample of a
|
|
112
112
|
Ruby on Rails model (be aware that this is truncated, not working code):
|
|
113
113
|
|
|
114
|
-
```
|
|
114
|
+
```ruby
|
|
115
115
|
class ShoppingCart < ActiveRecord::Base
|
|
116
116
|
has_many :items
|
|
117
117
|
|
|
@@ -140,7 +140,7 @@ would report:
|
|
|
140
140
|
Fixing this is pretty straightforward. Put the gross price calculation for a single item
|
|
141
141
|
where it belongs, which would be the `Item` class:
|
|
142
142
|
|
|
143
|
-
```
|
|
143
|
+
```ruby
|
|
144
144
|
class ShoppingCart < ActiveRecord::Base
|
|
145
145
|
has_many :items
|
|
146
146
|
|
|
@@ -165,7 +165,7 @@ those first when you have a warning that you don't know how to deal with.
|
|
|
165
165
|
|
|
166
166
|
There are multiple ways you can have Reek work on sources, the most common one just being
|
|
167
167
|
|
|
168
|
-
```
|
|
168
|
+
```bash
|
|
169
169
|
reek lib/
|
|
170
170
|
```
|
|
171
171
|
|
|
@@ -173,25 +173,25 @@ If you don't pass any source arguments to Reek it just takes the current working
|
|
|
173
173
|
|
|
174
174
|
So
|
|
175
175
|
|
|
176
|
-
```
|
|
176
|
+
```bash
|
|
177
177
|
reek
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
is the exact same thing as being explicit:
|
|
181
181
|
|
|
182
|
-
```
|
|
182
|
+
```bash
|
|
183
183
|
reek .
|
|
184
184
|
```
|
|
185
185
|
|
|
186
186
|
Additionally you can pipe code to Reek like this:
|
|
187
187
|
|
|
188
|
-
```
|
|
188
|
+
```bash
|
|
189
189
|
echo "class C; def m; end; end" | reek
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
This would print out:
|
|
193
193
|
|
|
194
|
-
```
|
|
194
|
+
```bash
|
|
195
195
|
$stdin -- 3 warnings:
|
|
196
196
|
[1]:C has no descriptive comment (IrresponsibleModule)
|
|
197
197
|
[1]:C has the name 'C' (UncommunicativeModuleName)
|
|
@@ -219,7 +219,7 @@ for up to date details of exactly what Reek will check in your code.
|
|
|
219
219
|
because it is [kind of controversial](https://github.com/troessner/reek/issues/844) which means
|
|
220
220
|
you have to explicitly activate it in your configuration via
|
|
221
221
|
|
|
222
|
-
```
|
|
222
|
+
```yaml
|
|
223
223
|
UnusedPrivateMethod:
|
|
224
224
|
enabled: true
|
|
225
225
|
```
|
|
@@ -228,7 +228,7 @@ UnusedPrivateMethod:
|
|
|
228
228
|
as well that can turn out to be really unforgiving.
|
|
229
229
|
As a consequence, we made it possible to disable it for non-public methods like this:
|
|
230
230
|
|
|
231
|
-
```
|
|
231
|
+
```yaml
|
|
232
232
|
---
|
|
233
233
|
UtilityFunction:
|
|
234
234
|
public_methods_only: true
|
|
@@ -240,7 +240,7 @@ UtilityFunction:
|
|
|
240
240
|
|
|
241
241
|
For a basic overview, run
|
|
242
242
|
|
|
243
|
-
```
|
|
243
|
+
```ruby
|
|
244
244
|
reek --help
|
|
245
245
|
```
|
|
246
246
|
|
|
@@ -328,7 +328,7 @@ directories:
|
|
|
328
328
|
exclude_paths:
|
|
329
329
|
- lib/legacy
|
|
330
330
|
- lib/rake/legacy_tasks
|
|
331
|
-
- lib/smelly.rb
|
|
331
|
+
- lib/smelly.rb
|
|
332
332
|
```
|
|
333
333
|
|
|
334
334
|
As you see above, Reek's configuration consists of 3 different sections denoted by 3 different keys:
|
|
@@ -395,7 +395,7 @@ In case you need to suppress a smell warning and you can't or don't want to
|
|
|
395
395
|
use configuration files for whatever reasons you can also use special
|
|
396
396
|
source code comments like this:
|
|
397
397
|
|
|
398
|
-
```
|
|
398
|
+
```ruby
|
|
399
399
|
# This method smells of :reek:NestedIterators
|
|
400
400
|
def smelly_method foo
|
|
401
401
|
foo.each {|bar| bar.each {|baz| baz.qux}}
|
|
@@ -404,14 +404,14 @@ end
|
|
|
404
404
|
|
|
405
405
|
You can even pass in smell specific configuration settings:
|
|
406
406
|
|
|
407
|
-
```
|
|
407
|
+
```ruby
|
|
408
408
|
# :reek:NestedIterators { max_allowed_nesting: 2 }
|
|
409
409
|
def smelly_method foo
|
|
410
410
|
foo.each {|bar| bar.each {|baz| baz.qux}}
|
|
411
411
|
end
|
|
412
412
|
```
|
|
413
413
|
|
|
414
|
-
This is an incredibly powerful feature and further explained under [Smell
|
|
414
|
+
This is an incredibly powerful feature and further explained under [Smell Suppression](docs/Smell-Suppression.md).
|
|
415
415
|
|
|
416
416
|
#### Debugging trouble with the configuration
|
|
417
417
|
|
|
@@ -432,7 +432,7 @@ codebase this might not be an option.
|
|
|
432
432
|
Fortunately Reek provides a 'todo' flag which you can use to generate a configuration that will
|
|
433
433
|
suppress all smell warnings for the current codebase:
|
|
434
434
|
|
|
435
|
-
```
|
|
435
|
+
```bash
|
|
436
436
|
reek --todo lib/
|
|
437
437
|
```
|
|
438
438
|
|
|
@@ -447,7 +447,7 @@ If for whatever reasons you decide to put '.reek.yml' somewhere else where
|
|
|
447
447
|
Reek won't pick it up automatically you need to tell Reek explicitly to do so
|
|
448
448
|
via:
|
|
449
449
|
|
|
450
|
-
```
|
|
450
|
+
```bash
|
|
451
451
|
reek -c whatever/.reek.yml lib/
|
|
452
452
|
```
|
|
453
453
|
|
|
@@ -461,7 +461,7 @@ and instead abort execution. It also will not take **any** other configuration f
|
|
|
461
461
|
|
|
462
462
|
This means that when you run
|
|
463
463
|
|
|
464
|
-
```
|
|
464
|
+
```bash
|
|
465
465
|
reek -c other_configuration.reek --todo lib/
|
|
466
466
|
```
|
|
467
467
|
|
|
@@ -474,7 +474,7 @@ but keep in mind that this is not the intended use case of this feature.
|
|
|
474
474
|
|
|
475
475
|
Besides the obvious
|
|
476
476
|
|
|
477
|
-
```
|
|
477
|
+
```bash
|
|
478
478
|
reek [options] [dir_or_source_file]*
|
|
479
479
|
```
|
|
480
480
|
|
|
@@ -523,7 +523,7 @@ bundle exec rake console
|
|
|
523
523
|
You can also use Pry while running the tests by adding the following at the
|
|
524
524
|
point where you want to start debugging:
|
|
525
525
|
|
|
526
|
-
```
|
|
526
|
+
```ruby
|
|
527
527
|
require 'pry'
|
|
528
528
|
binding.pry
|
|
529
529
|
```
|
|
@@ -569,7 +569,7 @@ Reek supports 5 output formats:
|
|
|
569
569
|
Making Reek "Rails"-friendly is fairly simple since we support directory specific configurations (`directory directives` in Reek talk).
|
|
570
570
|
Just add this to your configuration file:
|
|
571
571
|
|
|
572
|
-
```
|
|
572
|
+
```yaml
|
|
573
573
|
directories:
|
|
574
574
|
"app/controllers":
|
|
575
575
|
IrresponsibleModule:
|
data/bin/code_climate_reek
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
require_relative '../lib/reek'
|
|
8
8
|
require_relative '../lib/reek/cli/application'
|
|
9
|
-
require_relative '../lib/reek/
|
|
9
|
+
require_relative '../lib/reek/code_climate'
|
|
10
|
+
Reek::CLI::Silencer.silently { require 'parser/current' }
|
|
10
11
|
|
|
11
12
|
# Map input coming from CodeClimate to Reek.
|
|
12
13
|
class CodeClimateToReek
|
|
@@ -16,6 +17,8 @@ class CodeClimateToReek
|
|
|
16
17
|
'--failure-exit-code', '0',
|
|
17
18
|
'--success-exit-code', '0'
|
|
18
19
|
].freeze
|
|
20
|
+
CUSTOM_CONFIG_KEY = 'config'
|
|
21
|
+
CUSTOM_CONFIG_TARGET_RUBY_VERSION_KEY = 'target_ruby_version'
|
|
19
22
|
|
|
20
23
|
attr_reader :configuration_file_path, :include_paths_key, :include_paths_default
|
|
21
24
|
|
|
@@ -31,6 +34,10 @@ class CodeClimateToReek
|
|
|
31
34
|
include_paths + ENGINE_CONFIGURATION
|
|
32
35
|
end
|
|
33
36
|
|
|
37
|
+
def target_ruby_version
|
|
38
|
+
config.dig(CUSTOM_CONFIG_KEY, CUSTOM_CONFIG_TARGET_RUBY_VERSION_KEY)
|
|
39
|
+
end
|
|
40
|
+
|
|
34
41
|
private
|
|
35
42
|
|
|
36
43
|
def configuration_file_exists?
|
|
@@ -45,11 +52,14 @@ class CodeClimateToReek
|
|
|
45
52
|
# ]
|
|
46
53
|
# }
|
|
47
54
|
def include_paths
|
|
55
|
+
config.fetch include_paths_key, include_paths_default
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def config
|
|
48
59
|
if configuration_file_exists?
|
|
49
|
-
|
|
50
|
-
config.fetch include_paths_key, include_paths_default
|
|
60
|
+
JSON.parse File.read(configuration_file_path)
|
|
51
61
|
else
|
|
52
|
-
|
|
62
|
+
{}
|
|
53
63
|
end
|
|
54
64
|
end
|
|
55
65
|
end
|
|
@@ -57,11 +67,50 @@ end
|
|
|
57
67
|
# Override for ReportCommand to force the use of CodeClimateReport.
|
|
58
68
|
module ReportClassOverride
|
|
59
69
|
def report_class
|
|
60
|
-
Reek::
|
|
70
|
+
Reek::CodeClimate::CodeClimateReport
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Override Reek::Source::SourceCode to use a parser version specified by the user
|
|
75
|
+
module SourceCodeOverride
|
|
76
|
+
# override self.default_parser method
|
|
77
|
+
def default_parser
|
|
78
|
+
parser_class.new(Reek::AST::Builder.new).tap do |parser|
|
|
79
|
+
diagnostics = parser.diagnostics
|
|
80
|
+
diagnostics.all_errors_are_fatal = true
|
|
81
|
+
diagnostics.ignore_warnings = true
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# config.json file will look like this:
|
|
86
|
+
# {
|
|
87
|
+
# "include_paths":[
|
|
88
|
+
# "lib",
|
|
89
|
+
# "spec"
|
|
90
|
+
# ],
|
|
91
|
+
# "config": {
|
|
92
|
+
# "target_ruby_version": "3.1.0"
|
|
93
|
+
# }
|
|
94
|
+
# }
|
|
95
|
+
def parser_class
|
|
96
|
+
# convert an X.Y.Z version number to an XY two digit number
|
|
97
|
+
requested_version = CodeClimateToReek.new.target_ruby_version
|
|
98
|
+
return Parser::CurrentRuby if requested_version.nil?
|
|
99
|
+
|
|
100
|
+
version_number = Gem::Version.new(requested_version).segments[0..1].join
|
|
101
|
+
|
|
102
|
+
begin
|
|
103
|
+
Reek::CLI::Silencer.silently { require "parser/ruby#{version_number}" }
|
|
104
|
+
Module.const_get("Parser::Ruby#{version_number}")
|
|
105
|
+
rescue LoadError, NameError
|
|
106
|
+
# use Parser::CurrentRuby when an invalid version number is provided
|
|
107
|
+
Parser::CurrentRuby
|
|
108
|
+
end
|
|
61
109
|
end
|
|
62
110
|
end
|
|
63
111
|
|
|
64
112
|
Reek::CLI::Command::ReportCommand.prepend ReportClassOverride
|
|
113
|
+
Reek::Source::SourceCode.singleton_class.prepend SourceCodeOverride
|
|
65
114
|
|
|
66
115
|
application = Reek::CLI::Application.new(CodeClimateToReek.new.cli_arguments)
|
|
67
116
|
|
|
@@ -115,6 +115,15 @@ module Reek
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
# rubocop:enable Naming/ClassAndModuleCamelCase
|
|
118
|
+
|
|
119
|
+
# Utility methods for :kwnilarg nodes.
|
|
120
|
+
module KwnilargNode
|
|
121
|
+
include ArgNodeBase
|
|
122
|
+
|
|
123
|
+
def anonymous_splat?
|
|
124
|
+
true
|
|
125
|
+
end
|
|
126
|
+
end
|
|
118
127
|
end
|
|
119
128
|
end
|
|
120
129
|
end
|
|
@@ -24,13 +24,10 @@ module Reek
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def module_creation_call?
|
|
27
|
-
object_creation_call? && module_creation_receiver?
|
|
28
|
-
|
|
27
|
+
return true if object_creation_call? && module_creation_receiver?
|
|
28
|
+
return true if data_definition_call? && data_definition_receiver?
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
receiver &&
|
|
32
|
-
receiver.type == :const &&
|
|
33
|
-
[:Class, :Struct].include?(receiver.simple_name)
|
|
30
|
+
false
|
|
34
31
|
end
|
|
35
32
|
|
|
36
33
|
def object_creation_call?
|
|
@@ -47,6 +44,24 @@ module Reek
|
|
|
47
44
|
def attr_with_writable_flag?
|
|
48
45
|
name == :attr && args.any? && args.last.type == :true
|
|
49
46
|
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def module_creation_receiver?
|
|
51
|
+
const_receiver? && [:Class, :Struct].include?(receiver.simple_name)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def data_definition_call?
|
|
55
|
+
name == :define
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def data_definition_receiver?
|
|
59
|
+
const_receiver? && receiver.simple_name == :Data
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def const_receiver?
|
|
63
|
+
receiver && receiver.type == :const
|
|
64
|
+
end
|
|
50
65
|
end
|
|
51
66
|
|
|
52
67
|
Op_AsgnNode = SendNode
|
|
@@ -13,7 +13,7 @@ module Reek
|
|
|
13
13
|
#
|
|
14
14
|
class TodoListCommand < BaseCommand
|
|
15
15
|
HEADER = "# Auto generated by Reeks --todo flag\n"
|
|
16
|
-
EXISTING_FILE_MESSAGE = "\nExisting '#{DEFAULT_CONFIGURATION_FILE_NAME}' detected - aborting.\n"
|
|
16
|
+
EXISTING_FILE_MESSAGE = "\nExisting '#{DEFAULT_CONFIGURATION_FILE_NAME}' detected - aborting.\n".freeze
|
|
17
17
|
NO_SMELLS_FOUND_MESSAGE = "\nNo smells found - nothing to do, exiting.\n"
|
|
18
18
|
|
|
19
19
|
def execute
|
|
@@ -23,7 +23,7 @@ module Reek
|
|
|
23
23
|
puts EXISTING_FILE_MESSAGE
|
|
24
24
|
else
|
|
25
25
|
write_to_file
|
|
26
|
-
puts "\n'#{DEFAULT_CONFIGURATION_FILE_NAME}' generated! "\
|
|
26
|
+
puts "\n'#{DEFAULT_CONFIGURATION_FILE_NAME}' generated! " \
|
|
27
27
|
'You can now use this as a starting point.'
|
|
28
28
|
end
|
|
29
29
|
options.success_exit_code
|
data/lib/reek/cli/options.rb
CHANGED
|
@@ -110,12 +110,12 @@ module Reek
|
|
|
110
110
|
parser.on('--smell SMELL',
|
|
111
111
|
'Only look for a specific smell.',
|
|
112
112
|
'Call it like this: reek --smell MissingSafeMethod source.rb',
|
|
113
|
-
"Check out #{DocumentationLink.build('Code Smells')} "\
|
|
113
|
+
"Check out #{DocumentationLink.build('Code Smells')} " \
|
|
114
114
|
'for a list of smells') do |smell|
|
|
115
115
|
smells_to_detect << smell
|
|
116
116
|
end
|
|
117
117
|
parser.on('--stdin-filename FILE',
|
|
118
|
-
'When passing code in via pipe, assume this filename when '\
|
|
118
|
+
'When passing code in via pipe, assume this filename when ' \
|
|
119
119
|
'checking file or directory rules in the config.') do |file|
|
|
120
120
|
self.stdin_filename = file
|
|
121
121
|
end
|
|
@@ -210,12 +210,12 @@ module Reek
|
|
|
210
210
|
def set_exit_codes
|
|
211
211
|
parser.separator "\nExit codes:"
|
|
212
212
|
parser.on('--success-exit-code CODE',
|
|
213
|
-
'The exit code when no smells are found '\
|
|
213
|
+
'The exit code when no smells are found ' \
|
|
214
214
|
"(default: #{Status::DEFAULT_SUCCESS_EXIT_CODE})") do |option|
|
|
215
215
|
self.success_exit_code = Integer(option)
|
|
216
216
|
end
|
|
217
217
|
parser.on('--failure-exit-code CODE',
|
|
218
|
-
'The exit code when smells are found '\
|
|
218
|
+
'The exit code when smells are found ' \
|
|
219
219
|
"(default: #{Status::DEFAULT_FAILURE_EXIT_CODE})") do |option|
|
|
220
220
|
self.failure_exit_code = Integer(option)
|
|
221
221
|
end
|
|
@@ -231,7 +231,7 @@ module Reek
|
|
|
231
231
|
parser.on_tail('-l', '--list', 'List all available smell detectors') do
|
|
232
232
|
puts "All available smell detectors:\n\n"
|
|
233
233
|
puts DetectorRepository.available_detector_names
|
|
234
|
-
puts "\nCheck out #{DocumentationLink.build('Code Smells')} "\
|
|
234
|
+
puts "\nCheck out #{DocumentationLink.build('Code Smells')} " \
|
|
235
235
|
'for a details on each detector'
|
|
236
236
|
exit
|
|
237
237
|
end
|