Permalink
Browse files

Further work on fixing errors

  • Loading branch information...
jaspervdj committed Oct 30, 2011
1 parent b55471d commit 78e321ce9eac68f154f4d65288845a58d0d18857
Showing with 14 additions and 7 deletions.
  1. +10 −7 src/HStyle.hs
  2. +4 −0 src/HStyle/Block.hs
View
@@ -5,7 +5,7 @@ module HStyle
, fixStyle
) where
-import Control.Monad (foldM, forM_, unless)
+import Control.Monad (foldM, forM_, unless, when)
import Data.Char (isSpace)
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
@@ -118,12 +118,15 @@ checkStyle quiet file = do
contents' = if H.CPP `elem` exts then unCPP contents else contents
fs = FileState block False True
case H.parseModuleWithMode mode contents' of
- H.ParseOk md -> foldM (runRule quiet file md) fs
- [ (typeSigSelector, typeSigCheck, fixNothing)
- , (selectLines, tabsCheck, fixNothing)
- , (selectLines, lineLengthCheck 78, fixNothing)
- , (selectLines, trailingWhiteSpace, trailingWhiteSpaceFixer)
- ]
+ H.ParseOk md -> do
+ fs' <- foldM (runRule quiet file md) fs
+ [ (typeSigSelector, typeSigCheck, fixNothing)
+ , (selectLines, tabsCheck, fixNothing)
+ , (selectLines, lineLengthCheck 78, fixNothing)
+ , (selectLines, trailingWhiteSpace, trailingWhiteSpaceFixer)
+ ]
+ when (fileUpdated fs') $ T.writeFile file $ toText $ fileBlock fs'
+ return fs'
err -> do
putStrLn $ "HStyle.checkStyle: could not parse " ++
file ++ ": " ++ show err
View
@@ -3,6 +3,7 @@
module HStyle.Block
( Block
, fromText
+ , toText
, prettyBlock
, toLines
, subBlock
@@ -28,6 +29,9 @@ fromText text = Block
, blockLines = V.fromList $ T.lines text
}
+toText :: Block -> Text
+toText = T.unlines . toLines
+
prettyBlock :: Int -> Block -> Text
prettyBlock indent block = T.unlines $
map ((T.replicate indent " " `T.append`) . pretty) $

0 comments on commit 78e321c

Please sign in to comment.