eager_eye 1.1.0 → 1.1.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.
@@ -3,27 +3,20 @@
3
3
  module EagerEye
4
4
  module Fixers
5
5
  class PluckToSelect < Base
6
- # This fixer only works for single-line pluck + where patterns
7
- # Two-line patterns are too complex to fix automatically
8
-
9
6
  def fixable?
10
- issue.detector == :pluck_to_array &&
11
- single_line_pattern?
7
+ issue.detector == :pluck_to_array && single_line_pattern?
12
8
  end
13
9
 
14
10
  protected
15
11
 
16
12
  def fixed_content
17
- # Model.where(col: OtherModel.pluck(:id)) -> Model.where(col: OtherModel.select(:id))
18
13
  line_content.gsub(/\.pluck\((:\w+)\)/, '.select(\1)')
19
14
  end
20
15
 
21
16
  private
22
17
 
23
18
  def single_line_pattern?
24
- return false unless line_content
25
-
26
- line_content.include?(".pluck(") && line_content.include?(".where(")
19
+ line_content&.include?(".pluck(") && line_content.include?(".where(")
27
20
  end
28
21
  end
29
22
  end
@@ -40,20 +40,13 @@ module EagerEye
40
40
  end
41
41
 
42
42
  def ==(other)
43
- return false unless other.is_a?(Issue)
44
-
45
- detector == other.detector &&
46
- file_path == other.file_path &&
47
- line_number == other.line_number &&
48
- message == other.message &&
49
- severity == other.severity &&
50
- suggestion == other.suggestion
43
+ other.is_a?(Issue) && to_h == other.to_h
51
44
  end
52
45
 
53
46
  alias eql? ==
54
47
 
55
48
  def hash
56
- [detector, file_path, line_number, message, severity, suggestion].hash
49
+ to_h.hash
57
50
  end
58
51
 
59
52
  private
@@ -10,32 +10,20 @@ module EagerEye
10
10
  namespace :eager_eye do
11
11
  desc "Analyze Rails application for N+1 query issues"
12
12
  task analyze: :environment do
13
- require "eager_eye"
14
-
15
- load_config_file
16
-
17
- analyzer = EagerEye::Analyzer.new
18
- issues = analyzer.run
19
-
20
- reporter = EagerEye::Reporters::Console.new(issues)
21
- puts reporter.report
22
-
23
- exit 1 if issues.any? && EagerEye.configuration.fail_on_issues
13
+ puts run_analysis(EagerEye::Reporters::Console)
24
14
  end
25
15
 
26
16
  desc "Analyze and output results as JSON"
27
17
  task json: :environment do
28
- require "eager_eye"
18
+ puts run_analysis(EagerEye::Reporters::Json, pretty: true)
19
+ end
29
20
 
21
+ def run_analysis(reporter_class, **opts)
22
+ require "eager_eye"
30
23
  load_config_file
31
-
32
- analyzer = EagerEye::Analyzer.new
33
- issues = analyzer.run
34
-
35
- reporter = EagerEye::Reporters::Json.new(issues, pretty: true)
36
- puts reporter.report
37
-
24
+ issues = EagerEye::Analyzer.new.run
38
25
  exit 1 if issues.any? && EagerEye.configuration.fail_on_issues
26
+ reporter_class.new(issues, **opts).report
39
27
  end
40
28
 
41
29
  def load_config_file
@@ -55,7 +43,6 @@ module EagerEye
55
43
  end
56
44
  end
57
45
 
58
- # Generate initializer for configuration
59
46
  generators do
60
47
  require_relative "generators/install_generator"
61
48
  end
@@ -48,15 +48,7 @@ module EagerEye
48
48
  end
49
49
 
50
50
  def file_section(file_path, file_issues)
51
- lines = []
52
- lines << colorize(file_path, :cyan)
53
-
54
- file_issues.each do |issue|
55
- lines << format_issue(issue)
56
- end
57
-
58
- lines << ""
59
- lines.join("\n")
51
+ [colorize(file_path, :cyan), *file_issues.map { |i| format_issue(i) }, ""].join("\n")
60
52
  end
61
53
 
62
54
  def format_issue(issue)
@@ -81,15 +73,12 @@ module EagerEye
81
73
  end
82
74
 
83
75
  def summary
84
- total = issues.size
85
- errors = error_count
86
- warnings = warning_count
87
- infos = info_count
88
-
89
- "Total: #{total} issue#{"s" unless total == 1} " \
90
- "(#{errors} error#{"s" unless errors == 1}, " \
91
- "#{warnings} warning#{"s" unless warnings == 1}, " \
92
- "#{infos} info)"
76
+ t = issues.size
77
+ e = error_count
78
+ w = warning_count
79
+ i = info_count
80
+ "Total: #{t} issue#{"s" unless t == 1} " \
81
+ "(#{e} error#{"s" unless e == 1}, #{w} warning#{"s" unless w == 1}, #{i} info)"
93
82
  end
94
83
 
95
84
  def colorize(text, color)
@@ -19,8 +19,7 @@ module EagerEye
19
19
  def matches?(path)
20
20
  @path = path
21
21
  configure_eager_eye
22
- analyzer = build_analyzer
23
- @issues = analyzer.run
22
+ @issues = EagerEye::Analyzer.new(paths: [@path]).run
24
23
  @issues.count <= @max_issues
25
24
  end
26
25
 
@@ -61,10 +60,6 @@ module EagerEye
61
60
  config.fail_on_issues = false
62
61
  end
63
62
  end
64
-
65
- def build_analyzer
66
- EagerEye::Analyzer.new(paths: [@path])
67
- end
68
63
  end
69
64
  end
70
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerEye
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.2"
5
5
  end
data/lib/eager_eye.rb CHANGED
@@ -41,5 +41,4 @@ module EagerEye
41
41
  end
42
42
  end
43
43
 
44
- # Load Railtie only if Rails is defined
45
44
  require_relative "eager_eye/railtie" if defined?(Rails::Railtie)
data/sig/eager_eye.rbs CHANGED
@@ -1,4 +1,3 @@
1
1
  module EagerEye
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
3
  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.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamzagedikkaya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-12-28 00:00:00.000000000 Z
11
+ date: 2026-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast