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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/rubocop/cop/rails/ordered_macros.rb +20 -4
- data/lib/rubocop/fourshark/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: 4f2644c550944bc0f11e7b4222b430e7cecc1ed4bf97f2650eb6f60e9f588a03
|
|
4
|
+
data.tar.gz: 5e2cbafe91b1b52c7d8de97d8d45c8a7e39a65921d3040bd07d48b5ccfbcd0e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
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
|
-
|
|
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)
|