eager_eye 1.1.4 → 1.1.5

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: 6c6cd435e8db21b831eef924b598c7316fea3a2bc28e2f06744ee0e69d420b9d
4
+ data.tar.gz: e777d0653d14a48afc157e109ef715150fee54b0f3271b43bf75898bc35d1099
5
5
  SHA512:
6
- metadata.gz: fa15940b451ebd100e908b4f9931c8f40708f9566451a0f1edb8a65c70fee15f832bd30d91d49f54c9b2f0ebe63cbdf2f5dbabfb5f7894db23d1a2f35c1e95c5
7
- data.tar.gz: 80ea91965317596061db8a38cce960ac4f573a4c887de7a2fe88b7a4ad7e43f35f2b18b6716a6487e256e1ed292e8f79c437249e9dbef6cccded54397a7ecf8c
6
+ metadata.gz: 1817d044118d33fa27712adc6a1548ad2959344b48e76f2a2ba24def749b01fd5f7fe2126df538636df9a2b5ed3915d8001f11020a523e008e66ccc436a4bab7
7
+ data.tar.gz: 8b69f300d0692d49e63ddc15be8dd473cc4a1ce0c320af23e8145c75c8ad0e28446d3be9e49077111d8718aca9cf2f7ab1889cb83da314c40666ed3e483b0166
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.5] - 2026-01-06
11
+
12
+ ### Changed
13
+
14
+ - **PluckToArray Severity** - Lower severity to `info` for small collections
15
+ - `tags`, `settings`, `roles`, `permissions`, `options` etc. now `info` level
16
+ - Large collections remain `warning`, `.all.pluck` remains `error`
17
+
10
18
  ## [1.1.4] - 2026-01-06
11
19
 
12
20
  ### 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.5-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>
@@ -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.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamzagedikkaya