on master help sign in
Make sanity checking optional
commit53285db455f253ce65e9802bce55098d7bc3c021 authormrkkrp <mark.karpov@tweag.io> dateSun 24 Feb 2019, 21:27 (8 years ago) parentb2e05d6
2 files changed+11−5
src/Ormolu.hs+5−4 src/Ormolu/Config.hs+6−1
src/Ormolu.hs+5−4
@@ -49,10 +49,11 @@ ormolu cfg path str = do
4949 let txt = printModule anns0 parsedSrc0
5050 -- Parse the result of pretty-printing again and make sure that AST is the
5151 -- same as AST of original snippet module span positions.
52− (anns1, parsedSrc1) <-
53− parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
54− when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
55− liftIO $ throwIO (OrmoluASTDiffers str txt)
52+ when (cfgSanityCheck cfg) $ do
53+ (anns1, parsedSrc1) <-
54+ parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
55+ when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
56+ liftIO $ throwIO (OrmoluASTDiffers str txt)
5657 return txt
5758
5859-- | 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
1212
1313-- | Ormolu configuration.
1414
15−newtype Config = Config
15+data Config = Config
1616 { cfgDynOptions :: [DynOption]
1717 -- ^ 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.
1822 } deriving (Eq, Show)
1923
2024-- | Default 'Config'.
@@ -22,6 +26,7 @@ newtype Config = Config
2226defaultConfig :: Config
2327defaultConfig = Config
2428 { cfgDynOptions = []
29+ , cfgSanityCheck = True
2530 }
2631
2732-- | A wrapper for dynamic options.