eager_eye 1.1.4 → 1.1.6

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: 6ae532397830e96202bc3a3d10dc231570f4912d5df67085783123fbb2ebba5e
4
- data.tar.gz: ddc5a6971c2c65c73260c59ff8b6acfd52711a2e1ce1d43ea8c44895be729016
3
+ metadata.gz: 8770de7a3e968ddce30789d077c4ffd949b04438a494d4053a35af891343cb2b
4
+ data.tar.gz: 1e3b4e5b797527635983a43c888691eca6ebab70d1985af4bcca0f3f0f1f52f2
5
5
  SHA512:
6
- metadata.gz: fa15940b451ebd100e908b4f9931c8f40708f9566451a0f1edb8a65c70fee15f832bd30d91d49f54c9b2f0ebe63cbdf2f5dbabfb5f7894db23d1a2f35c1e95c5
7
- data.tar.gz: 80ea91965317596061db8a38cce960ac4f573a4c887de7a2fe88b7a4ad7e43f35f2b18b6716a6487e256e1ed292e8f79c437249e9dbef6cccded54397a7ecf8c
6
+ metadata.gz: bbd7f4209da48c0a7312fde0c2bb433999c45febcc9f87a4eca72ba0ce4b0ace89e6a4e530f4cd569746d0f18bd98094c9b262072c71069ad2313a5d83c176d6
7
+ data.tar.gz: 7f8701b944dbaff58f7d9aa9151da69a81dbf1ad206c8dfd7c5c9877d1c0143a19bb7e2601e010c1fae6c95b7db0f81fbf5385c6aaa368db588f516a4c0184de
data/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.6] - 2026-01-09
11
+
12
+ ### Fixed
13
+
14
+ - **CustomMethodQuery False Positive** - Skip `Hash#keys` and `Hash#values` chains
15
+ - `hash.keys.first`, `hash.values.last` no longer flagged as ActiveRecord queries
16
+ - Recognizes `keys` and `values` as Array-returning methods
17
+
18
+ ## [1.1.5] - 2026-01-06
19
+
20
+ ### Changed
21
+
22
+ - **PluckToArray Severity** - Lower severity to `info` for small collections
23
+ - `tags`, `settings`, `roles`, `permissions`, `options` etc. now `info` level
24
+ - Large collections remain `warning`, `.all.pluck` remains `error`
25
+
10
26
  ## [1.1.4] - 2026-01-06
11
27
 
12
28
  ### Fixed
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  <p align="center">
12
12
  <a href="https://github.com/hamzagedikkaya/eager_eye/actions/workflows/main.yml"><img src="https://github.com/hamzagedikkaya/eager_eye/actions/workflows/main.yml/badge.svg" alt="CI"></a>
13
- <a href="https://rubygems.org/gems/eager_eye"><img src="https://img.shields.io/badge/gem-v1.1.4-red.svg" alt="Gem Version"></a>
13
+ <a href="https://rubygems.org/gems/eager_eye"><img src="https://img.shields.io/badge/gem-v1.1.6-red.svg" alt="Gem Version"></a>
14
14
  <a href="https://github.com/hamzagedikkaya/eager_eye"><img src="https://img.shields.io/badge/coverage-95%25-brightgreen.svg" alt="Coverage"></a>
15
15
  <a href="https://www.ruby-lang.org/"><img src="https://img.shields.io/badge/ruby-%3E%3D%203.1-ruby.svg" alt="Ruby"></a>
16
16
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
@@ -6,6 +6,7 @@ module EagerEye
6
6
  QUERY_METHODS = %i[where find_by find_by! exists? find first last take pluck ids count sum average minimum
7
7
  maximum].freeze
8
8
  ARRAY_METHODS = %i[first last take].freeze
9
+ HASH_ARRAY_METHODS = %i[keys values].freeze
9
10
  ITERATION_METHODS = %i[each map select find_all reject collect detect find_index flat_map].freeze
10
11
 
11
12
  def self.detector_name
@@ -56,12 +57,18 @@ module EagerEye
56
57
 
57
58
  method_name = node.children[1]
58
59
  return false unless QUERY_METHODS.include?(method_name)
59
- return false if is_array_collection && ARRAY_METHODS.include?(method_name) &&
60
- receiver_is_only_block_var?(node.children[0], block_var)
60
+ return false if skip_array_method?(node, block_var, is_array_collection)
61
61
 
62
62
  receiver_chain_starts_with?(node.children[0], block_var)
63
63
  end
64
64
 
65
+ def skip_array_method?(node, block_var, is_array_collection)
66
+ return false unless ARRAY_METHODS.include?(node.children[1])
67
+
68
+ receiver_ends_with_hash_array_method?(node.children[0]) ||
69
+ (is_array_collection && receiver_is_only_block_var?(node.children[0], block_var))
70
+ end
71
+
65
72
  def receiver_is_only_block_var?(node, block_var)
66
73
  node.is_a?(Parser::AST::Node) && node.type == :lvar && node.children[0] == block_var
67
74
  end
@@ -89,11 +96,15 @@ module EagerEye
89
96
 
90
97
  case node.type
91
98
  when :array then true
92
- when :send then %i[map select collect flat_map to_a uniq compact].include?(node.children[1])
99
+ when :send then %i[map select collect flat_map to_a uniq compact keys values].include?(node.children[1])
93
100
  else false
