sevencop 0.12.0 → 0.12.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: 2fc5d0adbf2ac9b5c3aa8ac43e1e375f82efa0906710ca38bd41c145c3a2bb41
4
- data.tar.gz: fd8b73bcc7ea73410c6634a3dbd5fcb3b38f3af26570482b22a2d05b2f42f6b3
3
+ metadata.gz: adcb3382c32455ca63651bf5593974e773cf00dfd0b3d14955541c6ce219c6c7
4
+ data.tar.gz: d6f50b292bb6f56c0f6ec36fc4271c931af4c1c46cef9b8c14a2505cf984f8ed
5
5
  SHA512:
6
- metadata.gz: 9024936b3ef659bae3242f40c793e72249edde9d6838f65edf570039077aad0abebe18ad8e2be52dad270ef4322bce2b841ffc33d42323a151b55b97d86cdc5a
7
- data.tar.gz: 19450fde029f352c3bba68362bb8a0db0c2ec01ceb319702565083768d281613b9bd123b34345f1096350a6bd3eab7efdb89079cd0f63526406f8d6b0b404b9c
6
+ metadata.gz: 552d6582fc4aa3baa550afd6d27477c822e4f098b470c0c038a36380c6ab74f9962a27e8f04be05cc60586be43376de1ec20a0a5b56587d71b24d3fa36e8e4cb
7
+ data.tar.gz: 05df622c8de515879b816077ba5fc40cd47858c1666390beac8d2ac29e86c1983921d5d8964b8b7de64106e789f3217032b6338a9988442207dbe5aeb62a8031
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.12.0)
4
+ sevencop (0.12.1)
5
5
  rubocop
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -49,7 +49,7 @@ All cops are `Enabled: false` by default.
49
49
 
50
50
  ### Sevencop/AutoloadOrdered
51
51
 
52
- Sort `autoload` in alphabetical order.
52
+ Sort `autoload` in alphabetical order within their section.
53
53
 
54
54
  ```ruby
55
55
  # bad
@@ -59,6 +59,13 @@ autoload :A, 'a'
59
59
  # good
60
60
  autoload :A, 'a'
61
61
  autoload :B, 'b'
62
+
63
+ # good
64
+ autoload :B, 'b'
65
+ autoload :D, 'd'
66
+
67
+ autoload :A, 'a'
68
+ autoload :C, 'a'
62
69
  ```
63
70
 
64
71
  ### Sevencop/BelongsToOptional
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Sevencop
6
- # Sort `autoload` in alphabetical order.
6
+ # Sort `autoload` in alphabetical order within their section.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -13,12 +13,19 @@ module RuboCop
13
13
  # # good
14
14
  # autoload :A, 'a'
15
15
  # autoload :B, 'b'
16
+ #
17
+ # # good
18
+ # autoload :A, 'a'
19
+ # autoload :D, 'd'
20
+ #
21
+ # autoload :B, 'b'
22
+ # autoload :C, 'c'
16
23
  class AutoloadOrdered < Base
17
24
  extend AutoCorrector
18
25
 
19
26
  include RangeHelp
20
27
 
21
- MSG = 'Sort `autoload` in alphabetical order.'
28
+ MSG = 'Sort `autoload` in alphabetical order within their section.'
22
29
 
23
30
  RESTRICT_ON_SEND = %i[
24
31
  autoload
@@ -52,11 +59,21 @@ module RuboCop
52
59
  node.left_siblings.find do |sibling|
53
60
  next unless sibling.send_type?
54
61
  next unless sibling.method?(:autoload)
62
+ next unless in_same_section?(sibling, node)
55
63
 
56
64
  node.first_argument.source < sibling.first_argument.source
57
65
  end
58
66
  end
59
67
 
68
+ # @param node1 [RuboCop::AST::SendNode]
69
+ # @param node2 [RuboCop::AST::SendNode]
70
+ # @return [Boolean]
71
+ def in_same_section?(node1, node2)
72
+ !node1.location.expression.with(
73
+ end_pos: node2.location.expression.end_pos
74
+ ).source.include?("\n\n")
75
+ end
76
+
60
77
  # @param range1 [Paresr::Source::Range]
61
78
  # @param range2 [Paresr::Source::Range]
62
79
  # @param corrector [RuboCop::AST::Corrector]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.12.0'
4
+ VERSION = '0.12.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura