judgelint 0.1.7 → 0.1.9

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: 6dcc0a70019bd3dda62fe68777bf2ca2f76a79b5bef25d1d7bd5b6c9776a592c
4
- data.tar.gz: 15445873a65cdf4460e51a432b5f89023f391031a4f41fcd6ddcd15e4bb9fafc
3
+ metadata.gz: a90b0ee415a2b08188fd8141eef3ea4f725e3317a886b487d86ed4d1463c88a4
4
+ data.tar.gz: e0c57f2b25e7775a9dcedae5be947de53e8a1bc6ef363d4f07c3a601c8bcfb8d
5
5
  SHA512:
6
- metadata.gz: 4ae27a5ebabefb268a13d347d6470a51235845c4207e2134b29e46b9ccaf81affedd38c7090781f3430fd53ca07470716fb0e23af742b19d77108d46d9cb5585
7
- data.tar.gz: bc7b8d1901d0eb3b0ce2bcf20690e5d93b841e9e9376b2f8c5f0ced2e9c9228edbfb69f5ee1ef49b1c097433376c85d234b070fc97140da388642ea34222c8b3
6
+ metadata.gz: 8849be7a19c2fe4e64304109120856ae8adbd02e3b6cca0894b6cecc2a56be27fa9af3f5e7c805d8c32f6df73e40f42a7b0b2e15e8628c93b938371d605651a8
7
+ data.tar.gz: 3df1f283287488314cbb5fb8c2ac21f8b79ead7ed94ce5eb4a2354fd93ca2979f3984a73a24898a4c9a8467c29c2fe698887c52aef7deae2b001e4a1d87d7913
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.9 (2026-10-27)
4
+
5
+ - `check` uses much less memory on large projects. On 50,000 files its
6
+ peak falls from 835 MB to 518 MB in Ruby and from 2.25 GB to 856 MB in
7
+ the native binary. Output is unchanged.
8
+
9
+ ## 0.1.8 (2026-10-26)
10
+
11
+ - YAML that names a class `safe_load` won't build, like `!ruby/sym` or a
12
+ date, is a config error instead of a crash with a stack trace. So are
13
+ YAML aliases.
14
+
3
15
  ## 0.1.7 (2026-10-26)
4
16
 
5
17
  - A symlink that points to itself no longer crashes a run. Ruby's Dir.glob
@@ -21,12 +21,13 @@ module Judgelint
21
21
  EXCUSED = "A judgehint comment is about this rule, and gives a reason the code may break it."
22
22
  NOT_EXCUSED = "No judgehint comment is about this rule. Any judgehint is about a different rule, or gives no reason."
23
23
 
24
- attr_reader :rule, :first, :last, :places, :lines
24
+ attr_reader :rule, :first, :last, :lines
25
25
 
26
26
  # +kind+ is :verdict, :where, or :excuse. +places+ are a :where question's
27
- # options: line ids (L12) or the directory's files, as the model sees them.
27
+ # options as the model sees them: the directory's files, or nil for the
28
+ # range's line ids (L12).
28
29
  # +lines+ are the changed lines in the range, or nil to ask about all of it.
29
- def initialize(rule, first, last, kind: :verdict, places: [], lines: nil)
30
+ def initialize(rule, first, last, kind: :verdict, places: nil, lines: nil)
30
31
  @rule = rule
31
32
  @first = first
32
33
  @last = last
@@ -35,6 +36,10 @@ module Judgelint
35
36
  @lines = lines
36
37
  end
37
38
 
39
+ def places
40
+ @places || (first..last).map { |line| "L#{line}" }
41
+ end
42
+
38
43
  def excuse?
39
44
  @kind == :excuse
40
45
  end
@@ -14,22 +14,27 @@ module Judgelint
14
14
  # One file's work: the questions to ask, each model's answers (from the
15
15
  # cache or the model), and the requests still to send.
16
16
  class Job
17
- attr_reader :source, :state, :state_digest, :questions, :answers, :requests, :expected
17
+ attr_reader :source, :state_digest, :questions, :answers, :requests, :expected
18
18
  attr_accessor :skipped
19
19
 
20
- # The state is built and hashed once: it's the whole file, and every
21
- # question's cache key needs its hash. Rules from a spec read its prose
22
- # alongside the file, as team_rules.
20
+ # The state is the whole file, and a run plans every file before it
21
+ # sends one, so it's built when needed rather than kept. Its hash, which
22
+ # every question's cache key needs, is kept.
23
23
  def initialize(source, questions, prose: nil, expected: nil)
24
24
  @source = source
25
- @state = prose ? { "team_rules" => prose, "file" => source.state } : source.state
26
- @state_digest = Digest::SHA256.hexdigest(JSON.generate(@state))
25
+ @prose = prose
26
+ @state_digest = Digest::SHA256.hexdigest(JSON.generate(state))
27
27
  @questions = questions
28
28
  @answers = {} # model index => {question key => probability or nil}
29
29
  @requests = []
30
30
  @expected = expected
31
31
  @skipped = false
32
32
  end
33
+
34
+ # Rules from a spec read its prose alongside the file, as team_rules.
35
+ def state
36
+ @prose ? { "team_rules" => @prose, "file" => @source.state } : @source.state
37
+ end
33
38
  end
34
39
 
35
40
  # Questions sent together to one model, and their estimated input tokens.
@@ -185,8 +190,7 @@ module Judgelint
185
190
  asked = []
