hstyle 0.2.0.1 → 0.2.0.2
raw patch · 2 files changed
+19/−3 lines, 2 files
Files
- hstyle.cabal +1/−1
- src/HStyle.hs +18/−2
hstyle.cabal view
@@ -1,5 +1,5 @@ Name: hstyle-Version: 0.2.0.1+Version: 0.2.0.2 Synopsis: Checks Haskell source code for style compliance. Description: Originally intended to automate style checking for the Snap project. But the project should be general enough to work
src/HStyle.hs view
@@ -7,6 +7,8 @@ import Control.Applicative ((<$>)) import Control.Monad (forM, forM_) import Data.Char (isSpace)+import Data.List (isPrefixOf)+import Data.Maybe (fromMaybe) import qualified Data.Text as T import qualified Data.Text.IO as T@@ -69,11 +71,25 @@ then Just "trailing whitespace" else Nothing +-- | Filter out lines which use CPP macros+unCPP :: String -> String+unCPP = unlines . map unCpp' . lines+ where+ unCpp' x+ | "#" `isPrefixOf` x = ""+ | otherwise = x+ checkStyle :: FilePath -> IO Bool checkStyle file = do contents <- readFile file- let block = fromText $ T.pack contents- case H.parseModule contents of+ let block = fromText $ T.pack contents+ -- Determine the extensions used in the file, and update the parsing+ -- mode based upon those+ exts = fromMaybe [] $ H.readExtensions contents+ mode = H.defaultParseMode {H.extensions = exts}+ -- Special handling for CPP, haskell-src-exts can't deal with it+ contents' = if H.CPP `elem` exts then unCPP contents else contents+ case H.parseModuleWithMode mode contents' of H.ParseOk md -> and <$> mapM (runRule file block md) [ (typeSigSelector, typeSigCheck) , (selectLines, tabsCheck)