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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 400170a3fda22ccd3c629d58a47a9c142da2ebd38bd34c292fc702fc47e3fc51
4
- data.tar.gz: c82766e8b09239583a125b2d769e01a356330a83210e113dfdf43031a81a59ec
3
+ metadata.gz: caefc6549542af9deff3c876e4f5820c45b1641a0006d797c05776123675a3d2
4
+ data.tar.gz: 59a23203e472ff8485a69e714f3085efa6a5a323381097f4fedb104df5363238
5
5
  SHA512:
6
- metadata.gz: 1c2d09a8e4d0ffa82a2371396310bdd2d1cb0fa1308b87333f13edb30d9b3551a769309fe8e7a311806c221319c89b4be3160261115e92d9935ace180b878974
7
- data.tar.gz: 7200ec078d268fe5baadd7ba8627f3b20c705273444cdd7ad81b73d63009ffa93f9ae91be1fc267ae46b17b551519c5c93d4adfbabbfa228e7a0b78945dfaa18
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
data/config/default.yml CHANGED
@@ -50,7 +50,7 @@ Elegant/OneClassPerFile:
50
50
  Exclude:
51
51
  - '**/*Test.rb'
52
52
  - '**/test_*.rb'
53
- Elegant/IndentationLadder:
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 ladder" rule: when a line is indented further
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::IndentationLadder < RuboCop::Cop::Base
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 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
@@ -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/indentation_ladder'
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'
@@ -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.5.1'
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.5.1
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/indentation_ladder.rb
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