rubocop-ordered_methods 0.11 → 0.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d888d565f892bba920e148aa967920188045908a193d44a7a1e672fc713a66
|
4
|
+
data.tar.gz: 70396bfc0679f49119a78b1e6e62d6b85492c308b93e31738c4148117a3ec6ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e41e772f903aae3b9d92278bd09d3568ccb189c56a5c0ffece2d0b79eb97b3e7f6f03142d04d2bef61265717b2253c4c825d9bb953d042b45bb8124aef30a99e
|
7
|
+
data.tar.gz: 82ef17c01433200a393bed3fa2c812addaeb059ffc99b76b9c85287b972618f32e2b62acdbbeabe014e61dff597a490519835ab8118f7a65ae9a2123e4418e48
|
data/.github/workflows/main.yml
CHANGED
@@ -16,6 +16,8 @@ jobs:
|
|
16
16
|
- "3.0"
|
17
17
|
- "3.1"
|
18
18
|
- "3.2"
|
19
|
+
- "3.3"
|
20
|
+
- "3.4"
|
19
21
|
|
20
22
|
name: "Ruby ${{ matrix.ruby }}: run rspec"
|
21
23
|
steps:
|
@@ -35,6 +37,8 @@ jobs:
|
|
35
37
|
- "3.0"
|
36
38
|
- "3.1"
|
37
39
|
- "3.2"
|
40
|
+
- "3.3"
|
41
|
+
- "3.4"
|
38
42
|
|
39
43
|
name: "Ruby ${{ matrix.ruby }}: run rubocop"
|
40
44
|
steps:
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.13] - 2024-10-01
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Fix clobbering when consecutive nodes are with wrong order [#17](https://github.com/shanecav84/rubocop-ordered_methods/pull/17). Thanks, @Darhazer.
|
14
|
+
|
15
|
+
## [0.12] - 2024-07-16
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- Add MethodQualifiers to the default config [#13](https://github.com/shanecav84/rubocop-ordered_methods/pull/13). Thanks, @Darhazer.
|
20
|
+
- Fix rubocop 1.65 compatability [#16](https://github.com/shanecav84/rubocop-ordered_methods/pull/16). Thanks, @Darhazer.
|
21
|
+
|
9
22
|
## [0.11] - 2023-12-19
|
10
23
|
|
11
24
|
### Fixed
|
data/config/default.yml
CHANGED
@@ -17,14 +17,11 @@ module RuboCop
|
|
17
17
|
@cop_config = cop_config
|
18
18
|
end
|
19
19
|
|
20
|
-
def correct(node, previous_node)
|
20
|
+
def correct(node, previous_node, corrector)
|
21
21
|
AliasMethodOrderVerifier.verify!(node, previous_node)
|
22
22
|
current_range = join_surroundings(node)
|
23
23
|
previous_range = join_surroundings(previous_node)
|
24
|
-
|
25
|
-
corrector.replace(current_range, previous_range.source)
|
26
|
-
corrector.replace(previous_range, current_range.source)
|
27
|
-
end
|
24
|
+
corrector.swap(current_range, previous_range)
|
28
25
|
end
|
29
26
|
|
30
27
|
private
|
@@ -51,7 +48,7 @@ module RuboCop
|
|
51
48
|
# @param source_range Parser::Source::Range
|
52
49
|
# @return Parser::Source::Range
|
53
50
|
def join_comments(node, source_range)
|
54
|
-
@comment_locations[node
|
51
|
+
@comment_locations[node].each do |comment|
|
55
52
|
source_range = source_range.join(comment.loc.expression)
|
56
53
|
end
|
57
54
|
source_range
|
@@ -29,9 +29,9 @@ module RuboCop
|
|
29
29
|
#
|
30
30
|
# def c; end
|
31
31
|
# def d; end
|
32
|
-
class OrderedMethods <
|
33
|
-
|
34
|
-
include
|
32
|
+
class OrderedMethods < Base
|
33
|
+
extend AutoCorrector
|
34
|
+
include AllowedMethods
|
35
35
|
include RangeHelp
|
36
36
|
|
37
37
|
COMPARISONS = {
|
@@ -48,24 +48,9 @@ module RuboCop
|
|
48
48
|
node.first_argument.method_name
|
49
49
|
end
|
50
50
|
|
51
|
-
def autocorrect(node)
|
52
|
-
_siblings, corrector = cache(node)
|
53
|
-
corrector.correct(node, @previous_node)
|
54
|
-
end
|
55
|
-
|
56
51
|
def on_begin(node)
|
57
52
|
start_node = node.children.find(&:class_type?)&.children&.last || node
|
58
|
-
|
59
|
-
|
60
|
-
consecutive_methods(siblings) do |previous, current|
|
61
|
-
unless ordered?(previous, current)
|
62
|
-
@previous_node = previous
|
63
|
-
add_offense(
|
64
|
-
current,
|
65
|
-
message: "Methods should be sorted in #{cop_config['EnforcedStyle']} order."
|
66
|
-
)
|
67
|
-
end
|
68
|
-
end
|
53
|
+
check(start_node)
|
69
54
|
end
|
70
55
|
|
71
56
|
private
|
@@ -76,33 +61,21 @@ module RuboCop
|
|
76
61
|
(node.send_type? && node.bare_access_modifier?)
|
77
62
|
end
|
78
63
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# correction attempt is how RuboCop knows if the offense can be
|
92
|
-
# labeled "[Correctable]".
|
93
|
-
comment_locations = ::Parser::Source::Comment.associate_locations(
|
94
|
-
processed_source.ast,
|
95
|
-
processed_source.comments
|
96
|
-
)
|
97
|
-
corrector = OrderedMethodsCorrector.new(comment_locations, siblings, cop_config)
|
98
|
-
|
99
|
-
[siblings, corrector]
|
64
|
+
def check(start_node)
|
65
|
+
consecutive_methods(start_node.children) do |previous, current|
|
66
|
+
next if ordered?(previous, current)
|
67
|
+
|
68
|
+
add_offense(current, message: message) do |corrector|
|
69
|
+
next if part_of_ignored_node?(previous)
|
70
|
+
|
71
|
+
OrderedMethodsCorrector.new(
|
72
|
+
processed_source.ast_with_comments, start_node.children, cop_config
|
73
|
+
).correct(current, previous, corrector)
|
74
|
+
|
75
|
+
ignore_node(current)
|
100
76
|
end
|
101
77
|
end
|
102
|
-
|
103
|
-
@cache[node.hash]
|
104
78
|
end
|
105
|
-
# rubocop:enable Metrics/MethodLength
|
106
79
|
|
107
80
|
# We disable `Style/ExplicitBlockArgument` for performance. See
|
108
81
|
# https://github.com/shanecav84/rubocop-ordered_methods/pull/5#pullrequestreview-562957146
|
@@ -147,6 +120,10 @@ module RuboCop
|
|
147
120
|
end
|
148
121
|
end
|
149
122
|
|
123
|
+
def message
|
124
|
+
"Methods should be sorted in #{cop_config['EnforcedStyle']} order."
|
125
|
+
end
|
126
|
+
|
150
127
|
def ordered?(left_method, right_method)
|
151
128
|
comparison = COMPARISONS[cop_config['EnforcedStyle']]
|
152
129
|
raise Error, ERR_INVALID_COMPARISON if comparison.nil?
|
@@ -162,7 +139,7 @@ module RuboCop
|
|
162
139
|
end
|
163
140
|
|
164
141
|
def relevant_node?(node)
|
165
|
-
(node.defs_type? || node.def_type?) && !
|
142
|
+
(node.defs_type? || node.def_type?) && !allowed_method?(node.method_name)
|
166
143
|
end
|
167
144
|
end
|
168
145
|
end
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'rubocop-ordered_methods'
|
8
|
-
spec.version = '0.
|
8
|
+
spec.version = '0.13'
|
9
9
|
spec.authors = ['Shane Cavanaugh']
|
10
10
|
spec.email = ['shane@shanecav.net']
|
11
11
|
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
-
spec.
|
29
|
+
spec.add_dependency 'rubocop', '>= 1.0'
|
30
30
|
|
31
31
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-ordered_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.13'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Cavanaugh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.5.11
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Checks that methods are ordered alphabetically.
|