rubocop-elegant 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60367f0f72f86e055af5d89d7120871578083d2812c4996e6fa027fb6d3b6cae
4
- data.tar.gz: 72077f0159044736a87ebb84c818c72d8280182d8fc6fcbf42f09d776d9c0775
3
+ metadata.gz: caefc6549542af9deff3c876e4f5820c45b1641a0006d797c05776123675a3d2
4
+ data.tar.gz: 59a23203e472ff8485a69e714f3085efa6a5a323381097f4fedb104df5363238
5
5
  SHA512:
6
- metadata.gz: 6f906093f750d1a9c5db831efb8ddc769d00a6449b62432a6ca645c6dc256f62944b9af2d45688f028cc5b242001ff9fa634a261ecbec928399233f2ba25b93e
7
- data.tar.gz: 6f1e7b0f76573edea8582d3607c4e5deaae6b8944bfa133ed58d121cf9a2d4afc38dc6eb26d87fb4a388ded4a1bb355c9d7e56da380448f70b33d7baa35ab9e5
6
+ metadata.gz: 553939a2d42896140b0b778faa879bdf4729a5411a60c22013b66313173d2b2785d5c7052bf68baf8ec2b223d450de7707393a73aa7a0a47bfa970283ae388ab
7
+ data.tar.gz: 8dbae33a180941efead52d5ed739f0f1ee349947769790d322a8ece2e224169ef79179fed362383f508bd05d5ab27b84935e3a552028b04a132c0077a3ee2a28
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gemspec
9
9
  gem 'minitest', '~>6.0', require: false
10
10
  gem 'minitest-reporters', '~>1.7', require: false
11
11
  gem 'rake', '~>13.2', require: false
12
- gem 'rdoc', '7.2.0', require: false
12
+ gem 'rdoc', '8.0.0', require: false
13
13
  gem 'rubocop', '~>1.74', require: false
14
14
  gem 'rubocop-minitest', '~>0.38', require: false
15
15
  gem 'rubocop-performance', '~>1.25', require: false
data/README.md CHANGED
@@ -43,7 +43,6 @@ Then, format your `.rubocop.yml` like this:
43
43
 
44
44
  ```yaml
45
45
  AllCops:
46
- EnabledByDefault: true
47
46
  NewCops: enable
48
47
  plugins:
49
48
  - rubocop-minitest
@@ -3,17 +3,21 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
- # Forbids a method from returning the literal +nil+ explicitly. The
7
- # cop flags two patterns: a +return nil+ statement anywhere inside
8
- # the method body, and a method whose tail expression is the literal
9
- # +nil+ (whether it stands alone or appears as the last statement of
10
- # a multi-statement body). Methods that omit +return+, use a bare
6
+ # Forbids returning the literal +nil+ explicitly. The cop flags two
7
+ # patterns: a +return nil+ statement anywhere inside the body, and a
8
+ # body whose tail expression is the literal +nil+ (whether it stands
9
+ # alone or appears as the last statement of a multi-statement body).
10
+ # Both patterns are checked inside method definitions and inside
11
+ # blocks, lambdas, and procs. Bodies that omit +return+, use a bare
11
12
  # +return+ keyword, or merely happen to evaluate to +nil+ through
12
13
  # control flow are not flagged.
13
14
  class RuboCop::Cop::Elegant::NoNilReturn < RuboCop::Cop::Base
14
15
  MSG = 'Method must not return nil explicitly'
15
16
  public_constant :MSG
16
17
 
18
+ SCOPES = %i[def defs block numblock].freeze
19
+ private_constant :SCOPES
20
+
17
21
  def on_def(node)
18
22
  check(node)
19
23
  end
@@ -22,6 +26,14 @@ class RuboCop::Cop::Elegant::NoNilReturn < RuboCop::Cop::Base
22
26
  check(node)
23
27
  end
24
28
 
29
+ def on_block(node)
30
+ check(node)
31
+ end
32
+
33
+ def on_numblock(node)
34
+ check(node)
35
+ end
36
+
25
37
  private
26
38
 
27
39
  def check(node)
@@ -32,7 +44,7 @@ class RuboCop::Cop::Elegant::NoNilReturn < RuboCop::Cop::Base
32
44
 
33
45
  def explicit(node)
34
46
  node.each_descendant(:return) do |ret|
35
- next unless ret.each_ancestor(:def, :defs).first.equal?(node)
47
+ next unless ret.each_ancestor(*SCOPES).first.equal?(node)
36
48
  add_offense(ret) if void?(ret)
37
49
  end
38
50
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
10
10
  s.required_ruby_version = '>=2.2'
11
11
  s.name = 'rubocop-elegant'
12
- s.version = '0.6.0'
12
+ s.version = '0.7.0'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'Set of custom RuboCop cops for elegant Ruby coding'
15
15
  s.description =
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-elegant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko