forked from ndmitchell/hlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
44 lines (36 loc) · 1.17 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Main where
import Control.Arrow
import Control.Monad
import Data.List
import System.Directory
import Data.Generics.PlateData
import CmdLine
import Settings
import Report
import Type
import Test
import HSE.All
import Hint.All
import Paths_hlint
main = do
mode <- getMode
if modeTest mode then test else do
settings <- readSettings $ modeHints mode
let ignore idea = let f = classify settings in f idea == Skip
let hints = readHints settings
ideas <- liftM concat $ mapM (runFile ignore hints) (modeFiles mode)
let n = length ideas
if n == 0 then do
when (not $ null $ modeReports mode) $ putStrLn "Skipping writing reports"
putStrLn "No relevant suggestions"
else do
flip mapM_ (modeReports mode) $ \x -> do
putStrLn $ "Writing report to " ++ x ++ " ..."
writeReport x ideas
putStrLn $ "Found " ++ show n ++ " suggestions"
runFile :: (Idea -> Bool) -> Hint -> FilePath -> IO [Idea]
runFile ignore hint file = do
src <- parseFile file
let ideas = filter (not . ignore) $ applyHint hint src
mapM_ print ideas
return ideas