rubocop-fourshark 0.7.0 → 0.7.1
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/README.md +0 -1
- data/config/default.yml +0 -11
- data/lib/rubocop/cop/factory_bot/association_in_factory.rb +5 -5
- data/lib/rubocop/cop/rails/bidirectional_association.rb +10 -10
- data/lib/rubocop/cop/rails/mandatory_inverse_of.rb +5 -5
- data/lib/rubocop/cop/rails/ordered_macros.rb +5 -5
- data/lib/rubocop/cop/rspec/inverse_of_matcher.rb +5 -5
- data/lib/rubocop/cop/rspec/overwritten_let.rb +10 -10
- 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: 582aea0059be3aad96e3b1017d419db000bb72f5a424684b4f90347de8359bc9
|
|
4
|
+
data.tar.gz: 685cb43ef7bbc16988a954b3821cc7a9a813bb98bf7777432da0960d4808d149
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1469cf2ff8d928ec8af532f2c09b0ca3fd35414c02105820ca519760d54d01ec177c172c79cf710a79e3314cafe4784c8c62f099bceb7b59753c51dc7ed5bb72
|
|
7
|
+
data.tar.gz: cf5dbfa5a4762d24715bb18b73224c92cb7251bced71e7003fa66d48d4d24be38bdcca4eb19e33e2d124e87dad74ec9a2cf53c890c69621dcefb2875aed33a07
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -76,7 +76,6 @@ Where a 4Shark cop supersedes or contradicts a stock cop, `config/default.yml` t
|
|
|
76
76
|
|
|
77
77
|
| Cop | Intent |
|
|
78
78
|
|---|---|
|
|
79
|
-
| `Style/ConditionalAssignment` | When a conditional decides a value, each branch assigns the variable. The cop's default (`assign_to_condition`) demands `x = if ... else ... end`, the one form the no-ternary convention rejects — converting a ternary would land straight on it. Ternaries are out of scope (`IncludeTernaryExpressions: false`): `Style/DisallowTernary` bans them, and this cop's ternary autocorrect only produces another ternary. Stock cop, configured via `EnforcedStyle`. |
|
|
80
79
|
| `Style/DisallowDelegate` | Flags automatic delegation (`delegate`, `delegate_missing_to`, `def_delegator(s)`, `DelegateClass`). A `delegate` line is a macro call, not a definition, so `grep 'def foo'` and jump-to-definition find nothing — the community name for the smell is Fowler's Middle Man. Write the method, or let the caller ask the object that knows. |
|
|
81
80
|
| `Style/DisallowSafeNavigation` | Flags safe navigation (`&.`). 4Shark rejects it — a `&.` chain silently swallows a `nil` that usually signals a real bug. Use an explicit conditional so the `nil` case is handled on purpose. |
|
|
82
81
|
| `Style/DisallowTernary` | Flags the ternary conditional (`cond ? a : b`). `?` and `:` are punctuation that already mean other things in Ruby (`valid?`, `:symbol`), and the ternary hides a branch inside an expression where skimming misses it. Use an explicit `if`/`else`. |
|
data/config/default.yml
CHANGED
|
@@ -22,17 +22,6 @@ Layout/MultilineMethodCallIndentation:
|
|
|
22
22
|
Naming/RescuedExceptionsVariableName:
|
|
23
23
|
PreferredName: exception
|
|
24
24
|
|
|
25
|
-
# Stock cop configured (not a 4Shark cop): when a conditional decides a value,
|
|
26
|
-
# each branch assigns the variable. The cop's default (`assign_to_condition`)
|
|
27
|
-
# demands `x = if ... else ... end`, the one form the 4Shark no-ternary
|
|
28
|
-
# convention rejects — converting a ternary would land straight on it.
|
|
29
|
-
# Ternaries are out of scope: `Style/DisallowTernary` bans them outright, and
|
|
30
|
-
# this cop's ternary autocorrect produces another ternary (`cond ? x = a : x = b`),
|
|
31
|
-
# which stays an offense that no autocorrect can clear.
|
|
32
|
-
Style/ConditionalAssignment:
|
|
33
|
-
EnforcedStyle: assign_inside_condition
|
|
34
|
-
IncludeTernaryExpressions: false
|
|
35
|
-
|
|
36
25
|
Style/DisallowDelegate:
|
|
37
26
|
Description: 'Do not use automatic delegation. Write the method explicitly.'
|
|
38
27
|
Enabled: true
|
|
@@ -35,11 +35,11 @@ module RuboCop
|
|
|
35
35
|
body = node.body
|
|
36
36
|
return unless body
|
|
37
37
|
|
|
38
|
-
if body.begin_type?
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
statements = if body.begin_type?
|
|
39
|
+
body.children
|
|
40
|
+
else
|
|
41
|
+
[body]
|
|
42
|
+
end
|
|
43
43
|
|
|
44
44
|
statements.each do |statement|
|
|
45
45
|
add_offense(statement.loc.selector) if association_call?(statement)
|
|
@@ -47,22 +47,22 @@ module RuboCop
|
|
|
47
47
|
|
|
48
48
|
opposite_content = File.read(opposite_model_path)
|
|
49
49
|
|
|
50
|
-
if inverse_name
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
expected_inverse = if inverse_name
|
|
51
|
+
inverse_name.to_s
|
|
52
|
+
else
|
|
53
|
+
camel_to_snake(model_name).split('/').last.pluralize
|
|
54
|
+
end
|
|
55
55
|
|
|
56
56
|
unless /(belongs_to|has_many|has_one)\s+:#{expected_inverse}/.match?(opposite_content)
|
|
57
57
|
add_global_offense("#{target_class} is missing opposite association for #{model_name}")
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
rescue StandardError => exception
|
|
61
|
-
if processed_source && processed_source.buffer
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
source_name = if processed_source && processed_source.buffer
|
|
62
|
+
processed_source.file_path
|
|
63
|
+
else
|
|
64
|
+
'unknown'
|
|
65
|
+
end
|
|
66
66
|
|
|
67
67
|
warn "Rails/BidirectionalAssociation failed on #{source_name}: #{exception.message}"
|
|
68
68
|
end
|
|
@@ -42,11 +42,11 @@ module RuboCop
|
|
|
42
42
|
|
|
43
43
|
add_offense(node.loc.selector) if missing_inverse_of
|
|
44
44
|
rescue StandardError => exception
|
|
45
|
-
if processed_source && processed_source.buffer
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
source_name = if processed_source && processed_source.buffer
|
|
46
|
+
processed_source.file_path
|
|
47
|
+
else
|
|
48
|
+
'unknown'
|
|
49
|
+
end
|
|
50
50
|
|
|
51
51
|
warn "Rails/MandatoryInverseOf failed on #{source_name}: #{exception.message}"
|
|
52
52
|
end
|
|
@@ -39,11 +39,11 @@ module RuboCop
|
|
|
39
39
|
body = node.body
|
|
40
40
|
return unless body
|
|
41
41
|
|
|
42
|
-
if body.begin_type?
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
statements = if body.begin_type?
|
|
43
|
+
body.children
|
|
44
|
+
else
|
|
45
|
+
[body]
|
|
46
|
+
end
|
|
47
47
|
|
|
48
48
|
MACROS.each do |macro|
|
|
49
49
|
calls = statements.select { |statement| macro_call?(statement, macro) }
|
|
@@ -47,11 +47,11 @@ module RuboCop
|
|
|
47
47
|
add_offense(node.loc.selector, message: MSG_FORBIDDEN_INVERSE) if chain_has_inverse_of?(node)
|
|
48
48
|
end
|
|
49
49
|
rescue StandardError => exception
|
|
50
|
-
if processed_source && processed_source.buffer
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
source_name = if processed_source && processed_source.buffer
|
|
51
|
+
processed_source.file_path
|
|
52
|
+
else
|
|
53
|
+
'unknown'
|
|
54
|
+
end
|
|
55
55
|
|
|
56
56
|
warn "RSpec/InverseOfMatcher failed on #{source_name}: #{exception.message}"
|
|
57
57
|
end
|
|
@@ -65,11 +65,11 @@ module RuboCop
|
|
|
65
65
|
body = group.body
|
|
66
66
|
return false unless body
|
|
67
67
|
|
|
68
|
-
if body.begin_type?
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
statements = if body.begin_type?
|
|
69
|
+
body.children
|
|
70
|
+
else
|
|
71
|
+
[body]
|
|
72
|
+
end
|
|
73
73
|
|
|
74
74
|
statements.any? { |statement| let_named?(statement, name) }
|
|
75
75
|
end
|
|
@@ -77,11 +77,11 @@ module RuboCop
|
|
|
77
77
|
def let_named?(statement, name)
|
|
78
78
|
return false unless statement.is_a?(::RuboCop::AST::Node)
|
|
79
79
|
|
|
80
|
-
if statement.respond_to?(:send_node)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
send = if statement.respond_to?(:send_node)
|
|
81
|
+
statement.send_node
|
|
82
|
+
else
|
|
83
|
+
statement
|
|
84
|
+
end
|
|
85
85
|
|
|
86
86
|
return false unless send.send_type?
|
|
87
87
|
return false unless LET_METHODS.include?(send.method_name) && send.receiver.nil?
|