on master help sign in
Make sanity checking optional
53285dbmrkkrp
src/Ormolu.hs+5−4
@@ -49,10 +49,11 @@ ormolu cfg path str = do
49 let txt = printModule anns0 parsedSrc0
49 let txt = printModule anns0 parsedSrc0
50 -- Parse the result of pretty-printing again and make sure that AST is the
50 -- Parse the result of pretty-printing again and make sure that AST is the
51 -- same as AST of original snippet module span positions.
51 -- same as AST of original snippet module span positions.
52+ when (cfgSanityCheck cfg) $ do
52− (anns1, parsedSrc1) <-
53+ (anns1, parsedSrc1) <-
53− parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
54+ parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
54− when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
55+ when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
55− liftIO $ throwIO (OrmoluASTDiffers str txt)
56+ liftIO $ throwIO (OrmoluASTDiffers str txt)
56 return txt
57 return txt
57
58
58-- | Load a file and format it. The file stays intact and the rendered
59-- | Load a file and format it. The file stays intact and the rendered
src/Ormolu/Config.hs+6−1
@@ -12,9 +12,13 @@ import qualified SrcLoc as GHC
12
12
13-- | Ormolu configuration.
13-- | Ormolu configuration.
14
14
15−newtype Config = Config
15+data Config = Config
16 { cfgDynOptions :: [DynOption]
16 { cfgDynOptions :: [DynOption]
17 -- ^ Dynamic options to pass to GHC parser
17 -- ^ Dynamic options to pass to GHC parser
18+ , cfgSanityCheck :: Bool
19+ -- ^ Whether to parse output of formatter and compare the obtained AST
20+ -- with original AST. Doing this makes the program much slower, but
21+ -- it'll catch and report all possible issues.
18 } deriving (Eq, Show)
22 } deriving (Eq, Show)
19
23
20-- | Default 'Config'.
24-- | Default 'Config'.
@@ -22,6 +26,7 @@ newtype Config = Config
22defaultConfig :: Config
26defaultConfig :: Config
23defaultConfig = Config
27defaultConfig = Config
24 { cfgDynOptions = []
28 { cfgDynOptions = []
29+ , cfgSanityCheck = True
25 }
30 }
26
31
27-- | A wrapper for dynamic options.
32-- | A wrapper for dynamic options.