Skip to content

Commit

Permalink
fix line numbers; better iteration over the array
Browse files Browse the repository at this point in the history
  • Loading branch information
grunweg committed Sep 5, 2024
1 parent 4524784 commit 34b6ef3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Mathlib/Tactic/Linter/TextBased.lean
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,12 @@ def broadImportsLinter : TextbasedLinter := fun lines ↦ Id.run do
def trailingWhitespaceLinter : TextbasedLinter := fun lines ↦ Id.run do
let mut errors := Array.mkEmpty 0
let mut fixedLines := lines
-- invariant: this equals the current index of 'line' in 'lines',
-- hence starts at 0 and is incremented *at the end* of the loop
let mut lineNumber := 0
for line in lines do
for h : idx in [:lines.size] do
let line := lines[idx]
if line.back == ' ' then
errors := errors.push (StyleError.trailingWhitespace, lineNumber)
fixedLines := fixedLines.set! 0 (line.dropRightWhile (· == ' '))
lineNumber := lineNumber + 1
return (errors, fixedLines)
errors := errors.push (StyleError.trailingWhitespace, idx + 1)
fixedLines := fixedLines.set! idx (line.dropRightWhile (· == ' '))
return (errors, if errors.size > 0 then some fixedLines else none)


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

0 comments on commit 34b6ef3

Please sign in to comment.