1
1
mirror of https://github.com/google/ormolu.git synced 2024-11-23 22:27:16 +03:00

Make sanity checking optional

This commit is contained in:
mrkkrp 2019-02-24 21:27:41 +01:00 committed by Mark Karpov
parent b2e05d6f65
commit 53285db455
2 changed files with 11 additions and 5 deletions

View File

@ -49,10 +49,11 @@ ormolu cfg path str = do
let txt = printModule anns0 parsedSrc0
-- Parse the result of pretty-printing again and make sure that AST is the
-- same as AST of original snippet module span positions.
(anns1, parsedSrc1) <-
parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
liftIO $ throwIO (OrmoluASTDiffers str txt)
when (cfgSanityCheck cfg) $ do
(anns1, parsedSrc1) <-
parseModule' cfg OrmoluOutputParsingFailed "<rendered>" (T.unpack txt)
when (diff (anns0, parsedSrc0) (anns1, parsedSrc1)) $
liftIO $ throwIO (OrmoluASTDiffers str txt)
return txt
-- | Load a file and format it. The file stays intact and the rendered

View File

@ -12,9 +12,13 @@ import qualified SrcLoc as GHC
-- | Ormolu configuration.
newtype Config = Config
data Config = Config
{ cfgDynOptions :: [DynOption]
-- ^ Dynamic options to pass to GHC parser
, cfgSanityCheck :: Bool
-- ^ Whether to parse output of formatter and compare the obtained AST
-- with original AST. Doing this makes the program much slower, but
-- it'll catch and report all possible issues.
} deriving (Eq, Show)
-- | Default 'Config'.
@ -22,6 +26,7 @@ newtype Config = Config
defaultConfig :: Config
defaultConfig = Config
{ cfgDynOptions = []
, cfgSanityCheck = True
}
-- | A wrapper for dynamic options.