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 +4 -4
- data/Gemfile +1 -1
- data/README.md +0 -1
- data/lib/rubocop/cop/elegant/no_nil_return.rb +18 -6
- data/rubocop-elegant.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: caefc6549542af9deff3c876e4f5820c45b1641a0006d797c05776123675a3d2
|
|
4
|
+
data.tar.gz: 59a23203e472ff8485a69e714f3085efa6a5a323381097f4fedb104df5363238
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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', '
|
|
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
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
# Forbids
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
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(
|
|
47
|
+
next unless ret.each_ancestor(*SCOPES).first.equal?(node)
|
|
36
48
|
add_offense(ret) if void?(ret)
|
|
37
49
|
end
|
|
38
50
|
end
|
data/rubocop-elegant.gemspec
CHANGED
|
@@ -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.
|
|
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 =
|