diff --git a/src/validate-whitespace.hs b/src/validate-whitespace.hs index 5fbd46b..e5799f2 100644 --- a/src/validate-whitespace.hs +++ b/src/validate-whitespace.hs @@ -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 @@ -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"] @@ -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"