rubocop-ordered_methods 0.11 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a73cfd25f43f431101b9822358b1c59180d41a56f170bf614d7ec0149f4f2c3e
|
4
|
+
data.tar.gz: 3c470834560d76327fc38f4163284ab4131214d8b944f0ffe34ede2e4164caab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2600cc2de26566766baf34796941c5056340e3bd9ccc1e9eb30ee73b6d57aa315a2f290e641c2128e9089956415fc0f79d0a0b8dd300df02af5a73b238037e9
|
7
|
+
data.tar.gz: f7c14e935cbfae83760f4724292db502f9bed264e3c77c1d99c51d5d3ca4e6c948b46fedc8dbbbd32906d721dcaf310597160b2bc148b4bee06725f1c59119d3
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.12] - 2024-07-16
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Add MethodQualifiers to the default config [#13](https://github.com/shanecav84/rubocop-ordered_methods/pull/13). Thanks, @Darhazer.
|
14
|
+
- Fix rubocop 1.65 compatability [#16](https://github.com/shanecav84/rubocop-ordered_methods/pull/16). Thanks, @Darhazer.
|
15
|
+
|
9
16
|
## [0.11] - 2023-12-19
|
10
17
|
|
11
18
|
### 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,22 +48,15 @@ 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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
message: "Methods should be sorted in #{cop_config['EnforcedStyle']} order."
|
66
|
-
)
|
53
|
+
consecutive_methods(start_node.children) do |previous, current|
|
54
|
+
next if ordered?(previous, current)
|
55
|
+
|
56
|
+
add_offense(current, message: message) do |corrector|
|
57
|
+
OrderedMethodsCorrector.new(
|
58
|
+
processed_source.ast_with_comments, start_node.children, cop_config
|
59
|
+
).correct(current, previous, corrector)
|
67
60
|
end
|
68
61
|
end
|
69
62
|
end
|
@@ -76,34 +69,6 @@ module RuboCop
|
|
76
69
|
(node.send_type? && node.bare_access_modifier?)
|
77
70
|
end
|
78
71
|
|
79
|
-
# rubocop:disable Metrics/MethodLength
|
80
|
-
# Cache to avoid traversing the AST multiple times
|
81
|
-
def cache(node)
|
82
|
-
@cache ||= Hash.new do |h, key|
|
83
|
-
h[key.hash] = begin
|
84
|
-
siblings = node.children
|
85
|
-
|
86
|
-
# Init the corrector with the cache to avoid traversing the AST in
|
87
|
-
# the corrector.
|
88
|
-
#
|
89
|
-
# We always init the @corrector, even if @options[:auto_correct] is
|
90
|
-
# nil, because `add_offense` always attempts correction. This
|
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]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
@cache[node.hash]
|
104
|
-
end
|
105
|
-
# rubocop:enable Metrics/MethodLength
|
106
|
-
|
107
72
|
# We disable `Style/ExplicitBlockArgument` for performance. See
|
108
73
|
# https://github.com/shanecav84/rubocop-ordered_methods/pull/5#pullrequestreview-562957146
|
109
74
|
# rubocop:disable Style/ExplicitBlockArgument
|
@@ -147,6 +112,10 @@ module RuboCop
|
|
147
112
|
end
|
148
113
|
end
|
149
114
|
|
115
|
+
def message
|
116
|
+
"Methods should be sorted in #{cop_config['EnforcedStyle']} order."
|
117
|
+
end
|
118
|
+
|
150
119
|
def ordered?(left_method, right_method)
|
151
120
|
comparison = COMPARISONS[cop_config['EnforcedStyle']]
|
152
121
|
raise Error, ERR_INVALID_COMPARISON if comparison.nil?
|
@@ -162,7 +131,7 @@ module RuboCop
|
|
162
131
|
end
|
163
132
|
|
164
133
|
def relevant_node?(node)
|
165
|
-
(node.defs_type? || node.def_type?) && !
|
134
|
+
(node.defs_type? || node.def_type?) && !allowed_method?(node.method_name)
|
166
135
|
end
|
167
136
|
end
|
168
137
|
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.12'
|
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.12'
|
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-07-16 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.
|