Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Format output so it can be used by copen in vim

  • Loading branch information...
commit 72a6810fe45dfe6323b0abd49666382d04a715dd 1 parent 87db8c2
Jasper Van der Jeugt jaspervdj authored

Showing 2 changed files with 20 additions and 18 deletions. Show diff stats Hide diff stats

  1. +17 16 src/HStyle.hs
  2. +3 2 src/HStyle/Block.hs
33 src/HStyle.hs
@@ -20,17 +20,17 @@ import HStyle.Checker
20 20 -- | A selector and a check...
21 21 type Rule = (Selector, Checker)
22 22
23   -runRule :: Block -> H.Module H.SrcSpanInfo -> Rule -> IO ()
24   -runRule block md (selector, check) = forM_ (selector md block) $ \block' -> do
25   - let problems = check block'
26   - unless (null problems) $ do
27   - T.putStrLn $ T.replicate 78 "-"
28   - T.putStr $ prettyBlock block'
29   - T.putStrLn $ T.replicate 78 "-"
30   - forM_ problems $ \(i, problem) -> do
31   - let line = absoluteLineNumber i block'
32   - T.putStrLn $ T.pack (show line) `T.append` ": " `T.append` problem
33   - T.putStrLn ""
  23 +runRule :: FilePath -> Block -> H.Module H.SrcSpanInfo -> Rule -> IO ()
  24 +runRule file block md (selector, check) =
  25 + forM_ (selector md block) $ \block' -> do
  26 + let problems = check block'
  27 + forM_ problems $ \(i, problem) -> do
  28 + let line = absoluteLineNumber i block'
  29 + T.putStrLn $ T.pack file `T.append` ":" `T.append`
  30 + T.pack (show line) `T.append` ": " `T.append` problem
  31 + T.putStrLn ""
  32 + T.putStr $ prettyBlock 4 block'
  33 + T.putStrLn ""
34 34
35 35 fromSrcSpanInfo :: H.SrcSpanInfo -> Block -> Block
36 36 fromSrcSpanInfo ssi = subBlock start end
@@ -74,9 +74,10 @@ main = do
74 74 contents <- readFile file
75 75 let block = fromText $ T.pack contents
76 76 case H.parseModule contents of
77   - H.ParseOk md -> do
78   - runRule block md (typeSigSelector, typeSigCheck)
79   - runRule block md (selectLines, tabsCheck)
80   - runRule block md (selectLines, lineLengthCheck 80)
81   - runRule block md (selectLines, trailingWhiteSpace)
  77 + H.ParseOk md -> mapM_ (runRule file block md)
  78 + [ (typeSigSelector, typeSigCheck)
  79 + , (selectLines, tabsCheck)
  80 + , (selectLines, lineLengthCheck 80)
  81 + , (selectLines, trailingWhiteSpace)
  82 + ]
82 83 err -> putStrLn $ show err
5 src/HStyle/Block.hs
@@ -26,8 +26,9 @@ fromText text = Block
26 26 , blockLines = V.fromList $ T.lines text
27 27 }
28 28
29   -prettyBlock :: Block -> Text
30   -prettyBlock block = T.unlines $ map pretty $
  29 +prettyBlock :: Int -> Block -> Text
  30 +prettyBlock indent block = T.unlines $
  31 + map ((T.replicate indent " " `T.append`) . pretty) $
31 32 zip [offset + 1 ..] $ V.toList lines'
32 33 where
33 34 offset = blockOffset block

0 comments on commit 72a6810

Please sign in to comment.
Something went wrong with that request. Please try again.