ormolu-0.1.2.0: A formatter for Haskell source code

Safe Haskell | None
Language | Haskell2010

Ormolu

Description

A formatter for Haskell source code.

Synopsis

- ormolu :: MonadIO m => Config RegionIndices -> FilePath -> String -> m Text
- ormoluFile :: MonadIO m => Config RegionIndices -> FilePath -> m Text
- ormoluStdin :: MonadIO m => Config RegionIndices -> m Text
- data Config region = Config {
  - cfgDynOptions :: ![DynOption]
  - cfgUnsafe :: !Bool
  - cfgDebug :: !Bool
  - cfgCheckIdempotence :: !Bool
  - cfgRegion :: !region
  }
- data RegionIndices = RegionIndices {
  - regionStartLine :: !(Maybe Int)
  - regionEndLine :: !(Maybe Int)
  }
- defaultConfig :: Config RegionIndices
- newtype DynOption = DynOption {
  - unDynOption :: String
  }
- data OrmoluException
  - = OrmoluParsingFailed SrcSpan String
  - | OrmoluOutputParsingFailed SrcSpan String
  - | OrmoluASTDiffers FilePath [SrcSpan]
  - | OrmoluNonIdempotentOutput RealSrcLoc Text Text
  - | OrmoluUnrecognizedOpts (NonEmpty String)
- withPrettyOrmoluExceptions :: IO a -> IO a

# Documentation

ormolu Source #

Arguments

:: MonadIO m |
=> Config RegionIndices | 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 RegionIndices | 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 RegionIndices | Ormolu configuration
-> m Text | Resulting rendition

Read input from stdin and format it.

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

data Config region 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

- cfgCheckIdempotence :: !Bool

  Checks if re-formatting the result is idempotent

- cfgRegion :: !region

  Region selection

#### Instances

Instances details

Functor Config Source # |
Instance details Defined in Ormolu.Config Methods fmap :: (a -> b) -> Config a -> Config b Source # (<$) :: a -> Config b -> Config a Source #
Eq region => Eq (Config region) Source # |
Instance details Defined in Ormolu.Config Methods (==) :: Config region -> Config region -> Bool Source # (/=) :: Config region -> Config region -> Bool Source #
Show region => Show (Config region) Source # |
Instance details Defined in Ormolu.Config Methods showsPrec :: Int -> Config region -> ShowS Source # show :: Config region -> String Source # showList :: [Config region] -> ShowS Source #

data RegionIndices Source #

Region selection as the combination of start and end line numbers.

Constructors

RegionIndices |

Fields

- regionStartLine :: !(Maybe Int)

  Start line of the region to format

- regionEndLine :: !(Maybe Int)

  End line of the region to format

#### Instances

Instances details

Eq RegionIndices Source # |
Instance details Defined in Ormolu.Config Methods (==) :: RegionIndices -> RegionIndices -> Bool Source # (/=) :: RegionIndices -> RegionIndices -> Bool Source #
Show RegionIndices Source # |
Instance details Defined in Ormolu.Config Methods showsPrec :: Int -> RegionIndices -> ShowS Source # show :: RegionIndices -> String Source # showList :: [RegionIndices] -> ShowS Source #

defaultConfig :: Config RegionIndices Source #

Default ``Config` `RegionIndices``.

newtype DynOption Source #

A wrapper for dynamic options.

Constructors

DynOption |

Fields

- unDynOption :: String

#### Instances

Instances details

Eq DynOption Source # |
Instance details Defined in Ormolu.Config Methods (==) :: DynOption -> DynOption -> Bool Source # (/=) :: DynOption -> DynOption -> Bool Source #
Ord DynOption Source # |
Instance details Defined in Ormolu.Config Methods compare :: DynOption -> DynOption -> Ordering Source # (<) :: DynOption -> DynOption -> Bool Source # (<=) :: DynOption -> DynOption -> Bool Source # (>) :: DynOption -> DynOption -> Bool Source # (>=) :: DynOption -> DynOption -> Bool Source # max :: DynOption -> DynOption -> DynOption Source # min :: DynOption -> DynOption -> DynOption Source #
Show DynOption Source # |
Instance details Defined in Ormolu.Config Methods showsPrec :: Int -> DynOption -> ShowS Source # show :: DynOption -> String Source # showList :: [DynOption] -> ShowS Source #

data OrmoluException Source #

Ormolu exception representing all cases when Ormolu can fail.

Constructors

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

#### Instances

Instances details

Eq OrmoluException Source # |
Instance details Defined in Ormolu.Exception Methods (==) :: OrmoluException -> OrmoluException -> Bool Source # (/=) :: OrmoluException -> OrmoluException -> Bool Source #
Show OrmoluException Source # |
Instance details Defined in Ormolu.Exception Methods showsPrec :: Int -> OrmoluException -> ShowS Source # show :: OrmoluException -> String Source # showList :: [OrmoluException] -> ShowS Source #
Exception OrmoluException Source # |
Instance details Defined in Ormolu.Exception Methods toException :: OrmoluException -> SomeException Source # fromException :: SomeException -> Maybe OrmoluException Source # displayException :: OrmoluException -> String Source #

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`.