1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Check.Src.TrailingSpace where

import List      (last)

import Curry.Position
import Curry.Span
import Text.Pretty

import Types
import State

--Check for each line, if the last character is a space, in this case get the
--number of them (by reversing the line) and report
checkTSpaces :: SrcLine -> CSM ()
checkTSpaces (n,l) = do
  whenM ((last l) == ' ')
        (do let endPos = length l
                startPos = endPos - (length (takeWhile (\ x -> x == ' ') ( reverse l))) + 1
                posDif = endPos - startPos
                sp = "space" ++ (if posDif > 1 then "s" else "")
            (report (Message
                      (Span
                        (Position n startPos)
                        (Position n endPos))
                      ( colorizeKey (show (endPos - startPos))
                        <+> text "trailing"
                        <+> colorizeKey sp
                        <+> text "found")
                      ( text "delete"
                        <+> colorizeKey sp
                        <+> text "at end of line"))))