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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/SECURITY.md +1 -0
- data/lib/eager_eye/analyzer.rb +5 -14
- data/lib/eager_eye/association_parser.rb +6 -28
- data/lib/eager_eye/auto_fixer.rb +4 -12
- data/lib/eager_eye/cli.rb +2 -7
- data/lib/eager_eye/comment_parser.rb +0 -5
- data/lib/eager_eye/detectors/base.rb +3 -10
- data/lib/eager_eye/detectors/callback_query.rb +22 -47
- data/lib/eager_eye/detectors/count_in_iteration.rb +16 -54
- data/lib/eager_eye/detectors/custom_method_query.rb +25 -91
- data/lib/eager_eye/detectors/loop_association.rb +7 -30
- data/lib/eager_eye/detectors/missing_counter_cache.rb +16 -47
- data/lib/eager_eye/detectors/pluck_to_array.rb +15 -48
- data/lib/eager_eye/detectors/serializer_nesting.rb +20 -70
- data/lib/eager_eye/fixers/pluck_to_select.rb +2 -9
- data/lib/eager_eye/issue.rb +2 -9
- data/lib/eager_eye/railtie.rb +7 -20
- data/lib/eager_eye/reporters/console.rb +7 -18
- data/lib/eager_eye/rspec/matchers.rb +1 -6
- data/lib/eager_eye/version.rb +1 -1
- data/lib/eager_eye.rb +0 -1
- data/sig/eager_eye.rbs +0 -1
- metadata +2 -2
|
@@ -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
|
-
|
|
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
|
data/lib/eager_eye/issue.rb
CHANGED
|
@@ -40,20 +40,13 @@ module EagerEye
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def ==(other)
|
|
43
|
-
|
|
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
|
-
|
|
49
|
+
to_h.hash
|
|
57
50
|
end
|
|
58
51
|
|
|
59
52
|
private
|
data/lib/eager_eye/railtie.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
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
|
data/lib/eager_eye/version.rb
CHANGED
data/lib/eager_eye.rb
CHANGED
data/sig/eager_eye.rbs
CHANGED
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
|
+
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:
|
|
11
|
+
date: 2026-01-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ast
|