rubocop-fourshark 0.2.2 → 0.3.0
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 +12 -0
- data/README.md +1 -0
- data/config/default.yml +14 -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: a8b84b9e99c1ff660e70c0dc9b6d600361f175fc7ea47be4c27ceb3ed46c879c
|
|
4
|
+
data.tar.gz: b80b447aff3ef40874166bef818eba3d18caff427b39e095c0ad15099804fc88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abdb30af6129f55a4c37b4f788dbee1528e28129642bcdaaaddc6164d4187d6fb4b0d8177b27b0b523c5749482951af32ebcbd54963651d8c4eb16bb73b4ab19
|
|
7
|
+
data.tar.gz: eb6678c1b97f140ef14c222e047b3dbf9c6342281b1a01818f176f9000246de2c95c7d919f1fda3e6cb83507367b88697d049effac922cfd5a3c7f521de323b7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [0.3.0] - 2026-06-19
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- `RSpec/Dialect` configured to forbid `subject`, `subject!` and `let!` in favor of a lazy `let`
|
|
6
|
+
|
|
7
|
+
## [0.2.3] - 2026-05-30
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `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
|
|
12
|
+
|
|
1
13
|
## [0.2.2] - 2026-05-30
|
|
2
14
|
|
|
3
15
|
### Fixed
|
data/README.md
CHANGED
|
@@ -82,6 +82,7 @@ Where a 4Shark cop supersedes or contradicts a stock cop, `config/default.yml` t
|
|
|
82
82
|
|
|
83
83
|
| Cop | Intent |
|
|
84
84
|
|---|---|
|
|
85
|
+
| `RSpec/Dialect` | Use `let`, never `subject` or `let!` — every `subject`/`subject!`/`let!` is flagged in favor of a lazy `let` (force creation in an explicit `before`, not with `let!`). The implicit subject behind `is_expected` is a different method and is left untouched. Stock cop, configured via `PreferredMethods`. |
|
|
85
86
|
| `RSpec/InverseOfMatcher` | Root models must assert `.inverse_of` in association specs; subclasses must not (it belongs to the parent). Scoped to `spec/models`. |
|
|
86
87
|
| `RSpec/OverwrittenLet` | A `let`/`let!` must not override one defined in an outer example group — shadowing makes it ambiguous which value applies. Scenario-specific `let`s, and the same name across sibling contexts, are fine. |
|
|
87
88
|
| `RSpec/ConditionalInLet` | A `let` must not contain conditional logic (`if`/`case`) — branch with separate `context`s instead. Ternaries are allowed. |
|
data/config/default.yml
CHANGED
|
@@ -50,6 +50,20 @@ Rails/OrderedMacros:
|
|
|
50
50
|
- 'app/models/**/*.rb'
|
|
51
51
|
VersionAdded: '0.2.0'
|
|
52
52
|
|
|
53
|
+
# Stock cop configured (not a 4Shark cop): map `subject`/`subject!`/`let!` to `let`
|
|
54
|
+
# so every `subject`, `subject!` and `let!` call is flagged in favor of a lazy
|
|
55
|
+
# `let` (force creation in an explicit `before`, not with `let!`). The implicit
|
|
56
|
+
# subject behind `is_expected` is a different method and is left untouched.
|
|
57
|
+
RSpec/Dialect:
|
|
58
|
+
Description: 'Use `let`, never `subject` or `let!` — objects are lazy `let`, forced in `before`.'
|
|
59
|
+
Enabled: true
|
|
60
|
+
PreferredMethods:
|
|
61
|
+
subject: let
|
|
62
|
+
subject!: let
|
|
63
|
+
let!: let
|
|
64
|
+
Include:
|
|
65
|
+
- 'spec/**/*_spec.rb'
|
|
66
|
+
|
|
53
67
|
RSpec/InverseOfMatcher:
|
|
54
68
|
Description: 'Root models must include `.inverse_of` in association specs; subclasses must not.'
|
|
55
69
|
Enabled: true
|
|
@@ -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)
|