rubocop-fourshark 0.2.2 → 0.2.3

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: 6c048d884d1fbe9ba0f351c1bdf7e93e70410136084f72bb700dacb04d773cf8
4
- data.tar.gz: 2459ffac3431fce8bcba699eea337e61146dedac826ea854f262b96aa01139d7
3
+ metadata.gz: 4f2644c550944bc0f11e7b4222b430e7cecc1ed4bf97f2650eb6f60e9f588a03
4
+ data.tar.gz: 5e2cbafe91b1b52c7d8de97d8d45c8a7e39a65921d3040bd07d48b5ccfbcd0e4
5
5
  SHA512:
6
- metadata.gz: 76dbe2d05b1dc7471ac29d280a91d5bf9daa7a3da1888b7487b0715e36049d9883e72f15de51736c7ad35a8dac5bcca738797547e3f5549b8661b9034253ef26
7
- data.tar.gz: c09dcdc4fd7a190a916c9ce199116ad61fcfe2e5d5023139512f23da7418c780a1232b4489e2fb20982b417f93a264c162e2e6af1719255a4875a395c7da5898
6
+ metadata.gz: 7564a809a8d3e84320ac5de4e597cdc610c8568dbbc30eafcfa8b908955a38d022e68778fce30a35a8391a4576b98f965976e03234adb985c64dc26ae46c7ca8
7
+ data.tar.gz: fc105db26052f84221d17282382d867aa3d72a12d8a8b91d900061b84b01fe58d552e5365755af15f1a72df2036bb523574b28ff6311d2ffd14c0de5295e35dc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.2.3] - 2026-05-30
2
+
3
+ ### Fixed
4
+
5
+ - `Rails/OrderedMacros` sorts `:through` associations as a separate trailing group instead of interleaving them alphabetically — a `:through` association declared after its target association is no longer flagged
6
+
1
7
  ## [0.2.2] - 2026-05-30
2
8
 
3
9
  ### Fixed
@@ -9,9 +9,13 @@ module RuboCop
9
9
  # alphabetically by their first symbol argument. Checked per macro name:
10
10
  # all `belongs_to` sorted among themselves, all `validates` sorted, etc.
11
11
  #
12
- # Exceptions (lifecycle callbacks, dependency-ordered items, logical
13
- # grouping) are NOT modelled this is an experimental cop; if it flags
14
- # more legitimate cases than it helps, drop it.
12
+ # `:through` associations are sorted as a separate trailing group (a
13
+ # `:through` association must be declared after its target association),
14
+ # not interleaved with the regular declarations.
15
+ #
16
+ # Other exceptions (lifecycle callbacks, other dependency-ordered items)
17
+ # are NOT modelled — this is an experimental cop; if it flags more
18
+ # legitimate cases than it helps, drop it.
15
19
  #
16
20
  # @example
17
21
  # # bad
@@ -38,12 +42,24 @@ module RuboCop
38
42
  statements = body.begin_type? ? body.children : [body]
39
43
 
40
44
  MACROS.each do |macro|
41
- flag_unsorted(statements.select { |statement| macro_call?(statement, macro) })
45
+ calls = statements.select { |statement| macro_call?(statement, macro) }
46
+ regular, through = calls.partition { |call| !through_option?(call) }
47
+ flag_unsorted(regular)
48
+ flag_unsorted(through)
42
49
  end
43
50
  end
44
51
 
45
52
  private
46
53
 
54
+ # A `:through` association must be declared after its target association,
55
+ # so it forms a separate trailing group sorted among itself — never
56
+ # interleaved with (or compared against) the regular declarations.
57
+ def through_option?(node)
58
+ node.arguments.any? do |argument|
59
+ argument.hash_type? && argument.keys.any? { |key| key.value == :through }
60
+ end
61
+ end
62
+
47
63
  def flag_unsorted(calls)
48
64
  calls.each_cons(2) do |previous, current|
49
65
  previous_name = macro_name(previous)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Fourshark
5
- VERSION = '0.2.2'
5
+ VERSION = '0.2.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-fourshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Ribeiro