reek 5.6.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -1
  4. data/.simplecov +1 -0
  5. data/.travis.yml +12 -11
  6. data/CHANGELOG.md +8 -0
  7. data/Dockerfile +1 -0
  8. data/Gemfile +15 -17
  9. data/README.md +1 -7
  10. data/bin/code_climate_reek +12 -2
  11. data/docs/Attribute.md +1 -1
  12. data/docs/Control-Couple.md +1 -1
  13. data/docs/Nil-Check.md +4 -1
  14. data/features/command_line_interface/options.feature +2 -3
  15. data/features/reports/codeclimate.feature +2 -2
  16. data/features/reports/json.feature +3 -3
  17. data/features/reports/reports.feature +4 -4
  18. data/features/reports/yaml.feature +3 -3
  19. data/features/step_definitions/reek_steps.rb +4 -0
  20. data/lib/reek/ast/sexp_extensions/arguments.rb +11 -0
  21. data/lib/reek/cli/options.rb +2 -2
  22. data/lib/reek/code_comment.rb +36 -29
  23. data/lib/reek/errors/legacy_comment_separator_error.rb +36 -0
  24. data/lib/reek/report.rb +5 -7
  25. data/lib/reek/report/code_climate/code_climate_report.rb +2 -1
  26. data/lib/reek/report/simple_warning_formatter.rb +0 -7
  27. data/lib/reek/smell_detectors/base_detector.rb +0 -9
  28. data/lib/reek/smell_detectors/data_clump.rb +23 -56
  29. data/lib/reek/smell_detectors/nil_check.rb +1 -12
  30. data/lib/reek/version.rb +1 -1
  31. data/reek.gemspec +5 -6
  32. data/spec/reek/ast/sexp_extensions_spec.rb +15 -33
  33. data/spec/reek/code_comment_spec.rb +23 -21
  34. data/spec/reek/context_builder_spec.rb +110 -113
  35. data/spec/reek/smell_detectors/base_detector_spec.rb +0 -10
  36. data/spec/reek/smell_detectors/data_clump_spec.rb +14 -0
  37. data/spec/reek/smell_detectors/missing_safe_method_spec.rb +8 -2
  38. data/spec/reek/smell_detectors/nil_check_spec.rb +3 -3
  39. data/spec/reek/source/source_code_spec.rb +13 -0
  40. data/spec/spec_helper.rb +1 -0
  41. metadata +6 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da76dfc3aa1c997bffe832e526907dcf847cb5d86e04bc7c084abe074247e5d7
4
- data.tar.gz: 7abc545f4176d0f561797c092bea15f1630b824a3d3ba37b99975450eb3ec3df
3
+ metadata.gz: bf5a72026003b4d6b44ec51ba559efda3de62733061d6889596d8661ec24a12c
4
+ data.tar.gz: 142319663079b82d851245cf6aa0e3a07ea5418426d21c25171d4fae1adc8549
5
5
  SHA512:
6
- metadata.gz: 7fe6f93cf2fe75c232327e1250c4e72c10c88707ce57879341f43b5a8a195ddb0282d9433e60cb19f635923edcb3fa52bbaadb187b5ee67d4b4cea7fc72ce901
7
- data.tar.gz: a55abca10a6875077fda0b873667407f1dddf1840963fd6463ed918db9d9e58408fa93acf5a7e4741d9d488dede75963ad422c2150953e3d69f7af840a563dfd
6
+ metadata.gz: 8a626593f82fcb8307629380ca25374b73d013561a3c2b0ffb2a7b5175997632b1f2925add8fb2d7ff1fe10d3a6343ee8998d5d167d45ce09888ea59c8c2ec6e
7
+ data.tar.gz: f081217d15f01c31cc014ef935b359614ee412c8aa7c0fbbb22e40db0caa1dd0429b727935c02542ea1e73ca7023b15cb25d639d644e8ab3af42af33870f0de6
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg
2
+ spec/examples.txt
2
3
  spec/output
3
4
  tmp
4
5
  doc
@@ -9,7 +9,7 @@ AllCops:
9
9
  - 'samples/**/*'
10
10
  - 'tmp/**/*'
11
11
  - 'vendor/**/*'
12
- TargetRubyVersion: 2.3
12
+ TargetRubyVersion: 2.4
13
13
 
14
14
  # Tables are nice
15
15
  Layout/HashAlignment:
