Skip to content
This repository has been archived by the owner on Jun 9, 2019. It is now read-only.

Commit

Permalink
Check for CRLF, and add .stdout/stderr to suffixes
Browse files Browse the repository at this point in the history
Fixes #5.
  • Loading branch information
thomie committed Feb 23, 2016
1 parent 5e2e6c8 commit d9917b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/validate-whitespace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Common
hasSuffix :: Text -> Bool
hasSuffix fn = any (`T.isSuffixOf` fn) suffixes
where
suffixes = T.words ".hs .hsc .lhs .cabal .c .h .lhs-boot .hs-boot .x .y"
suffixes = T.words ".hs .hsc .lhs .cabal .c .h .lhs-boot .hs-boot .x .y .stdout .stderr"

main :: IO ()
main = do
Expand Down Expand Up @@ -98,6 +98,10 @@ lintBlob blobs0 blob1 = execWriter $ do
tell [ LintMsg LintLvlErr lno l "introduces trailing whitespace"
| (lno,l) <- zip [1..] lns, hasTrail l ]

when (hasCRLF blob1 && not (any hasCRLF blobs0)) $ do
tell [ LintMsg LintLvlErr lno l "introduces Windows line ending"
| (lno,l) <- zip [1..] lns, hasCRLF l ]

when (missingFinalEOL blob1) $ if not (any missingFinalEOL blobs0)
then tell [LintMsg LintLvlErr llno lln "lacking final EOL"]
else tell [LintMsg LintLvlWarn llno lln "lacking final EOL"]
Expand All @@ -120,6 +124,9 @@ lintBlob blobs0 blob1 = execWriter $ do
, "\t" `T.isSuffixOf` t
]

hasCRLF :: Text -> Bool
hasCRLF t = "\r\n" `T.isInfixOf` t || "\r" `T.isSuffixOf` t

missingFinalEOL :: Text -> Bool
missingFinalEOL = not . T.isSuffixOf "\n"

Expand Down

0 comments on commit d9917b5

Please sign in to comment.