eager_eye 1.3.1 → 1.3.3

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: edf21044e597735154b0b1acdcda9230749bf027e8b8acafe70c6aaa1da22b62
4
- data.tar.gz: b7d6b716ff42f9e160c292a54ecf0344027c73e24eae29f6aecd34aae27d60ac
3
+ metadata.gz: 709b9faacf1729a719b9d6a2b5a76b6896433ceacaea4f155f0454256211cec4
4
+ data.tar.gz: 320a664b2d85dadbb97c04b073ad7ad6a6136077fad2b9c32479273f438287a7
5
5
  SHA512:
6
- metadata.gz: 1849caab263614bdb85ed1ddcd15f63ae4199cd978ae56e2c8a690ca0e4c0e4616851f9a09f835d95e61adb457e35d5d07fbb3cb189c6394812f7064901cfaed
7
- data.tar.gz: fe737b046298753a2fb9739f26307d46fbe4852a47f2a147fae56169259824dff4ced9f3f4cc3c6a37c58dbaea03785d2a1003d230d6b5c7cba56c4224ad011e
6
+ metadata.gz: a24335ee136add109f4484a07b4e45888308275965a0cb2213d348ca42fca6ac2395d0f09e99f3a3bc9e8109048a9cb69af35b2edc453f607562582ff3bbfddf
7
+ data.tar.gz: 4e2294859302a6afc52bf833e5aa5fcad684febf7bb73b7f2e8c6a68b6fdf250b909f9315020cc8ad09ba29dd665ce01f287af3b84ba7425709b22e67be0c8b7
data/CHANGELOG.md CHANGED
@@ -7,6 +7,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.3] - 2026-07-09
11
+
12
+ ### Fixed
13
+
14
+ - **Repackage 1.3.2, which shipped without `lib/eager_eye/source_parser.rb`.**
15
+ The 1.3.2 gem was built from a tree where the new `source_parser.rb` had not
16
+ yet been committed, so `git ls-files` (which drives `spec.files`) omitted it
17
+ and every `require "eager_eye"` raised `LoadError: cannot load such file --
18
+ eager_eye/source_parser`. 1.3.3 contains the identical 1.3.2 changes with the
19
+ file included — no source changes beyond the version bump. The gemspec now
20
+ also fails the build if any `lib/**/*.rb` file is missing from the package,
21
+ so this cannot recur.
22
+
23
+ ## [1.3.2] - 2026-07-09
24
+
25
+
26
+ ### Fixed
27
+
28
+ - **Unparseable files are reported once, by name — not as raw parser dumps.**
29
+ A file the parser gem cannot lex (e.g. a model holding a binary string
30
+ literal whose escapes are invalid UTF-8) used to trigger the default
31
+ diagnostic consumer, which dumped a three-line error block to stderr on
32
+ *every* analysis pass — three times per scan — labelled `(string):63` with
33
+ no hint of which file was affected, while the file itself was silently
34
+ dropped from analysis. All parsing now goes through the new
35
+ `EagerEye::SourceParser` (quiet diagnostics, buffers named after the real
36
+ file), and the analyzer emits a single clear line per file instead:
37
+ `EagerEye: Skipped unparseable file app/models/coupon.rb: literal contains
38
+ escape sequences incompatible with UTF-8`. Skipped files and their reasons
39
+ are also exposed programmatically via `Analyzer#skipped_files` (reset on
40
+ every `#run`). Unknown magic encoding comments (`# encoding: utf8` — a
41
+ `Parser::UnknownEncodingInMagicComment`, which is an ArgumentError rather
42
+ than a SyntaxError and previously crashed the whole run) are handled the
43
+ same way, and an unparseable `db/schema.rb` now warns explicitly that
44
+ schema-aware column checks are disabled instead of degrading precision in
45
+ silence.
46
+ - **No more `parser/current` version-deviation warning.** EagerEye now
47
+ requires the grammar matching the running Ruby's *minor* version
48
+ (`parser/ruby33` on any 3.3.x) instead of `parser/current`, which insists
49
+ on an exact patch match and warned on every load ("parser/current is
50
+ loading parser/ruby33, which recognizes 3.3.4-compliant syntax, but you
51
+ are running 3.3.1"). Grammar only changes between minor versions, so
52
+ behaviour is identical; Rubies without a bundled grammar file fall back to
53
+ `parser/current` as before.
54
+
10
55
  ## [1.3.1] - 2026-06-12
11
56
 
12
57
  ### Changed — precision (fewer false positives)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parser/current"
3
+ require_relative "source_parser"
4
4
 
5
5
  module EagerEye
6
6
  class Analyzer
@@ -32,7 +32,7 @@ module EagerEye
32
32
 
33
33
  attr_reader :paths, :issues, :association_preloads, :association_names, :method_queries, :delegation_maps,
34
34
  :scope_maps, :uniqueness_models, :associations_by_model, :all_columns, :columns_by_model,
35
- :serializer_usage
35
+ :serializer_usage, :skipped_files
36
36
 
37
37
  def initialize(paths: nil)
38
38
  @paths = Array(paths || EagerEye.configuration.app_path)
@@ -47,10 +47,12 @@ module EagerEye
47
47
  @all_columns = Set.new
48
48
  @columns_by_model = {}
49
49
  @serializer_usage = SerializerUsageParser.new
50
+ @skipped_files = {}
50
51
  end
51
52
 
52
53
  def run
53
54
  @issues = []
55
+ @skipped_files = {}
54
56
  collect_schema
55
57
  collect_model_metadata
56
58
  collect_serializer_usage
@@ -73,7 +75,7 @@ module EagerEye
73
75
  # this to stay silent on associations preloaded at all render sites.
74
76
  def collect_serializer_usage
75
77
  ruby_files.each do |file_path|
76
- ast = parse_source(File.read(file_path))
78
+ ast = parse_source(File.read(file_path), file_path)
77
79
  @serializer_usage.parse_file(ast) if ast
78
80
  rescue Errno::ENOENT, Errno::EACCES
79
81
  next
@@ -82,7 +84,7 @@ module EagerEye
82
84
 
83
85
  def collect_model_metadata
84
86
  model_files.each do |file_path|
85
- ast = parse_source(File.read(file_path))
87
+ ast = parse_source(File.read(file_path), file_path)
86
88
  next unless ast
87
89
 
88
90
  model_name = extract_model_name(file_path)
@@ -143,7 +145,7 @@ module EagerEye
143
145
 
144
146
  def analyze_file(file_path)
145
147
  source = File.read(file_path)
146
- ast = parse_source(source)
148
+ ast = parse_source(source, file_path)
147
149
  return unless ast
148
150
 
149
151
  comment_parser = CommentParser.new(source)
@@ -160,12 +162,24 @@ module EagerEye
160
162
  warn "EagerEye: Could not read file #{file_path}: #{e.message}"
161
163
  end
162
164
 
163
- def parse_source(source)
164
- Parser::CurrentRuby.parse(source)
165
- rescue Parser::SyntaxError
165
+ # A file the parser cannot handle (syntax error, binary literal whose
166
+ # escapes are invalid UTF-8, ...) is skipped from analysis entirely. Each
167
+ # such file is recorded in #skipped_files and warned about exactly once,
168
+ # even though every file is parsed by multiple passes.
169
+ def parse_source(source, file_path)
170
+ SourceParser.parse(source, file_path)
171
+ rescue Parser::SyntaxError, Parser::UnknownEncodingInMagicComment, EncodingError => e
172
+ register_unparseable(file_path, e.message)
166
173
  nil
167
174
  end
168
175
 
176
+ def register_unparseable(file_path, message)
177
+ return if @skipped_files.key?(file_path)
178
+
179
+ @skipped_files[file_path] = message
180
+ warn "EagerEye: Skipped unparseable file #{file_path}: #{message}"
181
+ end
182
+
169
183
  def detector_args(detector, ast, file_path)
170
184
  extra = DETECTOR_EXTRA_ARGS.find { |klass, _| detector.is_a?(klass) }&.last || []
171
185
  [ast, file_path, *extra.map { |name| instance_variable_get(:"@#{name}") }]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parser/current"
3
+ require_relative "../source_parser"
4
4
 
5
5
  module EagerEye
6
6
  module Detectors
@@ -43,9 +43,12 @@ module EagerEye
43
43
  node.children.each { |child| traverse_ast(child, &block) }
44
44
  end
45
45
 
46
- def parse_source(source)
47
- Parser::CurrentRuby.parse(source)
48
- rescue Parser::SyntaxError
46
+ # Convenience for detector subclasses; returns nil (without any stderr
47
+ # output) when the source cannot be parsed. Pass file_path so any
48
+ # diagnostics you inspect on the raised error name the real file.
49
+ def parse_source(source, file_path = "(string)")
50
+ SourceParser.parse(source, file_path)
51
+ rescue Parser::SyntaxError, Parser::UnknownEncodingInMagicComment, EncodingError
49
52
  nil
50
53
  end
51
54
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parser/current"
3
+ require_relative "source_parser"
4
4
 
5
5
  module EagerEye
6
6
  # Parses db/schema.rb to learn the real column names of each table. Columns are
@@ -31,7 +31,7 @@ module EagerEye
31
31
  schema = locate_schema(start_path)
32
32
  return false unless schema
33
33
 
34
- ast = parse(File.read(schema))
34
+ ast = parse(File.read(schema), schema)
35
35
  return false unless ast
36
36
 
37
37
  walk(ast)
@@ -62,9 +62,12 @@ module EagerEye
62
62
  nil
63
63
  end
64
64
 
65
- def parse(source)
66
- Parser::CurrentRuby.parse(source)
67
- rescue Parser::SyntaxError
65
+ # An unparseable schema silently disables the column disambiguation that
66
+ # filters most false positives, so the failure must not be swallowed.
67
+ def parse(source, file_path)
68
+ SourceParser.parse(source, file_path)
69
+ rescue Parser::SyntaxError, Parser::UnknownEncodingInMagicComment, EncodingError => e
70
+ warn "EagerEye: Could not parse schema #{file_path}: #{e.message} (schema-aware column checks disabled)"
68
71
  nil
69
72
  end
70
73
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parser/current"
3
+ require_relative "source_parser"
4
4
 
5
5
  module EagerEye
6
6
  # Serializers are the worst false-positive source because the detector sees the
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Require the grammar matching the running Ruby's minor version (parser/ruby33
4
+ # for any 3.3.x) instead of parser/current, which insists on an exact *patch*
5
+ # match and warns on every load otherwise ("parser/current is loading
6
+ # parser/ruby33, which recognizes 3.3.4-compliant syntax, but you are running
7
+ # 3.3.1"). Grammar only changes between minor versions, so the versioned
8
+ # require is exactly as correct — and is the parser gem's documented way to
9
+ # opt out of the warning. Unknown future Rubies fall back to parser/current.
10
+ begin
11
+ require "parser/ruby#{RUBY_VERSION.split(".").first(2).join}"
12
+ rescue LoadError
13
+ require "parser/current"
14
+ end
15
+
16
+ module EagerEye
17
+ # Single entry point for turning Ruby source into an AST. Differs from
18
+ # `Parser::CurrentRuby.parse` in two ways that matter for a CLI tool:
19
+ #
20
+ # * No stderr side effects. The default parser prints every lexer/parser
21
+ # diagnostic straight to $stderr — so one unparseable file (e.g. a model
22
+ # holding a binary string literal whose escapes are invalid UTF-8) dumps
23
+ # a raw three-line diagnostic once per analysis pass. Diagnostics stay
24
+ # quiet here; failures surface only as the raised exception.
25
+ # * The buffer is named after the real file, so callers can report
26
+ # "app/models/coupon.rb", not "(string)".
27
+ #
28
+ # Raises like the original — Parser::SyntaxError, EncodingError, or
29
+ # Parser::UnknownEncodingInMagicComment (an ArgumentError, NOT a
30
+ # SyntaxError, raised for e.g. `# encoding: utf8` typos); callers decide
31
+ # whether and how to report.
32
+ module SourceParser
33
+ PARSER_CLASS =
34
+ begin
35
+ Parser.const_get(:"Ruby#{RUBY_VERSION.split(".").first(2).join}", false)
36
+ rescue NameError
37
+ Parser::CurrentRuby
38
+ end
39
+
40
+ def self.parse(source, file_path = "(string)")
41
+ parser = PARSER_CLASS.new
42
+ parser.diagnostics.all_errors_are_fatal = true
43
+ parser.diagnostics.ignore_warnings = true
44
+
45
+ buffer = Parser::Source::Buffer.new(file_path, 1)
46
+ buffer.source = source.dup.force_encoding(parser.default_encoding)
47
+ parser.parse(buffer)
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerEye
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.3"
5
5
  end
data/lib/eager_eye.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "set"
4
4
  require_relative "eager_eye/version"
5
+ require_relative "eager_eye/source_parser"
5
6
  require_relative "eager_eye/configuration"
6
7
  require_relative "eager_eye/issue"
7
8
  require_relative "eager_eye/baseline"
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.3.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamzagedikkaya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-06-12 00:00:00.000000000 Z
11
+ date: 2026-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -99,6 +99,7 @@ files:
99
99
  - lib/eager_eye/schema_parser.rb
100
100
  - lib/eager_eye/scope_parser.rb
101
101
  - lib/eager_eye/serializer_usage_parser.rb
102
+ - lib/eager_eye/source_parser.rb
102
103
  - lib/eager_eye/validation_parser.rb
103
104
  - lib/eager_eye/version.rb
104
105
  - sig/eager_eye.rbs