summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasperVanDerJeugt <>2011-10-29 10:21:42 (GMT)
committerhdiff <hdiff@luite.com>2011-10-29 10:21:42 (GMT)
commitb1399b052dc6b1e0846fd0510704255af4aa6465 (patch)
tree66681180545fcdc2fbf70e90df9fa92edc6b7fed /src
parent0d0b8804aeb0d767de52d89abb7b0581fea87e9a (diff)
version 0.2.0.20.2.0.2
Diffstat (limited to 'src')
-rw-r--r--src/HStyle.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/HStyle.hs b/src/HStyle.hs
index 33f7f8d..95762a9 100644
--- a/src/HStyle.hs
+++ b/src/HStyle.hs
@@ -7,6 +7,8 @@ module HStyle
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 @@ trailingWhiteSpace = checkLines $ \line ->
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)