Permalink
Browse files

Format output so it can be used by copen in vim

  • Loading branch information...
1 parent 87db8c2 commit 72a6810fe45dfe6323b0abd49666382d04a715dd @jaspervdj jaspervdj committed Oct 28, 2011
Showing with 20 additions and 18 deletions.
  1. +17 −16 src/HStyle.hs
  2. +3 −2 src/HStyle/Block.hs
View
@@ -20,17 +20,17 @@ import HStyle.Checker
-- | A selector and a check...
type Rule = (Selector, Checker)
-runRule :: Block -> H.Module H.SrcSpanInfo -> Rule -> IO ()
-runRule block md (selector, check) = forM_ (selector md block) $ \block' -> do
- let problems = check block'
- unless (null problems) $ do
- T.putStrLn $ T.replicate 78 "-"
- T.putStr $ prettyBlock block'
- T.putStrLn $ T.replicate 78 "-"
- forM_ problems $ \(i, problem) -> do
- let line = absoluteLineNumber i block'
- T.putStrLn $ T.pack (show line) `T.append` ": " `T.append` problem
- T.putStrLn ""
+runRule :: FilePath -> Block -> H.Module H.SrcSpanInfo -> Rule -> IO ()
+runRule file block md (selector, check) =
+ forM_ (selector md block) $ \block' -> do
+ let problems = check block'
+ forM_ problems $ \(i, problem) -> do
+ let line = absoluteLineNumber i block'
+ T.putStrLn $ T.pack file `T.append` ":" `T.append`
+ T.pack (show line) `T.append` ": " `T.append` problem
+ T.putStrLn ""
+ T.putStr $ prettyBlock 4 block'
+ T.putStrLn ""
fromSrcSpanInfo :: H.SrcSpanInfo -> Block -> Block
fromSrcSpanInfo ssi = subBlock start end
@@ -74,9 +74,10 @@ main = do
contents <- readFile file
let block = fromText $ T.pack contents
case H.parseModule contents of
- H.ParseOk md -> do
- runRule block md (typeSigSelector, typeSigCheck)
- runRule block md (selectLines, tabsCheck)
- runRule block md (selectLines, lineLengthCheck 80)
- runRule block md (selectLines, trailingWhiteSpace)
+ H.ParseOk md -> mapM_ (runRule file block md)
+ [ (typeSigSelector, typeSigCheck)
+ , (selectLines, tabsCheck)
+ , (selectLines, lineLengthCheck 80)
+ , (selectLines, trailingWhiteSpace)
+ ]
err -> putStrLn $ show err
View
@@ -26,8 +26,9 @@ fromText text = Block
, blockLines = V.fromList $ T.lines text
}
-prettyBlock :: Block -> Text
-prettyBlock block = T.unlines $ map pretty $
+prettyBlock :: Int -> Block -> Text
+prettyBlock indent block = T.unlines $
+ map ((T.replicate indent " " `T.append`) . pretty) $
zip [offset + 1 ..] $ V.toList lines'
where
offset = blockOffset block

0 comments on commit 72a6810

Please sign in to comment.