ormolu-0.0.3.1: A formatter for Haskell source code

Safe HaskellNone
LanguageHaskell2010

Ormolu

Description

A formatter for Haskell source code.

Synopsis

Documentation

ormolu Source #

Arguments

:: MonadIO m 
=> Config

Ormolu configuration

-> FilePath

Location of source file

-> String

Input to format

-> m Text 

Format a String, return formatted version as Text.

The function

  • Takes String because that's what GHC parser accepts.
  • Needs IO because some functions from GHC that are necessary to setup parsing context require IO. There should be no visible side-effects though.
  • Takes file name just to use it in parse error messages.
  • Throws OrmoluException.

ormoluFile Source #

Arguments

:: MonadIO m 
=> Config

Ormolu configuration

-> FilePath

Location of source file

-> m Text

Resulting rendition

Load a file and format it. The file stays intact and the rendered version is returned as Text.

ormoluFile cfg path =
  liftIO (readFile path) >>= ormolu cfg path

ormoluStdin Source #

Arguments

:: MonadIO m 
=> Config

Ormolu configuration

-> m Text

Resulting rendition

Read input from stdin and format it.

ormoluStdin cfg =
  liftIO (hGetContents stdin) >>= ormolu cfg "<stdin>"

data Config Source #

Ormolu configuration.

Constructors

Config 

Fields

  • cfgDynOptions :: ![DynOption]

    Dynamic options to pass to GHC parser

  • cfgUnsafe :: !Bool

    Do formatting faster but without automatic detection of defects

  • cfgDebug :: !Bool

    Output information useful for debugging

  • cfgTolerateCpp :: !Bool

    Do not fail if CPP pragma is present (still doesn't handle CPP but useful for formatting of files that enable the extension without actually containing CPP macros)

  • cfgCheckIdempotency :: !Bool

    Checks if re-formatting the result is idempotent.

Instances
Eq Config Source # 
Instance details

Defined in Ormolu.Config

Methods

(==) :: Config -> Config -> Bool #

(/=) :: Config -> Config -> Bool #

Show Config Source # 
Instance details

Defined in Ormolu.Config

newtype DynOption Source #

A wrapper for dynamic options.

Constructors

DynOption 

Fields

Instances
Eq DynOption Source # 
Instance details

Defined in Ormolu.Config

Ord DynOption Source # 
Instance details

Defined in Ormolu.Config

Show DynOption Source # 
Instance details

Defined in Ormolu.Config

data OrmoluException Source #

Ormolu exception representing all cases when Ormolu can fail.

Constructors

OrmoluCppEnabled FilePath

Ormolu does not work with source files that use CPP

OrmoluParsingFailed SrcSpan String

Parsing of original source code failed

OrmoluOutputParsingFailed SrcSpan String

Parsing of formatted source code failed

OrmoluASTDiffers FilePath [SrcSpan]

Original and resulting ASTs differ

OrmoluNonIdempotentOutput RealSrcLoc Text Text

Formatted source code is not idempotent

OrmoluUnrecognizedOpts (NonEmpty String)

Some GHC options were not recognized

withPrettyOrmoluExceptions Source #

Arguments

:: IO a

Action that may throw the exception

-> IO a 

Inside this wrapper OrmoluException will be caught and displayed nicely using displayException.