186
191
  ranges.each do |first, last|
187
192
  asked << Question.new(rule, first, last, lines: changed_lines(rule, lines, first, last))
188
- places = places(source, rule, first, last)
189
- asked << Question.new(rule, first, last, kind: :where, places: places) unless places.empty?
193
+ asked << where(source, rule, first, last) if where?(source, rule, first, last)
190
194
  asked << Question.new(rule, first, last, kind: :excuse) if source.hinted?(first, last)
191
195
  end
192
196
  questions[rule] = asked
@@ -196,14 +200,17 @@ module Judgelint
196
200
  job
197
201
  end
198
202
 
199
- # The options for asking where a bullet is broken: the range's line ids, or
200
- # the directory's files. None for a rule written as a question, or past
203
+ # Where a bullet is broken is asked over the range's lines or the
204
+ # directory's files, but not for a rule written as a question, or past
201
205
  # what a choice can hold.
202
- def places(source, rule, first, last)
203
- return [] unless rule.convention
206
+ def where?(source, rule, first, last)
207
+ rule.convention && (rule.directory? ? source.members.size : last - first + 1) <= MAX_OPTIONS
208
+ end
204
209
 
205
- places = rule.directory? ? source.members.map { |_path, shown| shown } : (first..last).map { |line| "L#{line}" }
206
- places.size > MAX_OPTIONS ? [] : places
210
+ # A file's line ids are made when the question is sent, not kept.
211
+ def where(source, rule, first, last)
212
+ places = rule.directory? ? source.members.map { |_path, shown| shown } : nil
213
+ Question.new(rule, first, last, kind: :where, places: places)
207
214
  end
208
215
 
209
216
  # Rules that read different context files or spec prose can't share a request.
@@ -264,7 +271,9 @@ module Judgelint
264
271
 
265
272
  # Sends every request at once: a file's packed requests and every model's.
266
273
  def ask(job)
267
- state = job.state.dup # Spinel can't yet pass the Job's shared String along
274
+ return if job.requests.empty?
275
+
276
+ state = job.state
268
277
  results = Pool.map(job.requests, job.requests.size) do |request|
269
278
  @clients[request.model].judge(state, request.questions)
270
279
  end
@@ -19,16 +19,20 @@ module Judgelint
19
19
  end
20
20
 
21
21
  # +text+ is the file's contents when it isn't on disk, like an example in a spec.
22
+ # Each file is kept as one string, since a run holds every file it plans.
22
23
  def initialize(path, shown_as: path, files: [path], context: [], directory: false, text: nil)
23
24
  @path = path
24
25
  @shown_as = shown_as
25
26
  @directory = directory
26
- @files = text ? [[path, text.lines]] : files.map { |file| [file, File.read(file).lines] }
27
+ @files = text ? [[path, text]] : files.map { |file| [file, File.read(file)] }
27
28
  @context = context
28
- @line_count = @files.sum { |_file, lines| lines.size }
29
+ @line_count = 0
29
30
  @hints = []
30
- @files.each do |_file, lines|
31
- lines.each_with_index { |line, index| @hints << index + 1 if HINT.match?(line) }
31
+ @files.each do |_file, contents|
32
+ contents.each_line do |line|
33
+ @line_count += 1
34
+ @hints << @line_count if HINT.match?(line)
35
+ end
32
36
  end
33
37
  end
34
38
 
@@ -39,7 +43,7 @@ module Judgelint
39
43
  def state
40
44
  body =
41
45
  if directory?
42
- sections = @files.map { |file, lines| "Path: #{shown(file)}\n\n#{numbered(lines)}" }
46
+ sections = @files.map { |file, contents| "Path: #{shown(file)}\n\n#{numbered(contents)}" }
43
47
  "Directory: #{shown_as}\n\n#{sections.join("\n")}"
44
48
  else
45
49
  "Path: #{shown_as}\n\n#{numbered(@files.first[1])}"
@@ -57,7 +61,7 @@ module Judgelint
57
61
 
58
62
  # The directory's files as [path, the path the model sees].
59
63
  def members
60
- @files.map { |file, _lines| [file, shown(file)] }
64
+ @files.map { |file, _contents| [file, shown(file)] }
61
65
  end
62
66
 
63
67
  def hinted?(first, last)
@@ -66,8 +70,8 @@ module Judgelint
66
70
 
67
71
  private
68
72
 
69
- def numbered(lines)
70
- lines.each_with_index.map { |line, index| "#{index + 1}: #{line.chomp}\n" }.join
73
+ def numbered(contents)
74
+ contents.lines.each_with_index.map { |line, index| "#{index + 1}: #{line.chomp}\n" }.join
71
75
  end
72
76
 
73
77
  # A file's path inside the directory, as the model sees it.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Judgelint
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
data/lib/judgelint.rb CHANGED
@@ -52,7 +52,10 @@ module Judgelint
52
52
  raise ConfigError, "#{path} must be a mapping" unless data.is_a?(Hash)
53
53
 
54
54
  data
55
- rescue Psych::SyntaxError => e
55
+ rescue Psych::AliasesNotEnabled
56
+ raise ConfigError, "#{path}: YAML aliases aren't supported"
57
+ rescue Psych::Exception => e
58
+ # Bad syntax, or a tag naming a class safe_load won't build.
56
59
  raise ConfigError, "#{path}: #{e.message}"
57
60
  end
58
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judgelint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Camara