reek 5.3.2 → 5.4.0

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
- SHA1:
3
- metadata.gz: 8e78fe759fff41903b35f67c62cd0a823258f46f
4
- data.tar.gz: 83e26bb16a5d03352a901311e1db029a5687bfe6
2
+ SHA256:
3
+ metadata.gz: 5c7a7193dd76b11cd88c3e3f031784a0bb54f3bcaa35a4e3b430dd550749facc
4
+ data.tar.gz: 0d2f96071b27301ebbd2b3ff82b8e1fbbde2aaf647125e3903d017074c4d061b
5
5
  SHA512:
6
- metadata.gz: a8db3fdbfd849bfd3e6e7f9f7fd13351ad92622d0aae71206960f70363077638e8de831bdb975c36c2515201c40dc294c6bf68ccc4ed12c3f78cac18b484f9c8
7
- data.tar.gz: 8ac99b438e7fe7e9dd72e53a30cb808f4bb9e0527bac80e9cf8ce95aef5e35783e91fce47786162b3db70248915e9c056fd2ef795c68f1f54a514addfd745a7e
6
+ metadata.gz: cc75695b17d58bf820bf6b874e747c3a7f81c43b0e8c80a33144118b1dbbbb0e0cd294ae386026937ee0799d0a7fa7cd12c65470bfd217faaa9c66dcbd22a03c
7
+ data.tar.gz: cb9bfef6dd9f799c2f2733b020952909010f489b1cf621d64828a2982cc64ea912211a7bf0f9e21fc1246ce4068edb5bb1571acdd16445df6ddebca2c3c9a84b
@@ -62,6 +62,9 @@ Metrics/LineLength:
62
62
  Metrics/ParameterLists:
63
63
  CountKeywordArgs: false
64
64
 
65
+ Naming/RescuedExceptionsVariableName:
66
+ PreferredName: error
67
+
65
68
  # These files do not test classes or modules
66
69
  RSpec/DescribeClass:
67
70
  Exclude:
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.4.0 (2019-04-24)
6
+
7
+ * (Philippe Bernery) Enable regex for directory directives.
8
+
5
9
  ## 5.3.2 (2019-03-22)
6
10
 
7
11
  * (troessner) Use Parser26.