data/.simplecov CHANGED
@@ -5,6 +5,7 @@ SimpleCov.start do
5
5
  add_filter 'spec/'
6
6
  add_filter 'samples/'
7
7
  coverage_dir 'tmp/coverage'
8
+ enable_coverage :branch
8
9
  end
9
10
 
10
11
  SimpleCov.at_exit do
@@ -1,35 +1,36 @@
1
- dist: trusty
2
- cache: bundler
3
1
  language: ruby
2
+
3
+ dist: xenial
4
+
5
+ cache:
6
+ bundler: true
7
+
4
8
  bundler_args: --without debugging
5
- before_script:
6
- # Avoid Java announcing _JAVA_OPTIONS environment variable
7
- # See https://github.com/travis-ci/travis-ci/issues/8408
8
- - unset _JAVA_OPTIONS
9
+
9
10
  script: bundle exec rake ci
11
+
10
12
  rvm:
11
- - 2.3
12
13
  - 2.4
13
14
  - 2.5
14
15
  - 2.6
15
16
  - 2.7
16
- - jruby-9.1.17.0
17
- - jruby-9.2.6.0
17
+ - jruby-9.2
18
18
  - jruby-head
19
19
  - ruby-head
20
- - rubinius-3
20
+
21
21
  matrix:
22
22
  allow_failures:
23
23
  - rvm: jruby-head
24
24
  - rvm: ruby-head
25
- - rvm: rubinius-3
26
25
  fast_finish: true
26
+
27
27
  notifications:
28
28
  email:
29
29
  - timo.roessner@googlemail.com
30
30
  - matijs@matijs.net
31
31
  - chastell@chastell.net
32
32
  irc: irc.freenode.org#reek
33
+
33
34
  branches:
34
35
  only:
35
36
  - master
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 6.0.0 (2020-03-30)
4
+
5
+ * (mvz) Make codeclimate-engine-rb a development dependency
6
+ * (mvz) Drop support for Ruby 2.3
7
+ * (mvz) Raise error when legacy code comment format is used
8
+ * (mvz) Stop reporting NilCheck for safe navigation
9
+ * (likeath) Properly handle "Forward all" syntax
10
+
3
11
  ## 5.6.0 (2020-01-20)
4
12
 
5
13
  * (mvz) Support Ruby 2.7
data/Dockerfile CHANGED
@@ -22,6 +22,7 @@ WORKDIR ${app_dir}
22
22
 
23
23
  RUN gem install rake
24
24
  RUN bundle install --without debugging development
25
+ RUN gem install codeclimate-engine-rb
25
26
 
26
27
  VOLUME ${code_dir}
27
28
  WORKDIR ${code_dir}
data/Gemfile CHANGED
@@ -5,19 +5,20 @@ gemspec
5
5
  ruby RUBY_VERSION
6
6
 
7
7
  group :development do
8
- gem 'aruba', '~> 0.14.8'
9
- gem 'cucumber', '~> 3.0'
10
- gem 'factory_bot', '~> 5.0', '!= 5.1.0'
11
- gem 'kramdown', '~> 2.1'
12
- gem 'kramdown-parser-gfm', '~> 1.0'
13
- gem 'rake', '~> 13.0'
14
- gem 'rspec', '~> 3.0'
15
- gem 'rspec-benchmark', '~> 0.5.0'
16
- gem 'rubocop', '~> 0.79.0'
17
- gem 'rubocop-performance', '~> 1.5.0'
18
- gem 'rubocop-rspec', '~> 1.37.0'
19
- gem 'simplecov', '~> 0.17.0'
20
- gem 'yard', '~> 0.9.5'
8
+ gem 'aruba', '~> 1.0'
9
+ gem 'codeclimate-engine-rb', '~> 0.4.0'
10
+ gem 'cucumber', '~> 3.0'
11
+ gem 'factory_bot', '~> 5.0', '!= 5.1.0'
12
+ gem 'kramdown', '~> 2.1'
13
+ gem 'kramdown-parser-gfm', '~> 1.0'
14
+ gem 'rake', '~> 13.0'
15
+ gem 'rspec', '~> 3.0'
16
+ gem 'rspec-benchmark', '~> 0.6.0'
17
+ gem 'rubocop', '~> 0.80.0'
18
+ gem 'rubocop-performance', '~> 1.5.0'
19
+ gem 'rubocop-rspec', '~> 1.38.1'
20
+ gem 'simplecov', '~> 0.18.1'
21
+ gem 'yard', '~> 0.9.5'
21
22
 
