@@ -22,7 +22,13 @@ import Common
2222hasSuffix :: Text -> Bool
2323hasSuffix fn = any (`T.isSuffixOf` fn) suffixes
2424 where
25- suffixes = T. words " .hs .hsc .lhs .cabal .c .h .lhs-boot .hs-boot .x .y"
25+ suffixes = T. words " .hs .hsc .lhs .cabal .c .h .lhs-boot .hs-boot .x .y .T"
26+
27+ hasInfix :: Text -> Bool
28+ hasInfix fn = any (`T.isInfixOf` fn) infixes
29+ where
30+ -- Use isInfixOf to also catch *.stderr-mingw32, *.stderr-ws-64 etc.
31+ infixes = T. words " .stdout .stderr"
2632
2733main :: IO ()
2834main = do
@@ -35,7 +41,8 @@ main = do
3541 stats <- shelly $ forM (map T. pack refs) $ \ ref -> do
3642 (cid,deltas) <- gitDiffTree dir ref
3743
38- lintMsgs0 <- forM deltas $ \ (origs, (gt, blobId), fname) -> if (gt == GitTypeRegFile && hasSuffix fname)
44+ lintMsgs0 <- forM deltas $ \ (origs, (gt, blobId), fname)
45+ -> if (gt == GitTypeRegFile && (hasSuffix fname || hasInfix fname))
3946 then do
4047 let blobIds0 = [ b0 | (GitTypeRegFile , b0, _) <- origs, b0 /= z40 ]
4148 blob1 <- gitCatBlob dir blobId
@@ -98,6 +105,10 @@ lintBlob blobs0 blob1 = execWriter $ do
98105 tell [ LintMsg LintLvlErr lno l " introduces trailing whitespace"
99106 | (lno,l) <- zip [1 .. ] lns, hasTrail l ]
100107
108+ when (hasCRLF blob1 && not (any hasCRLF blobs0)) $ do
109+ tell [ LintMsg LintLvlErr lno l " introduces Windows line ending"
110+ | (lno,l) <- zip [1 .. ] lns, hasCRLF l ]
111+
101112 when (missingFinalEOL blob1) $ if not (any missingFinalEOL blobs0)
102113 then tell [LintMsg LintLvlErr llno lln " lacking final EOL" ]
103114 else tell [LintMsg LintLvlWarn llno lln " lacking final EOL" ]
@@ -120,6 +131,9 @@ lintBlob blobs0 blob1 = execWriter $ do
120131 , " \t " `T.isSuffixOf` t
121132 ]
122133
134+ hasCRLF :: Text -> Bool
135+ hasCRLF t = " \r\n " `T.isInfixOf` t || " \r " `T.isSuffixOf` t
136+
123137 missingFinalEOL :: Text -> Bool
124138 missingFinalEOL = not . T. isSuffixOf " \n "
125139
0 commit comments