Skip to content

Commit 34b6ef3

Browse files
committed
fix line numbers; better iteration over the array
1 parent 4524784 commit 34b6ef3

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Mathlib/Tactic/Linter/TextBased.lean

+5-8
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,12 @@ def broadImportsLinter : TextbasedLinter := fun lines ↦ Id.run do
323323
def trailingWhitespaceLinter : TextbasedLinter := fun lines ↦ Id.run do
324324
let mut errors := Array.mkEmpty 0
325325
let mut fixedLines := lines
326-
-- invariant: this equals the current index of 'line' in 'lines',
327-
-- hence starts at 0 and is incremented *at the end* of the loop
328-
let mut lineNumber := 0
329-
for line in lines do
326+
for h : idx in [:lines.size] do
327+
let line := lines[idx]
330328
if line.back == ' ' then
331-
errors := errors.push (StyleError.trailingWhitespace, lineNumber)
332-
fixedLines := fixedLines.set! 0 (line.dropRightWhile (· == ' '))
333-
lineNumber := lineNumber + 1
334-
return (errors, fixedLines)
329+
errors := errors.push (StyleError.trailingWhitespace, idx + 1)
330+
fixedLines := fixedLines.set! idx (line.dropRightWhile (· == ' '))
331+
return (errors, if errors.size > 0 then some fixedLines else none)
335332

336333

337334
/-- Whether a collection of lines consists *only* of imports, blank lines and single-line comments.

0 commit comments

Comments
 (0)