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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -1
- data/lib/rubocop/cop/sevencop/autoload_ordered.rb +19 -2
- data/lib/sevencop/version.rb +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: adcb3382c32455ca63651bf5593974e773cf00dfd0b3d14955541c6ce219c6c7
|
4
|
+
data.tar.gz: d6f50b292bb6f56c0f6ec36fc4271c931af4c1c46cef9b8c14a2505cf984f8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552d6582fc4aa3baa550afd6d27477c822e4f098b470c0c038a36380c6ab74f9962a27e8f04be05cc60586be43376de1ec20a0a5b56587d71b24d3fa36e8e4cb
|
7
|
+
data.tar.gz: 05df622c8de515879b816077ba5fc40cd47858c1666390beac8d2ac29e86c1983921d5d8964b8b7de64106e789f3217032b6338a9988442207dbe5aeb62a8031
|
data/Gemfile.lock
CHANGED
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]
|
data/lib/sevencop/version.rb
CHANGED