reek 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf5a72026003b4d6b44ec51ba559efda3de62733061d6889596d8661ec24a12c
4
- data.tar.gz: 142319663079b82d851245cf6aa0e3a07ea5418426d21c25171d4fae1adc8549
3
+ metadata.gz: 107593e309020bb2745d630599f8bf33bde2c9f708877895465cd12360267f82
4
+ data.tar.gz: 61290a2608c069e4c5977720e5a1d99fe8d4e716dfaa8503c0491b226790a8a7
5
5
  SHA512:
6
- metadata.gz: 8a626593f82fcb8307629380ca25374b73d013561a3c2b0ffb2a7b5175997632b1f2925add8fb2d7ff1fe10d3a6343ee8998d5d167d45ce09888ea59c8c2ec6e
7
- data.tar.gz: f081217d15f01c31cc014ef935b359614ee412c8aa7c0fbbb22e40db0caa1dd0429b727935c02542ea1e73ca7023b15cb25d639d644e8ab3af42af33870f0de6
6
+ metadata.gz: '09025ee922070bcb0c415f82fd5591e6658610a661ae4fc24abb472f16df6c3ed222fcfd84f81500a1951cadfabfb33b5c9414e26164f67cc140699774a9d2e7'
7
+ data.tar.gz: 7b9af8e1a09c5722fbedd946389411dee5aa7a5b98f03f48330a9d7f76d4c126bf170fff94955af6abe7a3a6c2e4b1b046c1fd1b8e304ee678a0fbecb52919f1
@@ -130,3 +130,23 @@ Style/WordArray:
130
130
  Metrics/ClassLength:
131
131
  Exclude:
132
132
  - 'lib/reek/cli/options.rb'
133
+
134
+ # Activate new cops from RuboCop 0.80 - 0.83
135
+ Lint/RaiseException:
136
+ Enabled: true
137
+ Lint/StructNewOverride:
138
+ Enabled: true
139
+ Layout/EmptyLinesAroundAttributeAccessor:
140
+ Enabled: true
141
+ Layout/SpaceAroundMethodCallOperator:
142
+ Enabled: true
143
+ Style/ExponentialNotation:
144
+ Enabled: true
145
+ Style/HashEachMethods:
146
+ Enabled: true
147
+ Style/HashTransformKeys:
148
+ Enabled: true
149
+ Style/HashTransformValues:
150
+ Enabled: true
151
+ Style/SlicingWithRange:
152
+ Enabled: true
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## 6.0.1 (2020-05-26)
4
+
5
+ * (Maxim Pertsov) Handle absolute paths for directories correctly
6
+
3
7
  ## 6.0.0 (2020-03-30)
4
8
 
5
9
  * (mvz) Make codeclimate-engine-rb a development dependency
data/Gemfile CHANGED
@@ -8,15 +8,14 @@ group :development do
8
8
  gem 'aruba', '~> 1.0'
9
9
  gem 'codeclimate-engine-rb', '~> 0.4.0'
10
10
  gem 'cucumber', '~> 3.0'
11
- gem 'factory_bot', '~> 5.0', '!= 5.1.0'
12
11
  gem 'kramdown', '~> 2.1'
13
12
  gem 'kramdown-parser-gfm', '~> 1.0'
14
13
  gem 'rake', '~> 13.0'
15
14
  gem 'rspec', '~> 3.0'
16
15
  gem 'rspec-benchmark', '~> 0.6.0'
17
- gem 'rubocop', '~> 0.80.0'
16
+ gem 'rubocop', '~> 0.83.0'
18
17
  gem 'rubocop-performance', '~> 1.5.0'
19
- gem 'rubocop-rspec', '~> 1.38.1'
18
+ gem 'rubocop-rspec', '~> 1.39.0'
20
19
  gem 'simplecov', '~> 0.18.1'
21
20
  gem 'yard', '~> 0.9.5'
22
21
 
data/README.md CHANGED
@@ -286,7 +286,7 @@ detectors:
286
286
  # You can disable smells completely
287
287
  IrresponsibleModule:
288
288
  enabled: false
289
-
289
+
290
290
  # You can use filters to silence Reek warnings.
291
291
  # Either because you simply disagree with Reek (we are not the police) or
292
292
  # because you want to fix this at a later point in time.
@@ -294,7 +294,7 @@ detectors:
294
294
  exclude:
295
295
  - "MyWorker#self.class_method" # should be refactored
296
296
  - "AnotherWorker#instance_method" # should be refactored as well
297
-
297
+
298
298
  # A lot of smells allow fine tuning their configuration. You can look up all available options
299
299
  # in the corresponding smell documentation in /docs. In most cases you probably can just go
300
300
  # with the defaults as documented in defaults.reek.yml.
@@ -349,9 +349,14 @@ This configuration for instance:
349
349
  detectors:
350
350
  IrresponsibleModule:
351
351
  enabled: false
352
-
352
+
353
353
  TooManyStatements:
