@@ -22,7 +22,13 @@ import Common
22
22
hasSuffix :: Text -> Bool
23
23
hasSuffix fn = any (`T.isSuffixOf` fn) suffixes
24
24
where
25
- suffixes = T. words " .hs .hsc .lhs .cabal .c .h .lhs-boot .hs-boot .x .y"
25
+ suffixes = T. words " .hs .hsc .hsig .lhs .cabal .c .h .lhs-boot .hs-boot .x .y .T .script"
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 .stdin"
26
32
27
33
main :: IO ()
28
34
main = do
@@ -35,7 +41,8 @@ main = do
35
41
stats <- shelly $ forM (map T. pack refs) $ \ ref -> do
36
42
(cid,deltas) <- gitDiffTree dir ref
37
43
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))
39
46
then do
40
47
let blobIds0 = [ b0 | (GitTypeRegFile , b0, _) <- origs, b0 /= z40 ]
41
48
blob1 <- gitCatBlob dir blobId
@@ -98,6 +105,10 @@ lintBlob blobs0 blob1 = execWriter $ do
98
105
tell [ LintMsg LintLvlErr lno l " introduces trailing whitespace"
99
106
| (lno,l) <- zip [1 .. ] lns, hasTrail l ]
100
107
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
+
101
112
when (missingFinalEOL blob1) $ if not (any missingFinalEOL blobs0)
102
113
then tell [LintMsg LintLvlErr llno lln " lacking final EOL" ]
103
114
else tell [LintMsg LintLvlWarn llno lln " lacking final EOL" ]
@@ -120,6 +131,9 @@ lintBlob blobs0 blob1 = execWriter $ do
120
131
, " \t " `T.isSuffixOf` t
121
132
]
122
133
134
+ hasCRLF :: Text -> Bool
135
+ hasCRLF t = " \r\n " `T.isInfixOf` t || " \r " `T.isSuffixOf` t
136
+
123
137
missingFinalEOL :: Text -> Bool
124
138
missingFinalEOL = not . T. isSuffixOf " \n "
125
139
0 commit comments