@@ -190,3 +190,20 @@ We are following [semantic versioning](http://semver.org/).
190
190
  If you're working on a change that is breaking backwards-compatibility
191
191
  just go ahead with your pull request like normal. We'll discuss this then in
192
192
  the pull request and help you to point your pull request to the right branch.
193
+
194
+ ### Releasing Reek
195
+
196
+ In this example we assume the current version is 5.3.1 and you want to update to 5.3.2.
197
+
198
+ * Create a branch with a name like "prepare-v.5.3.2"
199
+ * Update the version in `lib/reek/version.rb`
200
+ * List all relevant changes in `CHANGELOG.md`
201
+ * Update the version number in our cucumber features, otherwise the build will fail. You can do this quite easily via
202
+ ```Bash
203
+ find features/ -type f -exec sed -i '' 's/v5.3.1/v5.3.2/g' {} +
204
+ ```
205
+ * Push the branch, create a pull request, have it reviewed and merged
206
+ * Pull the latest master and then do a
207
+ ```Bash
208
+ bundle exec rake release
209
+ ```
data/Gemfile CHANGED
@@ -12,8 +12,8 @@ group :development do
12
12
  gem 'kramdown-parser-gfm', '~> 1.0'
13
13
  gem 'rake', '~> 12.0'
14
14
  gem 'rspec', '~> 3.0'
15
- gem 'rspec-benchmark', '~> 0.4.0'
16
- gem 'rubocop', '~> 0.66.0'
15
+ gem 'rspec-benchmark', '~> 0.5.0'
16
+ gem 'rubocop', '~> 0.67.2'
17
17
  gem 'rubocop-rspec', '~> 1.32.0'
18
18
  gem 'simplecov', '~> 0.16.1'
19
19
  gem 'yard', '~> 0.9.5'
data/README.md CHANGED
@@ -309,12 +309,18 @@ detectors:
309
309
  # You can configure smells on a per-directory base.
310
310
  # E.g. the classic Rails case: controllers smell of NestedIterators (see /docs/Nested-Iterators.md) and
311
311
  # helpers smell of UtilityFunction (see docs/Utility-Function.md)
312
- # Note that we only allow configuration on a directory level, not a file level, so all paths have to point to directories.
312
+ #
313
+ # Note that we only allow configuration on a directory level, not a file level,
314
+ # so all paths have to point to directories.
315
+ # A Dir.glob pattern can be used.
313
316
  directories:
314
317
  "web_app/app/controllers":
315
318
  NestedIterators:
316
319
  enabled: false
317
- "web_app/app/helpers":
320
+ "web_app/app/helpers**:
321
+ UtilityFunction:
322
+ enabled: false
323
+ "web_app/lib/**/test/**":
318
324
  UtilityFunction:
319
325
  enabled: false
320
326
 
@@ -175,18 +175,13 @@ reek_of('DuplicateMethodCall')
175
175
  * `wiki-links` flag has been renamed to `documentation` flag
176
176
  * Reek assumes the default configuration file to be named ".reek.yml" and will ignore all other files. You can
177
177
  still use any name you want though by passing in a name via the `-c` flag
178
- * We have dropped the legacy code comment separator ":" at the end of a detector name. If you wanted to configure
179
- a smell detector via comment before this release you had to use g like this:
178
+ * We have dropped the legacy code comment separator `:` at the end of a detector name. Before this release,
179
+ to configure a smell detector via comment, you had to end with a colon after the detector name.
180
+ This syntax is disallowed with Reek 5 - now you have to drop the `:` at the end, like this:
180
181
 
181
- ```
182
- # :reek:UnusedPrivateMethod: { exclude: [ bravo ] }
183
- ```
184
-
185
- Mind the ":" at the end of "UnusedPrivateMethod". This syntax is disallowed with Reek 5 - you have to drop the ":"
186
- at the end now like this:
187
-
188
- ```
189
- # :reek:UnusedPrivateMethod { exclude: [ bravo ] }
182
+ ```diff
183
+ -# :reek:UnusedPrivateMethod: { exclude: [ bravo ] }
184
+ +# :reek:UnusedPrivateMethod { exclude: [ bravo ] }
190
185
  ```
191
186
 
192
187
  * We have dropped support for Ruby 2.1 and 2.2 since they are officially not supported by the Ruby core team anymore
@@ -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.3.2/docs/Code-Smells.md for a list of smells
46
+ Check out https://github.com/troessner/reek/blob/v5.4.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:
@@ -120,5 +120,5 @@ Feature: Reek can be controlled using command-line options
120
120
  UnusedPrivateMethod
121
121
  UtilityFunction
122
122
 
123
- Check out https://github.com/troessner/reek/blob/v5.3.2/docs/Code-Smells.md for a details on each detector
123
+ Check out https://github.com/troessner/reek/blob/v5.4.0/docs/Code-Smells.md for a details on each detector
124
124
  """
@@ -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.3.2/docs/Uncommunicative-Method-Name.md",
27
+ "documentation_link": "https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Uncommunicative-Variable-Name.md",
36
+ "documentation_link": "https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Irresponsible-Module.md"
56
+ "documentation_link": "https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Uncommunicative-Method-Name.md]
186
- [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.3.2/docs/Uncommunicative-Variable-Name.md]
185
+ [4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v5.4.0/docs/Uncommunicative-Method-Name.md]
186
+ [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Uncommunicative-Method-Name.md]
213
- UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.3.2/docs/Uncommunicative-Variable-Name.md]
212
+ UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/v5.4.0/docs/Uncommunicative-Method-Name.md]
213
+ UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Uncommunicative-Method-Name.md
28
+ documentation_link: https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Uncommunicative-Variable-Name.md
36
+ documentation_link: https://github.com/troessner/reek/blob/v5.4.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.3.2/docs/Irresponsible-Module.md
51
+ documentation_link: https://github.com/troessner/reek/blob/v5.4.0/docs/Irresponsible-Module.md
52
52
  """
@@ -53,10 +53,37 @@ 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(/#{Regexp.escape(pathname.to_s)}/) }.
56
+ select { |pathname| source_base_dir.to_s.match(glob_to_regexp(pathname.to_s)) }.
57
57
  max_by { |pathname| pathname.to_s.length }
58
58
  end
59
59
 
60
+ # Transform a glob pattern to a regexp.
61
+ #
62
+ # It changes:
63
+ # - /** to .*,
64
+ # - ** to .*,
65
+ # - * to [^\/]*.
66
+ #
67
+ # @quality :reek:FeatureEnvy
68
+ # @quality :reek:UtilityFunction
69
+ def glob_to_regexp(glob)
70
+ is_glob_pattern = glob.include?('*')
71
+
72
+ regexp = if is_glob_pattern
73
+ glob.
74
+ gsub(%r{/\*\*$}, '<<to_eol_wildcards>>').
75
+ gsub('**', '<<to_wildcards>>').
76
+ gsub('*', '[^/]*').
77
+ gsub('.', '\.').
78
+ gsub('<<to_eol_wildcards>>', '.*').
79
+ gsub('<<to_wildcards>>', '.*')
80
+ else
81
+ glob + '.*'
82
+ end
83
+
84
+ Regexp.new("^#{regexp}$", Regexp::IGNORECASE)
85
+ end
86
+
60
87
  def error_message_for_invalid_smell_type(klass)
61
88
  "You are trying to configure smell type #{klass} but we can't find one with that name.\n" \
62
89
  "Please make sure you spelled it right. (See 'docs/defaults.reek' in the Reek\n" \
@@ -93,8 +93,8 @@ module Reek
93
93
  wrap_exceptions do
94
94
  examine_tree
95
95
  end
96
- rescue StandardError => exception
97
- raise unless @error_handler.handle exception
96
+ rescue StandardError => error
97
+ raise unless @error_handler.handle error
98
98
 
99
99
  []
100
100
  end
@@ -8,6 +8,6 @@ module Reek
8
8
  # @public
9
9
  module Version
10
10
  # @public
11
- STRING = '5.3.2'
11
+ STRING = '5.4.0'
12
12
  end
13
13
  end
@@ -44,9 +44,12 @@ RSpec.describe Reek::Configuration::DirectoryDirectives do
44
44
  describe '#best_match_for' do
45
45
  let(:directives) do
46
46
  {
47
- Pathname.new('foo/bar/baz') => {},
48
- Pathname.new('foo/bar') => {},
49
- Pathname.new('bar/boo') => {}
47
+ Pathname.new('foo/bar/baz') => {},
48
+ Pathname.new('foo/bar') => {},
49
+ Pathname.new('bar/boo') => {},
50
+ Pathname.new('bar/**/test/**') => {},
51
+ Pathname.new('bar/**/spec/*') => {},
52
+ Pathname.new('bar/**/.spec/*') => {}
50
53
  }.extend(described_class)
51
54
  end
52
55
 
@@ -62,6 +65,42 @@ RSpec.describe Reek::Configuration::DirectoryDirectives do
62
65
  expect(hit.to_s).to eq('foo/bar')
63
66
  end
64
67
 
68
+ it 'returns the corresponding directory when source_base_dir matches the Dir.glob like pattern' do
69
+ source_base_dir = 'bar/something/test'
70
+ hit = directives.send :best_match_for, source_base_dir
71
+ expect(hit.to_s).to eq('bar/**/test/**')
72
+ end
73
+
74
+ it 'returns the corresponding directory when source_base_dir is a leaf of the Dir.glob like pattern' do
75
+ source_base_dir = 'bar/something/test/with/some/subdirectory'
76
+ hit = directives.send :best_match_for, source_base_dir
77
+ expect(hit.to_s).to eq('bar/**/test/**')
78
+ end
79
+
80
+ it 'returns the corresponding directory when source_base_dir is a direct leaf of the Dir.glob like pattern' do
81
+ source_base_dir = 'bar/something/spec/direct'
82
+ hit = directives.send :best_match_for, source_base_dir
83
+ expect(hit.to_s).to eq('bar/**/spec/*')
84
+ end
85
+
86
+ it 'returns the corresponding directory when source_base_dir contains a . character' do
87
+ source_base_dir = 'bar/something/.spec/direct'
88
+ hit = directives.send :best_match_for, source_base_dir
89
+ expect(hit.to_s).to eq('bar/**/.spec/*')
90
+ end
91
+
92
+ it 'does not match an arbitrary directory when source_base_dir contains a character that could match the .' do
93
+ source_base_dir = 'bar/something/aspec/direct'
94
+ hit = directives.send :best_match_for, source_base_dir
95
+ expect(hit.to_s).to eq('')
96
+ end
97
+
98
+ it 'returns nil when source_base_dir is a not direct leaf of the Dir.glob one-folder pattern' do
99
+ source_base_dir = 'bar/something/spec/with/some/subdirectory'
100
+ hit = directives.send :best_match_for, source_base_dir
101
+ expect(hit).to be_nil
102
+ end
103
+
65
104
  it 'returns nil we are on top of the tree and all other directories are below' do
66
105
  source_base_dir = 'foo'
67
106
  hit = directives.send :best_match_for, source_base_dir
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: 5.3.2
4
+ version: 5.4.0
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: 2019-03-22 00:00:00.000000000 Z
14
+ date: 2019-04-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: codeclimate-engine-rb
@@ -500,7 +500,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
500
500
  version: '0'
501
501
  requirements: []
502
502
  rubyforge_project:
503
- rubygems_version: 2.5.2.3
503
+ rubygems_version: 2.7.7
504
504
  signing_key:
505
505
  specification_version: 4
506
506
  summary: Code smell detector for Ruby