Skip to content

Commit d2931f9

Browse files
committed
add test file
1 parent ec18d1b commit d2931f9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Batteries/Linter/TrailingWhitespace.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ def trailingWhitespaceLinter : Linter where run := withSetOptionIn fun stx => do
2929
return
3030
if (← get).messages.hasErrors then
3131
return
32-
let srg := stx.getRange?.getD default
32+
unless Parser.isTerminalCommand stx do return
3333
let fm ← getFileMap
3434
for lb in fm.positions do
35-
if srg.contains lb then
3635
let last : Substring := { str := fm.source, startPos := ⟨lb.1 - 2⟩, stopPos := ⟨lb.1 - 1⟩ }
3736
if last.toString == " " then
3837
Linter.logLint linter.trailingWhitespace (.ofRange ⟨⟨lb.1 - 2⟩, ⟨lb.1 - 1⟩⟩)
3938
m!"Lines should not end with a space."
40-
unless Parser.isTerminalCommand stx do return
4139
let (backBack, back) := (fm.positions.pop.back, fm.positions.back)
4240
let rg : String.Range := ⟨back - ⟨1⟩, back⟩
4341
if backBack != back then

test/TrailingWhitespace.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Batteries.Linter.TrailingWhitespace
2+
3+
set_option linter.trailingWhitespace false
4+
5+
section
6+
end
7+
/--
8+
warning: using 'exit' to interrupt Lean
9+
---
10+
warning: Lines should not end with a space.
11+
note: this linter can be disabled with `set_option linter.trailingWhitespace false`
12+
---
13+
warning: Files should end with a line-break.
14+
note: this linter can be disabled with `set_option linter.trailingWhitespace false`
15+
-/
16+
#guard_msgs in
17+
set_option linter.trailingWhitespace true in
18+
#exit

0 commit comments

Comments
 (0)