reek 6.1.4 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +4 -4
  3. data/.rubocop.yml +1 -9
  4. data/CHANGELOG.md +60 -0
  5. data/CONTRIBUTING.md +6 -9
  6. data/Gemfile +5 -4
  7. data/README.md +27 -27
  8. data/bin/code_climate_reek +54 -5
  9. data/lib/reek/ast/sexp_extensions/send.rb +21 -6
  10. data/lib/reek/cli/command/todo_list_command.rb +1 -1
  11. data/lib/reek/{report/code_climate → code_climate}/code_climate_configuration.rb +1 -1
  12. data/lib/reek/{report/code_climate → code_climate}/code_climate_configuration.yml +38 -38
  13. data/lib/reek/{report/code_climate → code_climate}/code_climate_fingerprint.rb +2 -2
  14. data/lib/reek/{report/code_climate → code_climate}/code_climate_formatter.rb +1 -1
  15. data/lib/reek/{report/code_climate → code_climate}/code_climate_report.rb +3 -3
  16. data/lib/reek/code_comment.rb +3 -3
  17. data/lib/reek/configuration/app_configuration.rb +5 -5
  18. data/lib/reek/configuration/configuration_converter.rb +1 -1
  19. data/lib/reek/configuration/configuration_file_finder.rb +3 -3
  20. data/lib/reek/configuration/default_directive.rb +1 -1
  21. data/lib/reek/configuration/directory_directives.rb +1 -1
  22. data/lib/reek/configuration/excluded_paths.rb +1 -1
  23. data/lib/reek/configuration/schema.rb +177 -0
  24. data/lib/reek/configuration/schema_validator.rb +12 -13
  25. data/lib/reek/context/attribute_context.rb +1 -1
  26. data/lib/reek/context/method_context.rb +1 -1
  27. data/lib/reek/context/send_context.rb +1 -1
  28. data/lib/reek/documentation_link.rb +3 -5
  29. data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +2 -2
  30. data/lib/reek/errors/bad_detector_in_comment_error.rb +2 -2
  31. data/lib/reek/errors/encoding_error.rb +1 -1
  32. data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +2 -2
  33. data/lib/reek/errors/incomprehensible_source_error.rb +1 -1
  34. data/lib/reek/errors/legacy_comment_separator_error.rb +2 -2
  35. data/lib/reek/errors/syntax_error.rb +1 -1
  36. data/lib/reek/smell_detectors/control_parameter_helpers/control_parameter_finder.rb +1 -1
  37. data/lib/reek/smell_detectors/instance_variable_assumption.rb +8 -8
  38. data/lib/reek/smell_detectors/nested_iterators.rb +4 -3
  39. data/lib/reek/smell_detectors/unused_private_method.rb +2 -2
  40. data/lib/reek/version.rb +1 -1
  41. data/reek.gemspec +4 -3
  42. metadata +30 -16
  43. data/lib/reek/configuration/schema.yml +0 -210
  44. /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: 75ed5064f626b7d8ae34f869ee17d53960804381fb73db707c866202bb71490a
4
- data.tar.gz: 07f819f93d3ac3f84deb0a0a113dfbc3136e70f9b097f72e1c535f4352fb8b7f
3
+ metadata.gz: a1093258cb1b25a91e16e800eabcee4087d4ae8830d579decc6b11433b6fd9c4
4
+ data.tar.gz: ea2c3a5e1f51edd9bdfcb1fe973b4d08210491f34bcfb26278bc970cd61325bf
5
5
  SHA512:
6
- metadata.gz: 71313200963b12c5c2edb8cd84d5ee4ea8fd99241c1fa0f6c6329e332ba41538b5a11990b54f24a136a748bc2492fd87f5ffcd78ef358bdd4f1420970bd2915b
7
- data.tar.gz: 2f39a6f2ea9cf9a4d8eb629bc5542883ecccfb8811c1fc062a2c0aa8deb41ceacd47de2a76a2f9cb8f6b0e6b56da63551f403edc14e55cd35ae7bac62822a2b3
6
+ metadata.gz: 56e29753527fc67429285f7da3537411ac951567d41a59024895fefa4287523e67c8c78332bc46375b4b6b154bf68bb6b5d6665f10cadec4f86654e0f5ea0a00
7
+ data.tar.gz: e2b1f0f40d67f5ba966f527d9afdd1a18e6c6150ade2658a5316750f1d03ca5aef7580a82f59d59e617c581323dff8ef0b7d71ea070442a45cc924649edf32e7
@@ -22,10 +22,10 @@ jobs:
22
22
 
