File tree 6 files changed +47
-41
lines changed
6 files changed +47
-41
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ executable hlint
40
40
Report
41
41
Type
42
42
Test
43
+ Util
43
44
HSE.All
44
45
HSE.Bracket
45
46
HSE.Evaluate
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import System.Exit
11
11
import System.FilePath
12
12
import HSE.All
13
13
14
+ import Util
14
15
import Paths_hlint
15
16
import Data.Version
16
17
@@ -89,29 +90,3 @@ getFile file = do
89
90
b <- doesFileExist file
90
91
when (not b) $ error $ " Couldn't find file: " ++ file
91
92
return [file]
92
-
93
-
94
- getDirectoryContentsRecursive :: FilePath -> IO [FilePath ]
95
- getDirectoryContentsRecursive dir = do
96
- xs <- getDirectoryContents dir
97
- (dirs,files) <- partitionM doesDirectoryExist [dir </> x | x <- xs, not $ isBadDir x]
98
- rest <- concatMapM getDirectoryContentsRecursive dirs
99
- return $ files++ rest
100
-
101
-
102
- partitionM :: Monad m => (a -> m Bool ) -> [a ] -> m ([a ], [a ])
103
- partitionM f [] = return ([] , [] )
104
- partitionM f (x: xs) = do
105
- res <- f x
106
- (as,bs) <- partitionM f xs
107
- return ([x |res]++as, [x|not res]++bs)
108
-
109
-
110
- concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
111
- concatMapM f = liftM concat . mapM f
112
-
113
-
114
- isBadDir :: FilePath -> Bool
115
- isBadDir x = "." `isPrefixOf` x || "_" `isPrefixOf` x
116
-
117
-
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import HSE.Evaluate
15
15
import HSE.Bracket
16
16
import HSE.Match
17
17
import HSE.Operators
18
-
18
+ import Util
19
19
20
20
21
21
-- | On failure returns an empty module and prints to the console
Original file line number Diff line number Diff line change @@ -7,19 +7,7 @@ import Data.Generics.PlateData
7
7
import Data.List
8
8
import Data.Maybe
9
9
import Language.Haskell.Exts
10
-
11
-
12
- ---------------------------------------------------------------------
13
- -- GENERAL FUNCTIONS
14
-
15
- headDef :: a -> [a ] -> a
16
- headDef x [] = x
17
- headDef x (y: ys) = y
18
-
19
-
20
- limit :: Int -> String -> String
21
- limit n s = if null post then s else pre ++ " ..."
22
- where (pre,post) = splitAt n s
10
+ import Util
23
11
24
12
25
13
---------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import Settings
14
14
import Report
15
15
import Type
16
16
import Test
17
+ import Util
17
18
import HSE.All
18
19
import Hint.All
19
20
import Paths_hlint
@@ -25,7 +26,7 @@ main = do
25
26
settings <- readSettings cmdHintFiles
26
27
let extra = [Classify (" " ," " ) Ignore x | x <- cmdIgnore]
27
28
let apply = map (classify $ settings ++ extra) . applyHint (readHints settings)
28
- ideas <- liftM concat $ mapM (liftM apply . parseFile) cmdFiles
29
+ ideas <- concatMapM (liftM apply . parseFile) cmdFiles
29
30
mapM_ print [i | i <- ideas, cmdShowAll || rank i /= Ignore ]
30
31
31
32
-- figure out statistics
Original file line number Diff line number Diff line change
1
+
2
+ module Util where
3
+
4
+ import Control.Monad
5
+ import Data.List
6
+ import System.Directory
7
+ import System.FilePath
8
+
9
+
10
+ getDirectoryContentsRecursive :: FilePath -> IO [FilePath ]
11
+ getDirectoryContentsRecursive dir = do
12
+ xs <- getDirectoryContents dir
13
+ (dirs,files) <- partitionM doesDirectoryExist [dir </> x | x <- xs, not $ isBadDir x]
14
+ rest <- concatMapM getDirectoryContentsRecursive dirs
15
+ return $ files++ rest
16
+ where
17
+ isBadDir x = " ." `isPrefixOf` x || " _" `isPrefixOf` x
18
+
19
+
20
+ partitionM :: Monad m => (a -> m Bool ) -> [a ] -> m ([a ], [a ])
21
+ partitionM f [] = return ([] , [] )
22
+ partitionM f (x: xs) = do
23
+ res <- f x
24
+ (as,bs) <- partitionM f xs
25
+ return ([x |res]++as, [x|not res]++bs)
26
+
27
+
28
+ concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
29
+ concatMapM f = liftM concat . mapM f
30
+
31
+
32
+ headDef :: a -> [a] -> a
33
+ headDef x [] = x
34
+ headDef x (y:ys) = y
35
+
36
+
37
+ limit :: Int -> String -> String
38
+ limit n s = if null post then s else pre ++ "..."
39
+ where (pre,post) = splitAt n s
40
+
41
+
You can’t perform that action at this time.
0 commit comments