eager_eye 0.2.1 → 0.2.2
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/lib/eager_eye/detectors/loop_association.rb +46 -2
- data/lib/eager_eye/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: 6329285c3bdd39b8c99bbf665ffef121ac0dc5530b26b8e125d71ca04239a7a4
|
|
4
|
+
data.tar.gz: 78a608b043a06a58b22a54553d0c0b4ee459c2ee921405f01c5a216a77e801fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d985342e6d3bc4a09dab284b153807b4cda7a7dce898c4dca9ca3e0223e6fb2f575b369426a2a04c30f4d04b557749be8091ee4ed23de4c4a86522d410867ec
|
|
7
|
+
data.tar.gz: 18ba07590dce273befec6295f0ce05702241ee46a727c05825dd573d44e3019839655f0da14dc9674f5ded7d56b7ee21d802b6264a2b2a85c5f6859928c887da
|
|
@@ -49,7 +49,11 @@ module EagerEye
|
|
|
49
49
|
block_body = node.children[2]
|
|
50
50
|
next unless block_body
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
# Check if the collection already has includes
|
|
53
|
+
collection_node = node.children[0]
|
|
54
|
+
included_associations = extract_included_associations(collection_node)
|
|
55
|
+
|
|
56
|
+
find_association_calls(block_body, block_var, file_path, issues, included_associations)
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
issues
|
|
@@ -78,7 +82,44 @@ module EagerEye
|
|
|
78
82
|
first_arg.children[0]
|
|
79
83
|
end
|
|
80
84
|
|
|
81
|
-
def
|
|
85
|
+
def extract_included_associations(collection_node)
|
|
86
|
+
included = Set.new
|
|
87
|
+
return included unless collection_node&.type == :send
|
|
88
|
+
|
|
89
|
+
# Traverse through chained method calls to find includes()
|
|
90
|
+
current = collection_node
|
|
91
|
+
while current&.type == :send
|
|
92
|
+
method_name = current.children[1]
|
|
93
|
+
extract_includes_from_method(current, included) if method_name == :includes
|
|
94
|
+
|
|
95
|
+
current = current.children[0]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
included
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def extract_includes_from_method(method_node, included_set)
|
|
102
|
+
args = method_node.children[2..]
|
|
103
|
+
args&.each do |arg|
|
|
104
|
+
case arg&.type
|
|
105
|
+
when :sym
|
|
106
|
+
# includes(:product)
|
|
107
|
+
included_set.add(arg.children[0])
|
|
108
|
+
when :hash
|
|
109
|
+
# includes(product: :manufacturer)
|
|
110
|
+
extract_from_hash(arg, included_set)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def extract_from_hash(hash_node, included_set)
|
|
116
|
+
hash_node.children.each do |pair|
|
|
117
|
+
key = pair.children[0]
|
|
118
|
+
included_set.add(key.children[0]) if key&.type == :sym
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def find_association_calls(node, block_var, file_path, issues, included_associations = Set.new)
|
|
82
123
|
reported_associations = Set.new
|
|
83
124
|
|
|
84
125
|
traverse_ast(node) do |child|
|
|
@@ -91,6 +132,9 @@ module EagerEye
|
|
|
91
132
|
next unless direct_call_on_block_var?(receiver, block_var)
|
|
92
133
|
next unless likely_association?(method_name)
|
|
93
134
|
|
|
135
|
+
# Skip if association is already included
|
|
136
|
+
next if included_associations.include?(method_name)
|
|
137
|
+
|
|
94
138
|
# Avoid duplicate reports for same association on same line
|
|
95
139
|
report_key = "#{child.loc.line}:#{method_name}"
|
|
96
140
|
next if reported_associations.include?(report_key)
|
data/lib/eager_eye/version.rb
CHANGED