judgelint 0.1.5 → 0.1.7
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/CHANGELOG.md +12 -0
- data/README.md +5 -2
- data/lib/judgelint/glob.rb +21 -1
- data/lib/judgelint/question.rb +27 -7
- data/lib/judgelint/rule.rb +1 -1
- data/lib/judgelint/runner.rb +32 -5
- data/lib/judgelint/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dcc0a70019bd3dda62fe68777bf2ca2f76a79b5bef25d1d7bd5b6c9776a592c
|
|
4
|
+
data.tar.gz: 15445873a65cdf4460e51a432b5f89023f391031a4f41fcd6ddcd15e4bb9fafc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ae27a5ebabefb268a13d347d6470a51235845c4207e2134b29e46b9ccaf81affedd38c7090781f3430fd53ca07470716fb0e23af742b19d77108d46d9cb5585
|
|
7
|
+
data.tar.gz: bc7b8d1901d0eb3b0ce2bcf20690e5d93b841e9e9376b2f8c5f0ced2e9c9228edbfb69f5ee1ef49b1c097433376c85d234b070fc97140da388642ea34222c8b3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.7 (2026-10-26)
|
|
4
|
+
|
|
5
|
+
- A symlink that points to itself no longer crashes a run. Ruby's Dir.glob
|
|
6
|
+
raised ELOOP when a pattern looked inside one; judgelint now skips it.
|
|
7
|
+
|
|
8
|
+
## 0.1.6 (2026-10-26)
|
|
9
|
+
|
|
10
|
+
- `--base` and `--pr` ask about the changed lines, not the 40-line windows
|
|
11
|
+
around them. A finding the model places on a line the change didn't touch
|
|
12
|
+
doesn't count, so editing an old file can't fail it for code the edit
|
|
13
|
+
left alone.
|
|
14
|
+
|
|
3
15
|
## 0.1.5 (2026-10-26)
|
|
4
16
|
|
|
5
17
|
- The text report is in color in a terminal: errors in red, warnings and
|
data/README.md
CHANGED
|
@@ -227,8 +227,11 @@ judgelint --pr # changes in the current pull request
|
|
|
227
227
|
judgelint --pr --format github # GitHub annotations on the changed lines (json and sarif work too)
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
-
These only ask about the
|
|
231
|
-
doesn't block a new pull request
|
|
230
|
+
These only ask about the lines that changed, with the rest of the file as
|
|
231
|
+
context, so existing code doesn't block a new pull request: a finding the
|
|
232
|
+
model places on a line the change didn't touch doesn't count. A new file is
|
|
233
|
+
all changed lines. Rules about a whole file (`scope: file`) still read the
|
|
234
|
+
whole file when any of it changed. `--pr` gets the base branch from GitHub
|
|
232
235
|
Actions, GitLab, Buildkite, Bitbucket, Azure Pipelines,
|
|
233
236
|
`JUDGELINT_BASE_BRANCH`, or `gh`. Fetch enough history for git to find the
|
|
234
237
|
merge base.
|
data/lib/judgelint/glob.rb
CHANGED
|
@@ -14,7 +14,27 @@ module Judgelint
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.expand(patterns)
|
|
17
|
-
patterns.flat_map { |pattern|
|
|
17
|
+
patterns.flat_map { |pattern| glob(pattern) }.select { |path| File.file?(path) }.uniq.sort
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Dir.glob, except that a symlink to itself is skipped. Dir.glob raises
|
|
21
|
+
# ELOOP when a pattern looks inside one, so the pattern is then globbed a
|
|
22
|
+
# segment at a time, entering only directories that resolve.
|
|
23
|
+
def self.glob(pattern)
|
|
24
|
+
Dir.glob(pattern)
|
|
25
|
+
rescue Errno::ELOOP
|
|
26
|
+
parts = pattern.split("/")
|
|
27
|
+
found = [""]
|
|
28
|
+
until parts.empty?
|
|
29
|
+
part = parts.shift
|
|
30
|
+
part = "#{part}/#{parts.shift}" if part == "**" && !parts.empty?
|
|
31
|
+
found = found.flat_map do |dir|
|
|
32
|
+
next [] unless dir.empty? || File.directory?(dir)
|
|
33
|
+
|
|
34
|
+
Dir.glob(dir.empty? ? part : File.join(dir, part))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
found
|
|
18
38
|
end
|
|
19
39
|
|
|
20
40
|
# The files to check: in a git repository, those git tracks or would add,
|
data/lib/judgelint/question.rb
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Judgelint
|
|
4
4
|
# One rule asked about one range of a file. The model sees the whole file;
|
|
5
|
-
# the question points at the lines.
|
|
5
|
+
# the question points at the lines. When a change touched only some of a
|
|
6
|
+
# window's lines, it points at those, so code the change didn't touch can't
|
|
7
|
+
# fail it.
|
|
6
8
|
#
|
|
7
9
|
# A spec's bullet is a choice between breaking the rule, following it, and
|
|
8
10
|
# the rule not applying. With the three side by side, a decision model
|
|
@@ -19,16 +21,18 @@ module Judgelint
|
|
|
19
21
|
EXCUSED = "A judgehint comment is about this rule, and gives a reason the code may break it."
|
|
20
22
|
NOT_EXCUSED = "No judgehint comment is about this rule. Any judgehint is about a different rule, or gives no reason."
|
|
21
23
|
|
|
22
|
-
attr_reader :rule, :first, :last, :places
|
|
24
|
+
attr_reader :rule, :first, :last, :places, :lines
|
|
23
25
|
|
|
24
26
|
# +kind+ is :verdict, :where, or :excuse. +places+ are a :where question's
|
|
25
27
|
# options: line ids (L12) or the directory's files, as the model sees them.
|
|
26
|
-
|
|
28
|
+
# +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)
|
|
27
30
|
@rule = rule
|
|
28
31
|
@first = first
|
|
29
32
|
@last = last
|
|
30
33
|
@kind = kind
|
|
31
34
|
@places = places
|
|
35
|
+
@lines = lines
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
def excuse?
|
|
@@ -72,9 +76,9 @@ module Judgelint
|
|
|
72
76
|
def instructions
|
|
73
77
|
return excuse_instructions if excuse?
|
|
74
78
|
return where_instructions if where?
|
|
75
|
-
return "How #{rule.scope == 'file' ? 'does' : 'do'} #{subject} relate to the following team rule? Rule: #{rule.convention}" if rule.convention
|
|
79
|
+
return "How #{rule.scope == 'file' || lines&.size == 1 ? 'does' : 'do'} #{subject} relate to the following team rule? Rule: #{rule.convention}" if rule.convention
|
|
76
80
|
|
|
77
|
-
text = rule.window? ? "Look at
|
|
81
|
+
text = rule.window? ? "Look at #{span} of the file; the rest is context. #{rule.question}" : rule.question
|
|
78
82
|
return text unless rule.fail_when == "yes"
|
|
79
83
|
|
|
80
84
|
scope = { "window" => "those lines do it", "file" => "the code does it", "directory" => "the files do it" }
|
|
@@ -104,8 +108,24 @@ module Judgelint
|
|
|
104
108
|
private
|
|
105
109
|
|
|
106
110
|
def subject
|
|
107
|
-
{ "window" => "
|
|
108
|
-
|
|
111
|
+
{ "window" => "#{span} of the file", "file" => "the file", "directory" => "the files" }.fetch(rule.scope)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The lines asked about: "lines 41-80", or the changed ones, as "line 7" or
|
|
115
|
+
# "lines 3, 7-9".
|
|
116
|
+
def span
|
|
117
|
+
return "lines #{first}-#{last}" if lines.nil?
|
|
118
|
+
return "line #{lines.first}" if lines.size == 1
|
|
119
|
+
|
|
120
|
+
runs = []
|
|
121
|
+
lines.each do |line|
|
|
122
|
+
if !runs.empty? && runs.last[1] == line - 1
|
|
123
|
+
runs.last[1] = line
|
|
124
|
+
else
|
|
125
|
+
runs << [line, line]
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
"lines #{runs.map { |run| run[0] == run[1] ? run[0].to_s : "#{run[0]}-#{run[1]}" }.join(', ')}"
|
|
109
129
|
end
|
|
110
130
|
|
|
111
131
|
def where_instructions
|
data/lib/judgelint/rule.rb
CHANGED
|
@@ -89,7 +89,7 @@ module Judgelint
|
|
|
89
89
|
|
|
90
90
|
# The directories a directory rule governs.
|
|
91
91
|
def directories
|
|
92
|
-
paths.flat_map { |pattern|
|
|
92
|
+
paths.flat_map { |pattern| Glob.glob(pattern) }.select { |path| File.directory?(path) && applies_to?(path) }.uniq.sort
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
# The ranges to ask about: windows of +size+ lines, or the whole file.
|
data/lib/judgelint/runner.rb
CHANGED
|
@@ -72,6 +72,8 @@ module Judgelint
|
|
|
72
72
|
|
|
73
73
|
# +changes+ ({path => lines or :all}, from Changes.since) limits each file
|
|
74
74
|
# to the windows a change touched, and directories to those with a change.
|
|
75
|
+
# A window rule is asked about the changed lines alone, with the rest of
|
|
76
|
+
# the file as context.
|
|
75
77
|
# Rules that read different context files can't share a request, so a
|
|
76
78
|
# file gets one job per set of context files.
|
|
77
79
|
def plan(paths, directories: [], changes: nil)
|
|
@@ -182,7 +184,7 @@ module Judgelint
|
|
|
182
184
|
|
|
183
185
|
asked = []
|
|
184
186
|
ranges.each do |first, last|
|
|
185
|
-
asked << Question.new(rule, first, last)
|
|
187
|
+
asked << Question.new(rule, first, last, lines: changed_lines(rule, lines, first, last))
|
|
186
188
|
places = places(source, rule, first, last)
|
|
187
189
|
asked << Question.new(rule, first, last, kind: :where, places: places) unless places.empty?
|
|
188
190
|
asked << Question.new(rule, first, last, kind: :excuse) if source.hinted?(first, last)
|
|
@@ -209,6 +211,14 @@ module Judgelint
|
|
|
209
211
|
rules.group_by { |rule| [rule.context, rule.prose] }.map { |(globs, _prose), group| yield(Glob.expand(globs), group) }
|
|
210
212
|
end
|
|
211
213
|
|
|
214
|
+
# The lines a change touched in a window rule's range, or nil for all of them.
|
|
215
|
+
def changed_lines(rule, lines, first, last)
|
|
216
|
+
return nil if lines == :all || !rule.window?
|
|
217
|
+
|
|
218
|
+
changed = lines.select { |line| line.between?(first, last) }.uniq.sort
|
|
219
|
+
changed.size == last - first + 1 ? nil : changed
|
|
220
|
+
end
|
|
221
|
+
|
|
212
222
|
def touched?(lines, first, last)
|
|
213
223
|
lines == :all || (lines || []).any? { |line| line.between?(first, last) }
|
|
214
224
|
end
|
|
@@ -276,9 +286,11 @@ module Judgelint
|
|
|
276
286
|
|
|
277
287
|
# A window's probability of a violation is the average of its verdict
|
|
278
288
|
# over the models, and its place is the line or file the models' "where"
|
|
279
|
-
# answers agree on.
|
|
280
|
-
#
|
|
281
|
-
#
|
|
289
|
+
# answers agree on. When a change touched only some of its lines, the
|
|
290
|
+
# probability counts only the share of "where" answers on those lines. A
|
|
291
|
+
# rule's verdict is its worst window. A window whose judgehint excuses it,
|
|
292
|
+
# by the same average and threshold, is reported as excused instead,
|
|
293
|
+
# unless another window breaks the rule.
|
|
282
294
|
def verdict_for(rule, path, questions, job)
|
|
283
295
|
return Verdict.new(rule: rule, path: path, probability: nil, status: :skipped) if job.skipped
|
|
284
296
|
|
|
@@ -304,7 +316,10 @@ module Judgelint
|
|
|
304
316
|
end
|
|
305
317
|
next if values.empty?
|
|
306
318
|
|
|
307
|
-
|
|
319
|
+
probability = values.sum / values.size
|
|
320
|
+
changed = asked.first.lines # the verdict question comes first
|
|
321
|
+
probability *= changed_share(spread, changed) if changed
|
|
322
|
+
window = Window.new(first, last, probability, agreed(spread))
|
|
308
323
|
if !excuses.empty? && excuses.sum / excuses.size >= rule.threshold
|
|
309
324
|
excused << window
|
|
310
325
|
else
|
|
@@ -323,6 +338,18 @@ module Judgelint
|
|
|
323
338
|
line: hidden.line, file: hidden.file)
|
|
324
339
|
end
|
|
325
340
|
|
|
341
|
+
# The share of the summed "where" probabilities on +lines+, or all of it
|
|
342
|
+
# when nothing answered where.
|
|
343
|
+
def changed_share(spread, lines)
|
|
344
|
+
total = 0.0
|
|
345
|
+
changed = 0.0
|
|
346
|
+
spread.each do |place, value|
|
|
347
|
+
total += value
|
|
348
|
+
changed += value if lines.include?(place.delete_prefix("L").to_i)
|
|
349
|
+
end
|
|
350
|
+
total.positive? ? changed / total : 1.0
|
|
351
|
+
end
|
|
352
|
+
|
|
326
353
|
# The place with at least PLACE_AT of the summed "where" probabilities.
|
|
327
354
|
# A loop rather than max_by, which Spinel's Hash doesn't have yet.
|
|
328
355
|
def agreed(spread)
|
data/lib/judgelint/version.rb
CHANGED