354
354
  max_statements: 5
355
+
356
+ directories:
357
+ "app/controllers":
358
+ TooManyStatements:
359
+ max_statements: 10
355
360
  ```
356
361
 
357
362
  translates to:
@@ -607,6 +612,7 @@ Be careful though, Reek does not merge your configuration entries, so if you alr
607
612
  Reek
608
613
  * [ruby-critic](https://github.com/whitesmith/rubycritic) - gem that wraps around static analysis gems such as Reek, [flay](https://github.com/seattlerb/flay) and [flog](https://github.com/seattlerb/flog)
609
614
  * [pronto-reek](https://github.com/mmozuras/pronto-reek) - Reek integration for [pronto](https://github.com/mmozuras/pronto)
615
+ * [action-reek](https://github.com/reviewdog/action-reek) - GitHub Action to run reek with [reviewdog](https://github.com/reviewdog/reviewdog) 🐶
610
616
 
611
617
  ### Misc
612
618
 
@@ -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/v6.0.0/docs/Code-Smells.md for a list of smells
46
+ Check out https://github.com/troessner/reek/blob/v6.0.1/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:
@@ -119,5 +119,5 @@ Feature: Reek can be controlled using command-line options
119
119
  UnusedPrivateMethod
120
120
  UtilityFunction
121
121
 
122
- Check out https://github.com/troessner/reek/blob/v6.0.0/docs/Code-Smells.md for a details on each detector
122
+ Check out https://github.com/troessner/reek/blob/v6.0.1/docs/Code-Smells.md for a details on each detector
123
123
  """
@@ -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/v6.0.0/docs/Uncommunicative-Method-Name.md",
27
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.1/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/v6.0.0/docs/Uncommunicative-Variable-Name.md",
36
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.1/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/v6.0.0/docs/Irresponsible-Module.md"
56
+ "documentation_link": "https://github.com/troessner/reek/blob/v6.0.1/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/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]
185
+ [4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v6.0.1/docs/Uncommunicative-Method-Name.md]
186
+ [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v6.0.1/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/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]
212
+ UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v6.0.1/docs/Uncommunicative-Method-Name.md]
213
+ UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v6.0.1/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/v6.0.0/docs/Uncommunicative-Method-Name.md
28
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.1/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/v6.0.0/docs/Uncommunicative-Variable-Name.md
36
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.1/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/v6.0.0/docs/Irresponsible-Module.md
51
+ documentation_link: https://github.com/troessner/reek/blob/v6.0.1/docs/Irresponsible-Module.md
52
52
  """
@@ -1,7 +1,6 @@
1
1
  require_relative '../../lib/reek'
2
2
  require_relative '../../lib/reek/cli/application'
3
3
  require 'aruba/cucumber'
4
- require 'active_support/core_ext/string/strip'
5
4
 
6
5
  begin
7
6
  require 'pry-byebug'
@@ -74,7 +74,7 @@ module Reek
74
74
  return unless configuration[DETECTORS_KEY]
75
75
 
76
76
  configuration[DETECTORS_KEY].tap do |detectors|
77
- detectors.keys.each do |detector|
77
+ detectors.each_key do |detector|
78
78
  convertible_attributes(detectors[detector]).each do |attribute|
79
79
  detectors[detector][attribute] = detectors[detector][attribute].map do |item|
80
80
  to_regex item
@@ -94,7 +94,7 @@ module Reek
94
94
  return unless configuration[DIRECTORIES_KEY]
95
95
 
96
96
  configuration[DIRECTORIES_KEY].tap do |directories|
97
- directories.keys.each do |directory|
97
+ directories.each_key do |directory|
98
98
  directories[directory].each do |detector, configuration|
99
99
  convertible_attributes(configuration).each do |attribute|
100
100
  directories[directory][detector][attribute] = directories[directory][detector][attribute].map do |item|
@@ -53,10 +53,16 @@ module Reek
53
53
  # @quality :reek:FeatureEnvy
54
54
  def best_match_for(source_base_dir)
55
55
  keys.
56
- select { |pathname| source_base_dir.to_s.match(glob_to_regexp(pathname.to_s)) }.
56
+ select do |pathname|
57
+ match?(source_base_dir, pathname) || match?(source_base_dir, pathname.expand_path)
58
+ end.
57
59
  max_by { |pathname| pathname.to_s.length }
58
60
  end
59
61
 
62
+ def match?(source_base_dir, pathname)
63
+ source_base_dir.to_s.match(glob_to_regexp(pathname.to_s))
64
+ end
65
+
60
66
  # Transform a glob pattern to a regexp.
61
67
  #
62
68
  # It changes:
@@ -19,6 +19,7 @@ module Reek
19
19
  # @quality :reek:TooManyMethods { max_methods: 18 }
20
20
  class BaseDetector
21
21
  attr_reader :config
22
+
22
23
  # The name of the config field that lists the names of code contexts
23
24
  # that should not be checked. Add this field to the config for each
24
25
  # smell that should ignore this code element.
@@ -43,8 +43,9 @@ module Reek
43
43
  raise ArgumentError, "The attribute '#{extra_keys.first}' is not available for comparison"
44
44
  end
45
45
 
46
+ # :reek:FeatureEnvy
46
47
  def common_parameters_equal?(other_parameters)
47
- smell_warning.parameters.slice(*other_parameters.keys) == other_parameters
48
+ smell_warning.parameters.values_at(*other_parameters.keys) == other_parameters.values
48
49
  end
49
50
 
50
51
  def common_attributes_equal?(attributes)
@@ -8,6 +8,6 @@ module Reek
8
8
  # @public
9
9
  module Version
10
10
  # @public
11
- STRING = '6.0.0'
11
+ STRING = '6.0.1'
12
12
  end
13
13
  end
@@ -3,7 +3,7 @@ require_lib 'reek/code_comment'
3
3
 
4
4
  RSpec.describe Reek::CodeComment do
5
5
  context 'with an empty comment' do
6
- let(:comment) { build(:code_comment, comment: '') }
6
+ let(:comment) { build_code_comment(comment: '') }
7
7
 
8
8
  it 'is not descriptive' do
9
9
  expect(comment).not_to be_descriptive
@@ -16,22 +16,22 @@ RSpec.describe Reek::CodeComment do
16
16
 
17
17
  describe '#descriptive' do
18
18
  it 'rejects an empty comment' do
19
- comment = build(:code_comment, comment: '#')
19
+ comment = build_code_comment(comment: '#')
20
20
  expect(comment).not_to be_descriptive
21
21
  end
22
22
 
23
23
  it 'rejects a 1-word comment' do
24
- comment = build(:code_comment, comment: "# alpha\n# ")
24
+ comment = build_code_comment(comment: "# alpha\n# ")
25
25
  expect(comment).not_to be_descriptive
26
26
  end
27
27
 
28
28
  it 'accepts a 2-word comment' do
29
- comment = build(:code_comment, comment: '# alpha bravo ')
29
+ comment = build_code_comment(comment: '# alpha bravo ')
30
30
  expect(comment).to be_descriptive
31
31
  end
32
32
 
33
33
  it 'accepts a multi-word comment' do
34
- comment = build(:code_comment, comment: "# alpha bravo \n# charlie \n # delta ")
34
+ comment = build_code_comment(comment: "# alpha bravo \n# charlie \n # delta ")
35
35
  expect(comment).to be_descriptive
36
36
  end
37
37
  end
@@ -39,8 +39,7 @@ RSpec.describe Reek::CodeComment do
39
39
  describe 'good comment config' do
40
40
  it 'parses hashed options' do
41
41
  comment = '# :reek:DuplicateMethodCall { max_calls: 3 }'
42
- config = build(:code_comment,
43
- comment: comment).config
42
+ config = build_code_comment(comment: comment).config
44
43
 
45
44
  expect(config).to include('DuplicateMethodCall')
46
45
  expect(config['DuplicateMethodCall']).to have_key 'max_calls'
@@ -52,7 +51,7 @@ RSpec.describe Reek::CodeComment do
52
51
  # :reek:DuplicateMethodCall { max_calls: 3 }
53
52
  # :reek:NestedIterators { enabled: true }
54
53
  RUBY
55
- config = build(:code_comment, comment: comment).config
54
+ config = build_code_comment(comment: comment).config
56
55
 
57
56
  expect(config).to include('DuplicateMethodCall', 'NestedIterators')
58
57
  expect(config['DuplicateMethodCall']['max_calls']).to eq 3
@@ -63,7 +62,7 @@ RSpec.describe Reek::CodeComment do
63
62
  comment = <<-RUBY
64
63
  #:reek:DuplicateMethodCall { max_calls: 3 } and :reek:NestedIterators { enabled: true }
65
64
  RUBY
66
- config = build(:code_comment, comment: comment).config
65
+ config = build_code_comment(comment: comment).config
67
66
 
68
67
  expect(config).to include('DuplicateMethodCall', 'NestedIterators')
69
68
  expect(config['DuplicateMethodCall']['max_calls']).to eq 3
@@ -73,7 +72,7 @@ RSpec.describe Reek::CodeComment do
73
72
 
74
73
  it 'parses multiple unhashed options on the same line' do
75
74
  comment = '# :reek:DuplicateMethodCall and :reek:NestedIterators'
76
- config = build(:code_comment, comment: comment).config
75
+ config = build_code_comment(comment: comment).config
77
76
 
78
77
  expect(config).to include('DuplicateMethodCall', 'NestedIterators')
79
78
  expect(config['DuplicateMethodCall']).to include('enabled')
@@ -84,7 +83,7 @@ RSpec.describe Reek::CodeComment do
84
83
 
85
84
  it 'disables the smell if no options are specifed' do
86
85
  comment = '# :reek:DuplicateMethodCall'
87
- config = build(:code_comment, comment: comment).config
86
+ config = build_code_comment(comment: comment).config
88
87
 
89
88
  expect(config).to include('DuplicateMethodCall')
90
89
  expect(config['DuplicateMethodCall']).to include('enabled')
@@ -93,14 +92,13 @@ RSpec.describe Reek::CodeComment do
93
92
 
94
93
  it 'does not disable the smell if options are specifed' do
95
94
  comment = '# :reek:DuplicateMethodCall { max_calls: 3 }'
96
- config = build(:code_comment, comment: comment).config
95
+ config = build_code_comment(comment: comment).config
97
96
 
98
97
  expect(config['DuplicateMethodCall']).not_to include('enabled')
99
98
  end
100
99
 
101
100
  it 'ignores smells after a space' do
102
- config = build(:code_comment,
103
- comment: '# :reek: DuplicateMethodCall').config
101
+ config = build_code_comment(comment: '# :reek: DuplicateMethodCall').config
104
102
  expect(config).not_to include('DuplicateMethodCall')
105
103
  end
106
104
 
@@ -111,7 +109,7 @@ RSpec.describe Reek::CodeComment do
111
109
  # :reek:NestedIterators { enabled: true }
112
110
  # comment
113
111
  RUBY
114
- comment = build(:code_comment, comment: original_comment)
112
+ comment = build_code_comment(comment: original_comment)
115
113
 
116
114
  expect(comment.send(:sanitized_comment)).to eq('Actual comment')
117
115
  end
@@ -122,8 +120,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
122
120
  context 'when the comment contains an unknown detector name' do
123
121
  it 'raises BadDetectorInCommentError' do
124
122
  expect do
125
- build(:code_comment,
126
- comment: '# :reek:DoesNotExist')
123
+ build_code_comment(comment: '# :reek:DoesNotExist')
127
124
  end.to raise_error(Reek::Errors::BadDetectorInCommentError)
128
125
  end
129
126
  end
@@ -132,7 +129,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
132
129
  it 'raises GarbageDetectorConfigurationInCommentError' do
133
130
  expect do
134
131
  comment = '# :reek:UncommunicativeMethodName { thats: a: bad: config }'
135
- build(:code_comment, comment: comment)
132
+ build_code_comment(comment: comment)
136
133
  end.to raise_error(Reek::Errors::GarbageDetectorConfigurationInCommentError)
137
134
  end
138
135
  end
@@ -140,7 +137,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
140
137
  context 'when the legacy comment format was used' do
141
138
  it 'raises LegacyCommentSeparatorError' do
142
139
  comment = '# :reek:DuplicateMethodCall:'
143
- expect { build(:code_comment, comment: comment) }.
140
+ expect { build_code_comment(comment: comment) }.
144
141
  to raise_error Reek::Errors::LegacyCommentSeparatorError
145
142
  end
146
143
  end
@@ -151,7 +148,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
151
148
  expect do
152
149
  # exclude -> exlude and enabled -> nabled
153
150
  comment = '# :reek:UncommunicativeMethodName { exlude: alfa, nabled: true }'
154
- build(:code_comment, comment: comment)
151
+ build_code_comment(comment: comment)
155
152
  end.to raise_error(Reek::Errors::BadDetectorConfigurationKeyInCommentError)
156
153
  end
157
154
  end
@@ -160,7 +157,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
160
157
  it 'does not raise' do
161
158
  expect do
162
159
  comment = '# :reek:UncommunicativeMethodName { exclude: alfa, enabled: true }'
163
- build(:code_comment, comment: comment)
160
+ build_code_comment(comment: comment)
164
161
  end.not_to raise_error
165
162
  end
166
163
  end
@@ -170,7 +167,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
170
167
  expect do
171
168
  # max_copies -> mx_copies and min_clump_size -> mn_clump_size
172
169
  comment = '# :reek:DataClump { mx_copies: 4, mn_clump_size: 3 }'
173
- build(:code_comment, comment: comment)
170
+ build_code_comment(comment: comment)
174
171
  end.to raise_error(Reek::Errors::BadDetectorConfigurationKeyInCommentError)
175
172
  end
176
173
  end
@@ -179,7 +176,7 @@ RSpec.describe Reek::CodeComment::CodeCommentValidator do
179
176
  it 'does not raise' do
180
177
  expect do
181
178
  comment = '# :reek:DataClump { max_copies: 4, min_clump_size: 3 }'
182
- build(:code_comment, comment: comment)
179
+ build_code_comment(comment: comment)
183
180
  end.not_to raise_error
184
181
  end
185
182
  end
@@ -89,6 +89,12 @@ RSpec.describe Reek::Configuration::DirectoryDirectives do
89
89
  expect(hit.to_s).to eq('bar/**/.spec/*')
90
90
  end
91
91
 
92
+ it 'returns the corresponding directory when source_base_dir is an absolute_path' do
93
+ source_base_dir = Pathname.new('foo/bar').expand_path
94
+ hit = directives.send :best_match_for, source_base_dir
95
+ expect(hit.to_s).to eq('foo/bar')
96
+ end
97
+
92
98
  it 'does not match an arbitrary directory when source_base_dir contains a character that could match the .' do
93
99
  source_base_dir = 'bar/something/aspec/direct'
94
100
  hit = directives.send :best_match_for, source_base_dir
@@ -3,9 +3,7 @@ require_lib 'reek/report/code_climate/code_climate_configuration'
3
3
 
4
4
  RSpec.describe Reek::Report::CodeClimateConfiguration do
5
5
  yml = described_class.load
6
- smell_types = Reek::SmellDetectors::BaseDetector.descendants.map do |descendant|
7
- descendant.name.demodulize
8
- end
6
+ smell_types = Reek::SmellDetectors::BaseDetector.descendants.map(&:smell_type)
9
7
 
10
8
  smell_types.each do |name|
11
9
  config = yml.fetch(name)
@@ -8,12 +8,12 @@ RSpec.describe Reek::Report::CodeClimateFingerprint do
8
8
  context 'when fingerprinting a warning with no parameters' do
9
9
  let(:expected_fingerprint) { 'e68badd29db51c92363a7c6a2438d722' }
10
10
  let(:warning) do
11
- build(:smell_warning,
12
- smell_type: 'UtilityFunction',
13
- context: 'alfa',
14
- message: "doesn't depend on instance state (maybe move it to another class?)",
15
- lines: lines,
16
- source: 'a/ruby/source/file.rb')
11
+ Reek::SmellWarning.new(
12
+ 'UtilityFunction',
13
+ context: 'alfa',
14
+ message: "doesn't depend on instance state (maybe move it to another class?)",
15
+ lines: lines,
16
+ source: 'a/ruby/source/file.rb')
17
17
  end
18
18
 
19
19
  context 'with code at a specific location' do
@@ -35,12 +35,12 @@ RSpec.describe Reek::Report::CodeClimateFingerprint do
35
35
 
36
36
  context 'when the fingerprint should not be computed' do
37
37
  let(:warning) do
38
- build(:smell_warning,
39
- smell_type: 'ManualDispatch',
40
- context: 'Alfa#bravo',
41
- message: 'manually dispatches method call',
42
- lines: [4],
43
- source: 'a/ruby/source/file.rb')
38
+ Reek::SmellWarning.new(
39
+ 'ManualDispatch',
40
+ context: 'Alfa#bravo',
41
+ message: 'manually dispatches method call',
42
+ lines: [4],
43
+ source: 'a/ruby/source/file.rb')
44
44
  end
45
45
 
46
46
  it 'returns nil' do
@@ -50,13 +50,13 @@ RSpec.describe Reek::Report::CodeClimateFingerprint do
50
50
 
51
51
  context 'when the smell warning has only identifying parameters' do
52
52
  let(:warning) do
53
- build(:smell_warning,
54
- smell_type: 'ClassVariable',
55
- context: 'Alfa',
56
- message: "declares the class variable '@@#{name}'",
57
- lines: [4],
58
- parameters: { name: "@@#{name}" },
59
- source: 'a/ruby/source/file.rb')
53
+ Reek::SmellWarning.new(
54
+ 'ClassVariable',
55
+ context: 'Alfa',
56
+ message: "declares the class variable '@@#{name}'",
57
+ lines: [4],
58
+ parameters: { name: "@@#{name}" },
59
+ source: 'a/ruby/source/file.rb')
60
60
  end
61
61
 
62
62
  context 'when the name is one thing' do
@@ -80,13 +80,13 @@ RSpec.describe Reek::Report::CodeClimateFingerprint do
80
80
 
81
81
  context 'when the smell warning has identifying and non-identifying parameters' do
82
82
  let(:warning) do
83
- build(:smell_warning,
84
- smell_type: 'DuplicateMethodCall',
85
- context: "Alfa##{name}",
86
- message: "calls '#{name}' #{count} times",
87
- lines: lines,
88
- parameters: { name: "@@#{name}", count: count },
89
- source: 'a/ruby/source/file.rb')
83
+ Reek::SmellWarning.new(
84
+ 'DuplicateMethodCall',
85
+ context: "Alfa##{name}",
86
+ message: "calls '#{name}' #{count} times",
87
+ lines: lines,
88
+ parameters: { name: "@@#{name}", count: count },
89
+ source: 'a/ruby/source/file.rb')
90
90
  end
91
91
 
92
92
  context 'when the parameters are provided' do
@@ -4,12 +4,12 @@ require_lib 'reek/report/code_climate/code_climate_formatter'
4
4
  RSpec.describe Reek::Report::CodeClimateFormatter do
5
5
  describe '#render' do
6
6
  let(:warning) do
7
- build(:smell_warning,
8
- smell_type: 'UtilityFunction',
9
- context: 'context foo',
10
- message: 'message bar',
11
- lines: [1, 2],
12
- source: 'a/ruby/source/file.rb')
7
+ Reek::SmellWarning.new(
8
+ 'UtilityFunction',
9
+ context: 'context foo',
10
+ message: 'message bar',
11
+ lines: [1, 2],
12
+ source: 'a/ruby/source/file.rb')
13
13
  end
14
14
  let(:rendered) { described_class.new(warning).render }
15
15
  let(:json) { JSON.parse rendered.chop }
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
2
2
  require_lib 'reek/report/location_formatter'
3
3
 
4
4
  RSpec.describe Reek::Report::BlankLocationFormatter do
5
- let(:warning) { build(:smell_warning, lines: [11, 9, 250, 100]) }
5
+ let(:warning) { build_smell_warning(lines: [11, 9, 250, 100]) }
6
6
 
7
7
  describe '.format' do
8
8
  it 'returns a blank String regardless of the warning' do
@@ -12,7 +12,7 @@ RSpec.describe Reek::Report::BlankLocationFormatter do
12
12
  end
13
13
 
14
14
  RSpec.describe Reek::Report::DefaultLocationFormatter do
15
- let(:warning) { build(:smell_warning, lines: [11, 9, 250, 100]) }
15
+ let(:warning) { build_smell_warning(lines: [11, 9, 250, 100]) }
16
16
 
17
17
  describe '.format' do
18
18
  it 'returns a prefix with sorted line numbers' do
@@ -22,7 +22,7 @@ RSpec.describe Reek::Report::DefaultLocationFormatter do
22
22
  end
23
23
 
24
24
  RSpec.describe Reek::Report::SingleLineLocationFormatter do
25
- let(:warning) { build(:smell_warning, lines: [11, 9, 250, 100]) }
25
+ let(:warning) { build_smell_warning(lines: [11, 9, 250, 100]) }
26
26
 
27
27
  describe '.format' do
28
28
  it 'returns the first line where the smell was found' do
@@ -5,13 +5,13 @@ require_lib 'reek/smell_detectors/duplicate_method_call'
5
5
  RSpec.describe Reek::SmellDetectors::BaseDetector do
6
6
  describe '.todo_configuration_for' do
7
7
  it 'returns exclusion configuration for the given smells' do
8
- smell = create(:smell_warning, smell_type: 'Foo', context: 'Foo#bar')
8
+ smell = build_smell_warning(smell_type: 'Foo', context: 'Foo#bar')
9
9
  result = described_class.todo_configuration_for([smell])
10
10
  expect(result).to eq('BaseDetector' => { 'exclude' => ['Foo#bar'] })
11
11
  end
12
12
 
13
13
  it 'merges identical contexts' do
14
- smell = create(:smell_warning, smell_type: 'Foo', context: 'Foo#bar')
14
+ smell = build_smell_warning(smell_type: 'Foo', context: 'Foo#bar')
15
15
  result = described_class.todo_configuration_for([smell, smell])
16
16
  expect(result).to eq('BaseDetector' => { 'exclude' => ['Foo#bar'] })
17
17
  end
@@ -20,7 +20,7 @@ RSpec.describe Reek::SmellDetectors::BaseDetector do
20
20
  let(:subclass) { Reek::SmellDetectors::TooManyStatements }
21
21
 
22
22
  it 'includes default exclusions' do
23
- smell = create(:smell_warning, smell_type: 'TooManyStatements', context: 'Foo#bar')
23
+ smell = build_smell_warning(smell_type: 'TooManyStatements', context: 'Foo#bar')
24
24
  result = subclass.todo_configuration_for([smell])
25
25
 
26
26
  aggregate_failures do
@@ -24,23 +24,23 @@ RSpec.describe Reek::SmellWarning do
24
24
  end
25
25
 
26
26
  context 'when smells differ only by detector' do
27
- let(:first) { build(:smell_warning, smell_type: 'DuplicateMethodCall') }
28
- let(:second) { build(:smell_warning, smell_type: 'FeatureEnvy') }
27
+ let(:first) { build_smell_warning(smell_type: 'DuplicateMethodCall') }
28
+ let(:second) { build_smell_warning(smell_type: 'FeatureEnvy') }
29
29
 
30
30
  it_behaves_like 'first sorts ahead of second'
31
31
  end
32
32
 
33
33
  context 'when smells differ only by lines' do
34
- let(:first) { build(:smell_warning, smell_type: 'FeatureEnvy', lines: [2]) }
35
- let(:second) { build(:smell_warning, smell_type: 'FeatureEnvy', lines: [3]) }
34
+ let(:first) { build_smell_warning(smell_type: 'FeatureEnvy', lines: [2]) }
35
+ let(:second) { build_smell_warning(smell_type: 'FeatureEnvy', lines: [3]) }
36
36
 
37
37
  it_behaves_like 'first sorts ahead of second'
38
38
  end
39
39
 
40
40
  context 'when smells differ only by context' do
41
- let(:first) { build(:smell_warning, smell_type: 'DuplicateMethodCall', context: 'first') }
41
+ let(:first) { build_smell_warning(smell_type: 'DuplicateMethodCall', context: 'first') }
42
42
  let(:second) do
43
- build(:smell_warning, smell_type: 'DuplicateMethodCall', context: 'second')
43
+ build_smell_warning(smell_type: 'DuplicateMethodCall', context: 'second')
44
44
  end
45
45
 
46
46
  it_behaves_like 'first sorts ahead of second'
@@ -48,11 +48,11 @@ RSpec.describe Reek::SmellWarning do
48
48
 
49
49
  context 'when smells differ only by message' do
50
50
  let(:first) do
51
- build(:smell_warning, smell_type: 'DuplicateMethodCall',
51
+ build_smell_warning(smell_type: 'DuplicateMethodCall',
52
52
  context: 'ctx', message: 'first message')
53
53
  end
54
54
  let(:second) do
55
- build(:smell_warning, smell_type: 'DuplicateMethodCall',
55
+ build_smell_warning(smell_type: 'DuplicateMethodCall',
56
56
  context: 'ctx', message: 'second message')
57
57
  end
58
58
 
@@ -61,10 +61,10 @@ RSpec.describe Reek::SmellWarning do
61
61
 
62
62
  context 'when smells differ by name and message' do
63
63
  let(:first) do
64
- build(:smell_warning, smell_type: 'FeatureEnvy', message: 'second message')
64
+ build_smell_warning(smell_type: 'FeatureEnvy', message: 'second message')
65
65
  end
66
66
  let(:second) do
67
- build(:smell_warning, smell_type: 'UtilityFunction', message: 'first message')
67
+ build_smell_warning(smell_type: 'UtilityFunction', message: 'first message')
68
68
  end
69
69
 
70
70
  it_behaves_like 'first sorts ahead of second'
@@ -72,13 +72,13 @@ RSpec.describe Reek::SmellWarning do
72
72
 
73
73
  context 'when smells differ everywhere' do
74
74
  let(:first) do
75
- build(:smell_warning, smell_type: 'DuplicateMethodCall',
75
+ build_smell_warning(smell_type: 'DuplicateMethodCall',
76
76
  context: 'Dirty#a',
77
77
  message: 'calls @s.title twice')
78
78
  end
79
79
 
80
80
  let(:second) do
81
- build(:smell_warning, smell_type: 'UncommunicativeVariableName',
81
+ build_smell_warning(smell_type: 'UncommunicativeVariableName',
82
82
  context: 'Dirty',
83
83
  message: "has the variable name '@s'")
84
84
  end
@@ -1,7 +1,6 @@
1
1
  require 'pathname'
2
2
  require_relative '../../spec_helper'
3
3
  require_lib 'reek/spec'
4
- require 'active_support/core_ext/hash/except'
5
4
 
6
5
  RSpec.describe Reek::Spec::ShouldReekOf do
7
6
  describe 'smell type selection' do
@@ -40,7 +40,7 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
40
40
  end
41
41
 
42
42
  context 'with 1 non-matching smell' do
43
- let(:smells) { [build(:smell_warning, smell_type: 'ControlParameter')] }
43
+ let(:smells) { [build_smell_warning(smell_type: 'ControlParameter')] }
44
44
 
45
45
  it_behaves_like 'no match'
46
46
  end
@@ -48,8 +48,8 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
48
48
  context 'with 2 non-matching smells' do
49
49
  let(:smells) do
50
50
  [
51
- build(:smell_warning, smell_type: 'ControlParameter'),
52
- build(:smell_warning, smell_type: 'FeatureEnvy')
51
+ build_smell_warning(smell_type: 'ControlParameter'),
52
+ build_smell_warning(smell_type: 'FeatureEnvy')
53
53
  ]
54
54
  end
55
55
 
@@ -59,8 +59,8 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
59
59
  context 'with 1 non-matching and 1 matching smell' do
60
60
  let(:smells) do
61
61
  [
62
- build(:smell_warning, smell_type: 'ControlParameter'),
63
- build(:smell_warning, smell_type: expected_smell_type.to_s,
62
+ build_smell_warning(smell_type: 'ControlParameter'),
63
+ build_smell_warning(smell_type: expected_smell_type.to_s,
64
64
  message: "message mentioning #{expected_context_name}")
65
65
  ]
66
66
  end
@@ -70,7 +70,7 @@ RSpec.describe Reek::Spec::ShouldReekOnlyOf do
70
70
 
71
71
  context 'with 1 matching smell' do
72
72
  let(:smells) do
73
- [build(:smell_warning, smell_type: expected_smell_type.to_s,
73
+ [build_smell_warning(smell_type: expected_smell_type.to_s,
74
74
  message: "message mentioning #{expected_context_name}")]
75
75
  end
76
76
 
@@ -3,7 +3,7 @@ require_lib 'reek/spec/smell_matcher'
3
3
 
4
4
  RSpec.describe Reek::Spec::SmellMatcher do
5
5
  let(:smell_warning) do
6
- build(:smell_warning, smell_type: 'UncommunicativeVariableName',
6
+ build_smell_warning(smell_type: 'UncommunicativeVariableName',
7
7
  message: "has the variable name '@s'",
8
8
  parameters: { test: 'something' })
9
9
  end
@@ -1,6 +1,5 @@
1
1
  require 'pathname'
2
2
  require 'timeout'
3
- require 'active_support/core_ext/string/strip'
4
3
  require 'rspec-benchmark'
5
4
  require_relative '../lib/reek'
6
5
  require_relative '../lib/reek/spec'
@@ -14,9 +13,6 @@ begin
14
13
  rescue LoadError # rubocop:disable Lint/SuppressedException
15
14
  end
16
15
 
17
- require 'factory_bot'
18
- FactoryBot.find_definitions
19
-
20
16
  # Simple helpers for our specs.
21
17
  module Helpers
22
18
  def test_configuration_for(config)
@@ -70,12 +66,29 @@ module Helpers
70
66
  @klass_map ||= Reek::AST::ASTNodeClassMap.new
71
67
  @klass_map.klass_for(type).new(type, children)
72
68
  end
69
+
70
+ def build_smell_warning(smell_type: 'FeatureEnvy',
71
+ context: 'self',
72
+ lines: [42],
73
+ message: 'smell warning message',
74
+ source: 'dummy_file',
75
+ parameters: {})
76
+ Reek::SmellWarning.new(smell_type,
77
+ context: context,
78
+ lines: lines,
79
+ message: message,
80
+ source: source,
81
+ parameters: parameters)
82
+ end
83
+
84
+ def build_code_comment(comment: '', line: 1, source: 'string')
85
+ Reek::CodeComment.new(comment: comment, line: line, source: source)
86
+ end
73
87
  end
74
88
 
75
89
  RSpec.configure do |config|
76
90
  config.filter_run :focus
77
91
  config.run_all_when_everything_filtered = true
78
- config.include FactoryBot::Syntax::Methods
79
92
  config.include Helpers
80
93
  config.include RSpec::Benchmark::Matchers
81
94
  config.example_status_persistence_file_path = 'spec/examples.txt'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-03-30 00:00:00.000000000 Z
14
+ date: 2020-05-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: kwalify
@@ -31,28 +31,28 @@ dependencies:
31
31
  name: parser
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '2.8'
37
34
  - - ">="
38
35
  - !ruby/object:Gem::Version
39
36
  version: 2.5.0.0
40
37
  - - "!="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 2.5.1.1
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.8'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "<"
48
- - !ruby/object:Gem::Version
49
- version: '2.8'
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: 2.5.0.0
53
50
  - - "!="
54
51
  - !ruby/object:Gem::Version
55
52
  version: 2.5.1.1
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.8'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: psych
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -372,7 +372,6 @@ files:
372
372
  - samples/source_with_non_ruby_files/gibberish
373
373
  - samples/source_with_non_ruby_files/python_source.py
374
374
  - samples/source_with_non_ruby_files/ruby.rb
375
- - spec/factories/factories.rb
376
375
  - spec/performance/reek/smell_detectors/runtime_speed_spec.rb
377
376
  - spec/quality/documentation_spec.rb
378
377
  - spec/quality/reek_source_spec.rb
@@ -486,8 +485,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
486
485
  - !ruby/object:Gem::Version
487
486
  version: '0'
488
487
  requirements: []
489
- rubyforge_project:
490
- rubygems_version: 2.7.7
488
+ rubygems_version: 3.0.3
491
489
  signing_key:
492
490
  specification_version: 4
493
491
  summary: Code smell detector for Ruby
@@ -1,37 +0,0 @@
1
- require_relative '../../lib/reek/smell_detectors'
2
- require_relative '../../lib/reek/smell_detectors/base_detector'
3
- require_relative '../../lib/reek/smell_warning'
4
- require_relative '../../lib/reek/cli/options'
5
-
6
- FactoryBot.define do
7
- factory :smell_warning, class: 'Reek::SmellWarning' do
8
- skip_create
9
-
10
- smell_type { 'FeatureEnvy' }
11
- source { 'dummy_file' }
12
- lines { [42] }
13
- message { 'smell warning message' }
14
- parameters { {} }
15
- context { 'self' }
16
-
17
- initialize_with do
18
- new(smell_type,
19
- source: source,
20
- context: context,
21
- lines: lines,
22
- message: message,
23
- parameters: parameters)
24
- end
25
- end
26
-
27
- factory :code_comment, class: 'Reek::CodeComment' do
28
- comment { '' }
29
- line { 1 }
30
- source { 'string' }
31
- initialize_with do
32
- new comment: comment,
33
- line: line,
34
- source: source
35
- end
36
- end
37
- end