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: 8136e162c37c297ad3e2eee09364841551f447b6854ada050b165d0286fda95d
4
- data.tar.gz: 595fd69b9114f9122920cf5c8f15a1cb6a43b22f4c31ab9665a11bf2411ff91d
3
+ metadata.gz: b4d888d565f892bba920e148aa967920188045908a193d44a7a1e672fc713a66
4
+ data.tar.gz: 70396bfc0679f49119a78b1e6e62d6b85492c308b93e31738c4148117a3ec6ec
5
5
  SHA512:
6
- metadata.gz: ab8b3c4ae74ac44dc4ee43af04cdb3854f8df847113e499dc2d429843c4276a34084316edc3c0aca41fd4174fdd6c3a508a642ec8dbc19302e6c015bc65ee16e
7
- data.tar.gz: 96347af9d20819c73c485e5a985702097ab5507ec86774ab144bf8f9fa54363461dc0a53f993429a6321e0e8fea6d0b4bcf244c9159b17a03fcf7f503b41ec75
6
+ metadata.gz: e41e772f903aae3b9d92278bd09d3568ccb189c56a5c0ffece2d0b79eb97b3e7f6f03142d04d2bef61265717b2253c4c825d9bb953d042b45bb8124aef30a99e
7
+ data.tar.gz: 82ef17c01433200a393bed3fa2c812addaeb059ffc99b76b9c85287b972618f32e2b62acdbbeabe014e61dff597a490519835ab8118f7a65ae9a2123e4418e48
@@ -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
@@ -4,4 +4,5 @@ Layout/OrderedMethods:
4
4
  EnforcedStyle: 'alphabetical'
5
5
  IgnoredMethods:
6
6
  - initialize
7
+ MethodQualifiers: []
7
8
  Signature: ~
@@ -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
- lambda do |corrector|
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.loc].each do |comment|
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 < Cop
33
- # TODO: Extending Cop is deprecated. Should extend Cop::Base.
34
- include IgnoredMethods
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
- siblings, _corrector = cache(start_node)
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
- # 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]
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?) && !ignored_method?(node.method_name)
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.11'
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.add_runtime_dependency 'rubocop', '>= 1.0'
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.11'
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: 2023-12-19 00:00:00.000000000 Z
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.2.33
75
+ rubygems_version: 3.5.11
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Checks that methods are ordered alphabetically.