23
23
  strategy:
24
24
  matrix:
25
- ruby: ["2.6", "2.7", "3.0", "3.1", "3.2", "jruby-9.3", "jruby-9.4"]
25
+ ruby: ["3.0", "3.1", "3.2", "jruby-9.4", "3.3"]
26
26
 
27
27
  steps:
28
- - uses: actions/checkout@v3
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@v3
50
+ - uses: actions/checkout@v4
51
51
  - name: Set up Ruby
52
52
  uses: ruby/setup-ruby@v1
53
53
  with:
54
- ruby-version: 2.7
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: 2.6
15
+ TargetRubyVersion: 3.0
16
16
 
17
17
  # Tables are nice
18
18
  Layout/HashAlignment:
@@ -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,65 @@
1
+
1
2
  # Change log
2
3
 
4
+ ## 6.3.0 (2024-01-28)
5
+
6
+ ### Features and bugfixes
7
+
8
+ * Update parser dependency to the 3.3.x series([#1761] by [mvz])
9
+
10
+ ## 6.2.0 (2023-12-31)
11
+
12
+ ### Features and bugfixes
13
+
14
+ * Code Climate: add config `target_ruby_version` to support different versions
15
+ of Ruby syntax ([#1694] by [dantevvp])
16
+ * Treat `Data.define` as a class definition ([#1725] by [mvz])
17
+ * Fix Instance Variable Assumption false positive ([#1737] by [JuanVqz])
18
+ * Add `Tempfile.create` to ignored iterators list ([#1747] by [mateusdeap])
19
+ * Improve configuration schema validation. This also replaces the kwalify
20
+ dependency with dry-schema ([#1749] by [fbuys])
21
+
22
+ ### Dependencies
23
+
24
+ * Add missing dependency rexml ([#1703] by [tricknotes])
25
+ * Drop support for Ruby 2.6 and 2.7 ([#1716] and [#1755] by [mvz])
26
+ * Add support for Ruby 3.3 ([#1756] and [#1755] by [mvz])
27
+
28
+ ### Documentation
29
+
30
+ * Fix the badges in our README ([#1711] by [troessner])
31
+ * Remove non working link in CONTRIBUTING.md ([#1738] by [JuanVqz])
32
+ * Add downloads badge ([#1750] by [troessner])
33
+
34
+ ### Internal
35
+
36
+ * Rename Code Climate related classes ([#1735] by [mvz])
37
+ * Fix `cucumber_opts` warning ([#1736] by [JuanVqz])
38
+ * Fix editor highlighting for fenced code blocks in documentation ([#1745] by [JuanVqz])
39
+
40
+ [JuanVqz]: https://github.com/JuanVqz
41
+ [dantevvp]: https://github.com/dantevvp
42
+ [fbuys]: https://github.com/fbuys
43
+ [mateusdeap]: https://github.com/mateusdeap
44
+ [mvz]: https://github.com/mvz
45
+ [tricknotes]: https://github.com/tricknotes
46
+ [troessner]: https://github.com/troessner
47
+
48
+ [#1694]: https://github.com/troessner/reek/pull/1694
49
+ [#1703]: https://github.com/troessner/reek/pull/1703
50
+ [#1711]: https://github.com/troessner/reek/pull/1711
51
+ [#1725]: https://github.com/troessner/reek/pull/1725
52
+ [#1735]: https://github.com/troessner/reek/pull/1735
53
+ [#1736]: https://github.com/troessner/reek/pull/1736
54
+ [#1737]: https://github.com/troessner/reek/pull/1737
55
+ [#1738]: https://github.com/troessner/reek/pull/1738
56
+ [#1745]: https://github.com/troessner/reek/pull/1745
57
+ [#1749]: https://github.com/troessner/reek/pull/1749
58
+ [#1747]: https://github.com/troessner/reek/pull/1747
59
+ [#1750]: https://github.com/troessner/reek/pull/1750
60
+ [#1756]: https://github.com/troessner/reek/pull/1756
61
+ [#1755]: https://github.com/troessner/reek/pull/1755
62
+
3
63
  ## 6.1.4 (2023-01-13)
4
64
 
5
65
  * (mvz) Update parser dependency to the 3.2.x series
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/). We're not using
66
- RSpec's
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
- ```Ruby
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
- ```Ruby
84
+ ```ruby
88
85
  class Alfa
89
86
  def bravo(charlie)
90
87
  charlie.delta
@@ -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
- ```Bash
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
- ```Bash
207
+ ```bash
211
208
  bundle exec rake release
212
209
  ```
data/Gemfile CHANGED
@@ -6,16 +6,17 @@ ruby RUBY_VERSION
6
6
 
7
7
  group :development do
8
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', '~> 8.0'
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.43.0'
17
- gem 'rubocop-performance', '~> 1.15.0'
18
- gem 'rubocop-rspec', '~> 2.17.0'
17
+ gem 'rubocop', '~> 1.60.2'
18
+ gem 'rubocop-performance', '~> 1.20.0'
19
+ gem 'rubocop-rspec', '~> 2.26.0'
19
20
  gem 'simplecov', '>= 0.18.0', '< 0.23.0'
20
21
  gem 'yard', '~> 0.9.5'
21
22
 
data/README.md CHANGED
@@ -35,15 +35,15 @@
35
35
 
36
36
  ## Overview
37
37
 
38
- * [![Build Status](https://secure.travis-ci.org/troessner/reek.svg?branch=master)](https://travis-ci.org/troessner/reek?branch=master)
38
+ * ![Downloads](https://img.shields.io/badge/Downloads-%3E24_million-blue)
39
+ * ![Build Status](https://github.com/troessner/reek/actions/workflows/ruby.yml/badge.svg?branch=master)
39
40
  * [![Gem Version](https://badge.fury.io/rb/reek.svg)](https://badge.fury.io/rb/reek)
40
- * ![](http://img.shields.io/github/tag/troessner/reek.svg)
41
- * ![](http://img.shields.io/badge/license-MIT-brightgreen.svg)
41
+ * ![Git Tag](http://img.shields.io/github/tag/troessner/reek.svg)
42
+ * ![Licence](http://img.shields.io/badge/license-MIT-brightgreen.svg)
42
43
  * [![Inline docs](https://inch-ci.org/github/troessner/reek.png)](https://inch-ci.org/github/troessner/reek)
43
44
  * [![Code Climate](https://codeclimate.com/github/troessner/reek/badges/gpa.svg)](https://codeclimate.com/github/troessner/reek)
44
45
  * [![codebeat](https://codebeat.co/badges/42fed4ff-3e55-4aed-8ecc-409b4aa539b3)](https://codebeat.co/projects/github-com-troessner-reek)
45
- * ![](http://ruby-gem-downloads-badge.herokuapp.com/reek?type=total)
46
- * ![](http://ruby-gem-downloads-badge.herokuapp.com/reek?label=downloads-current-version)
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
- ```Bash
59
+ ```bash
60
60
  gem install reek
61
61
  ```
62
62
 
63
63
  and run it like this:
64
64
 
65
- ```Bash
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
- ```Ruby
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
- ```Ruby
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
- ```Ruby
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
- ```Bash
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
- ```Bash
176
+ ```bash
177
177
  reek
178
178
  ```
179
179
 
180
180
  is the exact same thing as being explicit:
181
181
 
182
- ```Bash
182
+ ```bash
183
183
  reek .
184
184
  ```
185
185
 
186
186
  Additionally you can pipe code to Reek like this:
187
187
 
188
- ```Bash
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
- ```Bash
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
- ```Yaml
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
- ```Yaml
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
- ```Ruby
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
- ```Ruby
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,7 +404,7 @@ end
404
404
 
405
405
  You can even pass in smell specific configuration settings:
406
406
 
407
- ```Ruby
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}}
@@ -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
- ```Bash
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
- ```Bash
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
- ```Bash
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
- ```Bash
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
- ```Ruby
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
- ```Yaml
572
+ ```yaml
573
573
  directories:
574
574
  "app/controllers":
575
575
  IrresponsibleModule:
@@ -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/report/code_climate'
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
- config = JSON.parse File.read(configuration_file_path)
50
- config.fetch include_paths_key, include_paths_default
60
+ JSON.parse File.read(configuration_file_path)
51
61
  else
52
- include_paths_default
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::Report::CodeClimateReport
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
 
@@ -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
- end
27
+ return true if object_creation_call? && module_creation_receiver?
28
+ return true if data_definition_call? && data_definition_receiver?
29
29
 
30
- def module_creation_receiver?
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Reek
4
- module Report
4
+ module CodeClimate
5
5
  # loads the smell type metadata to present in Code Climate
6
6
  module CodeClimateConfiguration
7
7
  def self.load