22
23
  platforms :mri do
23
24
  gem 'redcarpet', '~> 3.4'
@@ -25,8 +26,5 @@ group :development do
25
26
  end
26
27
 
27
28
  group :debugging do
28
- gem 'pry'
29
- platforms :mri do
30
- gem 'pry-byebug'
31
- end
29
+ gem 'pry', '~> 0.13.0'
32
30
  end
data/README.md CHANGED
@@ -45,12 +45,6 @@
45
45
  * ![](http://ruby-gem-downloads-badge.herokuapp.com/reek?type=total)
46
46
  * ![](http://ruby-gem-downloads-badge.herokuapp.com/reek?label=downloads-current-version)
47
47
 
48
- ## Reek 5 is out!
49
-
50
- Reek 5 is out and with it a bunch of breaking changes. If you're a new user you can just
51
- continue with the quickstart below. If you're a Reek 4 user and would like to upgrade to 5, don't
52
- worry, this shouldn't take you more than 10 minutes. Check out our [Upgrade Guide](docs/Reek-4-to-Reek-5-migration.md).
53
-
54
48
  ## Quickstart
55
49
 
56
50
  Reek is a tool that examines Ruby classes, modules and methods and reports any
@@ -100,7 +94,7 @@ demo.rb -- 2 warnings:
100
94
 
101
95
  ## Supported Ruby versions
102
96
 
103
- Reek is officially supported for CRuby 2.3 to 2.6 and for JRuby 9.1 and 9.2.
97
+ Reek is officially supported for CRuby 2.4 to 2.7 and for JRuby 9.2.
104
98
  Other Ruby implementations (like Rubinius) are not officially supported but
105
99
  should work as well.
106
100
 
@@ -6,15 +6,16 @@
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
10
 
10
11
  # Map input coming from CodeClimate to Reek.
11
12
  class CodeClimateToReek
12
13
  # Following the spec (https://github.com/codeclimate/spec/blob/master/SPEC.md)
13
14
  # we have to exit with a zero for both failure and success.
14
15
  ENGINE_CONFIGURATION = [
15
- '-f', 'code_climate',
16
16
  '--failure-exit-code', '0',
17
- '--success-exit-code', '0'
17
+ '--success-exit-code', '0',
18
+ '.'
18
19
  ].freeze
19
20
 
20
21
  attr_reader :configuration_file_path, :include_paths_key, :include_paths_default
@@ -54,6 +55,15 @@ class CodeClimateToReek
54
55
  end
55
56
  end
56
57
 
58
+ # Override for ReportCommand to force the use of CodeClimateReport.
59
+ module ReportClassOverride
60
+ def report_class
61
+ Reek::Report::CodeClimateReport
62
+ end
63
+ end
64
+
65
+ Reek::CLI::Command::ReportCommand.prepend ReportClassOverride
66
+
57
67
  application = Reek::CLI::Application.new(CodeClimateToReek.new.cli_arguments)
58
68
 
59
69
  exit application.execute
@@ -29,7 +29,7 @@ test.rb -- 1 warning:
29
29
 
30
30
  ## Support in Reek
31
31
 
32
- This detector it raises a warning for every public `attr_writer`,
32
+ This detector raises a warning for every public `attr_writer`,
33
33
  `attr_accessor`, and `attr` with the writable flag set to `true`.
34
34
 
35
35
  Reek does not raise warnings for read-only attributes.
@@ -14,7 +14,7 @@ controlling parameter must be reflected on both sides of the call. A _Control
14
14
  Couple_ also reveals a loss of simplicity: the called method probably has more
15
15
  than one responsibility, because it includes at least two different code paths.
16
16
 
17
- 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).
17
+ You can find a good write-up regarding this problem [here](https://solnic.codes/2012/04/11/get-rid-of-that-code-smell-control-couple/).
18
18
 
19
19
  ## Current Support in Reek
20
20
 
@@ -37,7 +37,10 @@ _Nil Check_ reports use of
37
37
  * <code>.nil?</code> method
38
38
  * <code>==</code> and <code>===</code> operators when checking vs. <code>nil</code>
39
39
  * case statements that use syntax like <code>when nil</code>
40
- * use of the safe navigation operator like `foo&.bar`
40
+
41
+ _Nil Check_ allows use of
42
+
43
+ * the safe navigation operator like `foo&.bar`
41
44
 
42
45
  ## Configuration
43
46
 
@@ -43,7 +43,7 @@ Feature: Reek can be controlled using command-line options
43
43
  -c, --config FILE Read configuration options from FILE
44
44
  --smell SMELL Only look for a specific smell.
45
45
  Call it like this: reek --smell MissingSafeMethod source.rb
46
- Check out https://github.com/troessner/reek/blob/v5.6.0/docs/Code-Smells.md for a list of smells
46
+ Check out https://github.com/troessner/reek/blob/v6.0.0/docs/Code-Smells.md for a list of smells
47
47
  --stdin-filename FILE When passing code in via pipe, assume this filename when checking file or directory rules in the config.
48
48
 
49
49
  Generate a todo list:
@@ -56,7 +56,6 @@ Feature: Reek can be controlled using command-line options
56
56
  yaml
57
57
  json
58
58
  xml
59
- code_climate
60
59
 
61
60
  Text format options:
62
61
  --[no-]color Use colors for the output (default: true)
@@ -120,5 +119,5 @@ Feature: Reek can be controlled using command-line options
120
119
  UnusedPrivateMethod
121
120
  UtilityFunction
122
121
 
123
- Check out https://github.com/troessner/reek/blob/v5.6.0/docs/Code-Smells.md for a details on each detector
122
+ Check out https://github.com/troessner/reek/blob/v6.0.0/docs/Code-Smells.md for a details on each detector
124
123
  """
@@ -4,7 +4,7 @@ Feature: Report smells using Code Climate format
4
4
 
5
5
  Scenario: output is empty when there are no smells
6
6
  Given a directory called 'clean' containing two clean files
7
- When I run reek --format code_climate clean
7
+ When I run the code climate reek runner
8
8
  Then it succeeds
9
9
  And it reports this Code Climate output:
10
10
  """
@@ -12,7 +12,7 @@ Feature: Report smells using Code Climate format
12
12
 
13
13
  Scenario: Indicate smells and print them as JSON when using files
14
14
  Given the smelly file 'smelly.rb'
15
- When I run reek --format code_climate smelly.rb
15
+ When I run the code climate reek runner
16
16
  Then it reports this Code Climate output:
17
17
  """
18
18
  {
@@ -24,7 +24,7 @@ Feature: Report smells using simple JSON layout
24
24
  "context": "Smelly#x",
25
25
  "lines": [ 4 ],
26
26
  "message": "has the name 'x'",
27
- "documentation_link": "https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Method-Name.md",
27
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Method-Name.md",
28
28
  "name": "x"
29
29
  },
30
30
  {
@@ -33,7 +33,7 @@ Feature: Report smells using simple JSON layout
33
33
  "context": "Smelly#x",
34
34
  "lines": [ 5 ],
35
35
  "message": "has the variable name 'y'",
36
- "documentation_link": "https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Variable-Name.md",
36
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Variable-Name.md",
37
37
  "name": "y"
38
38
  }
39
39
  ]
@@ -53,7 +53,7 @@ Feature: Report smells using simple JSON layout
53
53
  1
54
54
  ],
55
55
  "message": "has no descriptive comment",
56
- "documentation_link": "https://github.com/troessner/reek/blob/v5.6.0/docs/Irresponsible-Module.md"
56
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.0/docs/Irresponsible-Module.md"
57
57
  }
58
58
  ]
59
59
  """
@@ -182,8 +182,8 @@ Feature: Correctly formatted reports
182
182
  And it reports:
183
183
  """
184
184
  smelly.rb -- 2 warnings:
185
- [4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Method-Name.md]
186
- [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Variable-Name.md]
185
+ [4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Method-Name.md]
186
+ [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Variable-Name.md]
187
187
  """
188
188
 
189
189
  Examples:
@@ -209,8 +209,8 @@ Feature: Correctly formatted reports
209
209
  And it reports:
210
210
  """
211
211
  smelly.rb -- 2 warnings:
212
- UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Method-Name.md]
213
- UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Variable-Name.md]
212
+ UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Method-Name.md]
213
+ UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Variable-Name.md]
214
214
  """
215
215
 
216
216
  Examples:
@@ -25,7 +25,7 @@ Feature: Report smells using simple YAML layout
25
25
  smell_type: UncommunicativeMethodName
26
26
  source: smelly.rb
27
27
  name: x
28
- documentation_link: https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Method-Name.md
28
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Method-Name.md
29
29
  - context: Smelly#x
30
30
  lines:
31
31
  - 5
@@ -33,7 +33,7 @@ Feature: Report smells using simple YAML layout
33
33
  smell_type: UncommunicativeVariableName
34
34
  source: smelly.rb
35
35
  name: y
36
- documentation_link: https://github.com/troessner/reek/blob/v5.6.0/docs/Uncommunicative-Variable-Name.md
36
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.0/docs/Uncommunicative-Variable-Name.md
37
37
  """
38
38
 
39
39
  Scenario: Indicate smells and print them as yaml when using STDIN
@@ -48,5 +48,5 @@ Feature: Report smells using simple YAML layout
48
48
  lines:
49
49
  - 1
50
50
  message: has no descriptive comment
51
- documentation_link: https://github.com/troessner/reek/blob/v5.6.0/docs/Irresponsible-Module.md
51
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.0/docs/Irresponsible-Module.md
52
52
  """
@@ -2,6 +2,10 @@ When /^I run reek (.*)$/ do |args|
2
2
  reek(args)
3
3
  end
4
4
 
5
+ When 'I run the code climate reek runner' do
6
+ run_command_and_stop 'code_climate_reek'
7
+ end
8
+
5
9
  When /^I pass "([^\"]*)" to reek *(.*)$/ do |stdin, args|
6
10
  reek_with_pipe(stdin, args)
7
11
  end
@@ -93,6 +93,17 @@ module Reek
93
93
  module ShadowargNode
94
94
  include ArgNodeBase
95
95
  end
96
+
97
+ # Utility methods for :forward_args nodes.
98
+ # rubocop:disable Naming/ClassAndModuleCamelCase
99
+ module Forward_ArgsNode
100
+ include ArgNodeBase
101
+
102
+ def anonymous_splat?
103
+ true
104
+ end
105
+ end
106
+ # rubocop:enable Naming/ClassAndModuleCamelCase
96
107
  end
97
108
  end
98
109
  end
@@ -131,9 +131,9 @@ module Reek
131
131
  def set_alternative_formatter_options
132
132
  parser.separator "\nReport format:"
133
133
  parser.on(
134
- '-f', '--format FORMAT', [:html, :text, :yaml, :json, :xml, :code_climate],
134
+ '-f', '--format FORMAT', [:html, :text, :yaml, :json, :xml],
135
135
  'Report smells in the given format:',
136
- ' html', ' text (default)', ' yaml', ' json', ' xml', ' code_climate') do |opt|
136
+ ' html', ' text (default)', ' yaml', ' json', ' xml') do |opt|
137
137
  self.report_format = opt
138
138
  end
139
139
  end
@@ -6,6 +6,7 @@ require_relative 'smell_detectors/base_detector'
6
6
  require_relative 'errors/bad_detector_in_comment_error'
7
7
  require_relative 'errors/bad_detector_configuration_key_in_comment_error'
8
8
  require_relative 'errors/garbage_detector_configuration_in_comment_error'
9
+ require_relative 'errors/legacy_comment_separator_error'
9
10
 
10
11
  module Reek
11
12
  #
@@ -14,12 +15,10 @@ module Reek
14
15
  #
15
16
  class CodeComment
16
17
  CONFIGURATION_REGEX = /
17
- :reek: # prefix
18
- (\w+) # smell detector e.g.: UncommunicativeVariableName
19
- (
20
- \s*
21
- (\{.*?\}) # optional details in hash style e.g.: { max_methods: 30 }
22
- )?
18
+ :reek: # prefix
19
+ (\w+) # smell detector e.g.: UncommunicativeVariableName
20
+ (:?\s*) # separator
21
+ (\{.*?\})? # details in hash style e.g.: { max_methods: 30 }
23
22
  /x.freeze
24
23
  SANITIZE_REGEX = /(#|\n|\s)+/.freeze # Matches '#', newlines and > 1 whitespaces.
25
24
  DISABLE_DETECTOR_CONFIGURATION = '{ enabled: false }'
@@ -38,7 +37,8 @@ module Reek
38
37
  @source = source
39
38
  @config = Hash.new { |hash, key| hash[key] = {} }
40
39
 
41
- @original_comment.scan(CONFIGURATION_REGEX) do |detector_name, _option_string, options|
40
+ @original_comment.scan(CONFIGURATION_REGEX) do |detector_name, separator, options|
41
+ escalate_legacy_separator separator
42
42
  CodeCommentValidator.new(detector_name: detector_name,
43
43
  original_comment: original_comment,
44
44
  line: line,
@@ -64,6 +64,14 @@ module Reek
64
64
  strip
65
65
  end
66
66
 
67
+ def escalate_legacy_separator(separator)
68
+ return unless separator.start_with? ':'
69
+
70
+ raise Errors::LegacyCommentSeparatorError.new(original_comment: original_comment,
71
+ source: source,
72
+ line: line)
73
+ end
74
+
67
75
  #
68
76
  # A typical configuration via code comment looks like this:
69
77
  #
@@ -88,25 +96,22 @@ module Reek
88
96
  # @param source [String] path to source file or "string"
89
97
  # @param options [String] the configuration options as String for the detector that were
90
98
  # extracted from the original comment
91
- def initialize(detector_name:, original_comment:, line:, source:, options: {})
99
+ def initialize(detector_name:, original_comment:, line:, source:, options:)
92
100
  @detector_name = detector_name
93
101
  @original_comment = original_comment
94
102
  @line = line
95
103
  @source = source
96
104
  @options = options
97
- @detector_class = nil # We only know this one after our first initial checks
98
- @parsed_options = nil # We only know this one after our first initial checks
99
105
  end
100
106
 
101
107
  #
102
108
  # Method can raise the following errors:
109
+ # * Errors::LegacyCommentSeparatorError
103
110
  # * Errors::BadDetectorInCommentError
104
111
  # * Errors::GarbageDetectorConfigurationInCommentError
105
112
  # * Errors::BadDetectorConfigurationKeyInCommentError
106
113
  # @return [undefined]
107
114
  def validate
108
- escalate_bad_detector
109
- escalate_bad_detector_configuration
110
115
  escalate_unknown_configuration_key
111
116
  end
112
117
 
@@ -116,22 +121,12 @@ module Reek
116
121
  :original_comment,
117
122
  :line,
118
123
  :source,
119
- :options,
120
- :detector_class,
121
- :parsed_options
122
-
123
- def escalate_bad_detector
124
- return if SmellDetectors::BaseDetector.valid_detector?(detector_name)
124
+ :separator,
125
+ :options
125
126
 
126
- raise Errors::BadDetectorInCommentError.new(detector_name: detector_name,
127
- original_comment: original_comment,
128
- source: source,
129
- line: line)
130
- end
131
-
132
- def escalate_bad_detector_configuration
133
- @parsed_options = YAML.safe_load(options || CodeComment::DISABLE_DETECTOR_CONFIGURATION,
134
- permitted_classes: [Regexp])
127
+ def parsed_options
128
+ @parsed_options ||= YAML.safe_load(options || CodeComment::DISABLE_DETECTOR_CONFIGURATION,
129
+ permitted_classes: [Regexp])
135
130
  rescue Psych::SyntaxError
136
131
  raise Errors::GarbageDetectorConfigurationInCommentError.new(detector_name: detector_name,
137
132
  original_comment: original_comment,
@@ -140,8 +135,6 @@ module Reek
140
135
  end
141
136
 
142
137
  def escalate_unknown_configuration_key
143
- @detector_class = SmellDetectors::BaseDetector.to_detector(detector_name)
144
-
145
138
  return if given_keys_legit?
146
139
 
147
140
  raise Errors::BadDetectorConfigurationKeyInCommentError.new(detector_name: detector_name,
@@ -151,6 +144,20 @@ module Reek
151
144
  line: line)
152
145
  end
153
146
 
147
+ def detector_class
148
+ @detector_class ||= SmellDetectors::BaseDetector.to_detector(detector_name)
149
+ rescue NameError
150
+ raise Errors::BadDetectorInCommentError.new(detector_name: detector_name,
151
+ original_comment: original_comment,
152
+ source: source,
153
+ line: line)
154
+ end
155
+
156
+ # @return [Boolean] comment uses legacy three-colon format
157
+ def legacy_format?
158
+ separator.start_with? ':'
159
+ end
160
+
154
161
  # @return [Boolean] all keys in code comment are applicable to the detector in question
155
162
  def given_keys_legit?
156
163
  given_configuration_keys.subset? valid_detector_keys