rubocop-elegant 0.5.1 → 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/config/default.yml +1 -1
- data/lib/rubocop/cop/elegant/{indentation_ladder.rb → monotonic_indents.rb} +2 -2
- data/lib/rubocop/cop/elegant/no_nil_return.rb +18 -6
- data/lib/rubocop/cop/elegant_cops.rb +1 -1
- data/rubocop-elegant.gemspec +1 -1
- metadata +2 -2
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
data/config/default.yml
CHANGED
|
@@ -50,7 +50,7 @@ Elegant/OneClassPerFile:
|
|
|
50
50
|
Exclude:
|
|
51
51
|
- '**/*Test.rb'
|
|
52
52
|
- '**/test_*.rb'
|
|
53
|
-
Elegant/
|
|
53
|
+
Elegant/MonotonicIndents:
|
|
54
54
|
Description: 'Requires the indentation step to be exactly two spaces when a line indents to the right of the previous one'
|
|
55
55
|
Enabled: true
|
|
56
56
|
VersionAdded: '0.1.0'
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
|
-
# Enforces the "indentation
|
|
6
|
+
# Enforces the "monotonic indentation" rule: when a line is indented further
|
|
7
7
|
# to the right than the previous non-empty line, the extra indentation
|
|
8
8
|
# must be exactly two spaces. Larger jumps (or odd ones, such as a single
|
|
9
9
|
# space or three spaces) break the visual rhythm of the code and make
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# de-indent by any amount, are not affected. Lines that belong to the
|
|
12
12
|
# body of a heredoc are ignored, because their whitespace is part of the
|
|
13
13
|
# literal value rather than program structure.
|
|
14
|
-
class RuboCop::Cop::Elegant::
|
|
14
|
+
class RuboCop::Cop::Elegant::MonotonicIndents < RuboCop::Cop::Base
|
|
15
15
|
MSG = 'Indentation step of %<step>d spaces is not allowed; use 2 spaces'
|
|
16
16
|
public_constant :MSG
|
|
17
17
|
|
|
@@ -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
|
|
@@ -8,7 +8,7 @@ module RuboCop::Cop::Elegant; end
|
|
|
8
8
|
require_relative 'elegant/class_in_module'
|
|
9
9
|
require_relative 'elegant/good_method_name'
|
|
10
10
|
require_relative 'elegant/good_variable_name'
|
|
11
|
-
require_relative 'elegant/
|
|
11
|
+
require_relative 'elegant/monotonic_indents'
|
|
12
12
|
require_relative 'elegant/no_class_in_module'
|
|
13
13
|
require_relative 'elegant/no_comments'
|
|
14
14
|
require_relative 'elegant/no_empty_lines_in_blocks'
|
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 =
|
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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -56,7 +56,7 @@ files:
|
|
|
56
56
|
- lib/rubocop/cop/elegant/class_in_module.rb
|
|
57
57
|
- lib/rubocop/cop/elegant/good_method_name.rb
|
|
58
58
|
- lib/rubocop/cop/elegant/good_variable_name.rb
|
|
59
|
-
- lib/rubocop/cop/elegant/
|
|
59
|
+
- lib/rubocop/cop/elegant/monotonic_indents.rb
|
|
60
60
|
- lib/rubocop/cop/elegant/no_class_in_module.rb
|
|
61
61
|
- lib/rubocop/cop/elegant/no_comments.rb
|
|
62
62
|
- lib/rubocop/cop/elegant/no_empty_lines_in_blocks.rb
|