94
101
  end
95
102
  end
96
103
 
104
+ def receiver_ends_with_hash_array_method?(node)
105
+ node.is_a?(Parser::AST::Node) && node.type == :send && HASH_ARRAY_METHODS.include?(node.children[1])
106
+ end
107
+
97
108
  def add_issue(node)
98
109
  method_name = node.children[1]
99
110
  association_chain = reconstruct_chain(node.children[0])
@@ -3,6 +3,8 @@
3
3
  module EagerEye
4
4
  module Detectors
5
5
  class PluckToArray < Base
6
+ SMALL_COLLECTIONS = %w[tags settings options categories roles permissions statuses types priorities].freeze
7
+
6
8
  def self.detector_name
7
9
  :pluck_to_array
8
10
  end
@@ -13,6 +15,7 @@ module EagerEye
13
15
  @pluck_variables = {}
14
16
  @map_id_variables = {}
15
17
  @critical_pluck_variables = {}
18
+ @small_collection_variables = {}
16
19
 
17
20
  return @issues unless ast
18
21
 
@@ -38,6 +41,7 @@ module EagerEye
38
41
  value = node.children[1]
39
42
 
40
43
  @critical_pluck_variables[var_name] = node.loc.line if all_pluck_call?(value)
44
+ @small_collection_variables[var_name] = node.loc.line if small_collection_pluck?(value)
41
45
  @pluck_variables[var_name] = node.loc.line if pluck_call?(value)
42
46
  @map_id_variables[var_name] = node.loc.line if map_id_call?(value)
43
47
  end
@@ -45,8 +49,13 @@ module EagerEye
45
49
  def check_where_calls(node)
46
50
  return unless where_call?(node)
47
51
 
48
- add_critical_issue(node) if critical_pluck?(node)
49
- add_issue(node) if regular_pluck?(node)
52
+ if critical_pluck?(node)
53
+ add_critical_issue(node)
54
+ elsif small_collection?(node)
55
+ add_info_issue(node)
56
+ elsif regular_pluck?(node)
57
+ add_issue(node)
58
+ end
50
59
  end
51
60
 
52
61
  def local_variable_assignment?(node) = node.type == :lvasgn
@@ -64,6 +73,16 @@ module EagerEye
64
73
  receiver.is_a?(Parser::AST::Node) && receiver.type == :send && receiver.children[1] == :all
65
74
  end
66
75
 
76
+ def small_collection_pluck?(node)
77
+ return false unless pluck_call?(node)
78
+
79
+ receiver = node.children[0]
80
+ return false unless receiver.is_a?(Parser::AST::Node) && receiver.type == :send
81
+
82
+ method_name = receiver.children[1].to_s
83
+ SMALL_COLLECTIONS.any? { |c| method_name.include?(c) }
84
+ end
85
+
67
86
  def map_id_call?(node)
68
87
  node.is_a?(Parser::AST::Node) && (block_map?(node) || send_map?(node))
69
88
  end
@@ -92,6 +111,10 @@ module EagerEye
92
111
  node.children[2..].any? { |arg| critical_pluck_in_hash?(arg) }
93
112
  end
94
113
 
114
+ def small_collection?(node)
115
+ node.children[2..].any? { |arg| small_collection_in_hash?(arg) }
116
+ end
117
+
95
118
  def pluck_var_in_hash?(node)
96
119
  return false unless node.is_a?(Parser::AST::Node) && node.type == :hash
97
120
 
@@ -104,6 +127,12 @@ module EagerEye
104
127
  node.children.any? { |pair| pair.type == :pair && critical_value?(pair.children[1]) }
105
128
  end
106
129
 
130
+ def small_collection_in_hash?(node)
131
+ return false unless node.is_a?(Parser::AST::Node) && node.type == :hash
132
+
133
+ node.children.any? { |pair| pair.type == :pair && small_collection_value?(pair.children[1]) }
134
+ end
135
+
107
136
  def pluck_value?(value)
108
137
  value.type == :lvar && (@pluck_variables.key?(value.children[0]) || @map_id_variables.key?(value.children[0]))
109
138
  end
@@ -112,6 +141,10 @@ module EagerEye
112
141
  value.type == :lvar ? @critical_pluck_variables.key?(value.children[0]) : all_pluck_call?(value)
113
142
  end
114
143
 
144
+ def small_collection_value?(value)
145
+ value.type == :lvar && @small_collection_variables.key?(value.children[0])
146
+ end
147
+
115
148
  def add_issue(node)
116
149
  @issues << create_issue(
117
150
  file_path: @file_path,
@@ -131,6 +164,16 @@ module EagerEye
131
164
  severity: :error
132
165
  )
133
166
  end
167
+
168
+ def add_info_issue(node)
169
+ @issues << create_issue(
170
+ file_path: @file_path,
171
+ line_number: node.loc.line,
172
+ message: "Small collection pluck may be acceptable for few records",
173
+ suggestion: "Consider `.select(:id)` for consistency, but pluck is fine for small collections",
174
+ severity: :info
175
+ )
176
+ end
134
177
  end
135
178
  end
136
179
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerEye
4
- VERSION = "1.1.4"
4
+ VERSION = "1.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eager_eye
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamzagedikkaya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-06 00:00:00.000000000 Z
11
+ date: 2026-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast