rubocop-elegant 0.6.0 → 0.7.1

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: 49e44073640a27652772c3b1930072896e3fa04d47f81ec741a3f1941f9dcaca
4
+ data.tar.gz: 9d4de768ab46f9246ac3bf5554501e9c3472a821563cd3022a21a15be6f4e728
5
5
  SHA512:
6
- metadata.gz: 6f906093f750d1a9c5db831efb8ddc769d00a6449b62432a6ca645c6dc256f62944b9af2d45688f028cc5b242001ff9fa634a261ecbec928399233f2ba25b93e
7
- data.tar.gz: 6f1e7b0f76573edea8582d3607c4e5deaae6b8944bfa133ed58d121cf9a2d4afc38dc6eb26d87fb4a388ded4a1bb355c9d7e56da380448f70b33d7baa35ab9e5
6
+ metadata.gz: 60d73b3d6db72f172ecdf0950670221938cb2c08fb88a4f70183db7b324a8d31f5ad0e03d71502cae60df24dc24aaa12e53a805f44ac914117c49cd48df74fa6
7
+ data.tar.gz: 81c6c3e3bb185c60ebe83b82dc810325ab8dd5b93ea17b2853ff73dc20f0664296cdad793e369652a6947a38bba63dc945cfcf35cfc37d51622b81e5582add9f
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
@@ -103,6 +103,8 @@ Layout/EndOfLine:
103
103
  EnforcedStyle: lf
104
104
  Layout/ParameterAlignment:
105
105
  Enabled: false
106
+ Layout/ArrayAlignment:
107
+ EnforcedStyle: with_fixed_indentation
106
108
  Layout/LineLength:
107
109
  Max: 120
108
110
  Style/MultilineBlockChain:
@@ -18,11 +18,16 @@ class RuboCop::Cop::Elegant::GoodMethodName < RuboCop::Cop::Base
18
18
  private
19
19
 
20
20
  def check(node, name)
21
+ return unless identifier?(name)
21
22
  return if allowed?(name)
22
23
  return if match?(name)
23
24
  add_offense(node, message: format(MSG, name: name))
24
25
  end
25
26
 
27
+ def identifier?(name)
28
+ /\A[a-zA-Z_]/.match?(name)
29
+ end
30
+
26
31
  def match?(name)
27
32
  pattern.match?(name)
28
33
  end
@@ -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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko