ormolu-0.7.4.0: A formatter for Haskell source code
Safe HaskellSafe-Inferred
LanguageGHC2021

Ormolu

Description

A formatter for Haskell source code. This module exposes the official stable API, other modules may be not as reliable.

Synopsis

Top-level formatting functions

ormolu Source #

Arguments

:: MonadIO m 
=> Config RegionIndices

Ormolu configuration

-> FilePath

Location of source file

-> Text

Input to format

-> m Text 

Format a Text.

The function

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

NOTE: The caller is responsible for setting the appropriate value in the cfgSourceType field. Autodetection of source type won't happen here, see detectSourceType.

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.

NOTE: The caller is responsible for setting the appropriate value in the cfgSourceType field. Autodetection of source type won't happen here, see detectSourceType.

ormoluStdin Source #

Arguments

:: MonadIO m 
=> Config RegionIndices

Ormolu configuration

-> m Text

Resulting rendition

Read input from stdin and format it.

NOTE: The caller is responsible for setting the appropriate value in the cfgSourceType field. Autodetection of source type won't happen here, see detectSourceType.

Configuration

data Config region Source #

Ormolu configuration.

Constructors

Config 

Fields

Instances

Instances details
Functor Config Source # 
Instance details

Defined in Ormolu.Config

Methods

fmap :: (a -> b) -> Config a -> Config b #

(<$) :: a -> Config b -> Config a #

Generic (Config region) Source # 
Instance details

Defined in Ormolu.Config

Associated Types

type Rep (Config region) :: Type -> Type #

Methods

from :: Config region -> Rep (Config region) x #

to :: Rep (Config region) x -> Config region #

Show region => Show (Config region) Source # 
Instance details

Defined in Ormolu.Config

Methods

showsPrec :: Int -> Config region -> ShowS #

show :: Config region -> String #

showList :: [Config region] -> ShowS #

Eq region => Eq (Config region) Source # 
Instance details

Defined in Ormolu.Config

Methods

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

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

type Rep (Config region) Source # 
Instance details

Defined in Ormolu.Config

data ColorMode Source #

Whether to use colors and other features of ANSI terminals.

Constructors

Never 
Always 
Auto 

Instances

Instances details
Show ColorMode Source # 
Instance details

Defined in Ormolu.Terminal

Eq ColorMode Source # 
Instance details

Defined in Ormolu.Terminal

data RegionIndices Source #

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

Constructors

RegionIndices 

Fields

Instances

Instances details
Show RegionIndices Source # 
Instance details

Defined in Ormolu.Config

Eq RegionIndices Source # 
Instance details

Defined in Ormolu.Config

data SourceType Source #

Type of sources that can be formatted by Ormolu.

Constructors

ModuleSource

Consider the input as a regular Haskell module

SignatureSource

Consider the input as a Backpack module signature

Instances

Instances details
Show SourceType Source # 
Instance details

Defined in Ormolu.Config

Eq SourceType Source # 
Instance details

Defined in Ormolu.Config

detectSourceType :: FilePath -> SourceType Source #

Detect SourceType based on the file extension.

refineConfig Source #

Arguments

:: SourceType

Source type to use

-> Maybe CabalInfo

Cabal info for the file, if available

-> Maybe FixityOverrides

Fixity overrides, if available

-> Maybe ModuleReexports

Module re-exports, if available

-> Config region

Config to refine

-> Config region

Refined Config

Refine a Config by incorporating given SourceType, CabalInfo, and fixity overrides FixityMap. You can use detectSourceType to deduce SourceType based on the file extension, getCabalInfoForSourceFile to obtain CabalInfo and getFixityOverridesForSourceFile for FixityMap.

Since: 0.5.3.0

newtype DynOption Source #

A wrapper for dynamic options.

Constructors

DynOption 

Fields

Instances

Instances details
Show DynOption Source # 
Instance details

Defined in Ormolu.Config

Eq DynOption Source # 
Instance details

Defined in Ormolu.Config

Ord DynOption Source # 
Instance details

Defined in Ormolu.Config

Cabal info

data CabalSearchResult Source #

The result of searching for a .cabal file.

Since: 0.5.3.0

Constructors

CabalNotFound

Cabal file could not be found

CabalDidNotMention CabalInfo

Cabal file was found, but it did not mention the source file in question

CabalFound CabalInfo

Cabal file was found and it mentions the source file in question

data CabalInfo Source #

Cabal information of interest to Ormolu.

Constructors

CabalInfo 

Fields

Instances

Instances details
Show CabalInfo Source # 
Instance details

Defined in Ormolu.Utils.Cabal

Eq CabalInfo Source # 
Instance details

Defined in Ormolu.Utils.Cabal

getCabalInfoForSourceFile Source #

Arguments

:: MonadIO m 
=> FilePath

Haskell source file

-> m CabalSearchResult

Extracted cabal info, if any

Locate a .cabal file corresponding to the given Haskell source file and obtain CabalInfo from it.

Fixity overrides and module re-exports

data FixityOverrides Source #

Map from the operator name to its FixityInfo.

defaultFixityOverrides :: FixityOverrides Source #

Fixity overrides to use by default.

data ModuleReexports Source #

Module re-exports

defaultModuleReexports :: ModuleReexports Source #

Module re-exports to apply by default.

getDotOrmoluForSourceFile Source #

Arguments

:: MonadIO m 
=> FilePath

CabalInfo already obtained for this source file

-> m (FixityOverrides, ModuleReexports) 

Attempt to locate and parse an .ormolu file. If it does not exist, default fixity map and module reexports are returned. This function maintains a cache of fixity overrides and module re-exports where cabal file paths act as keys.

Working with exceptions

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 TextDiff [RealSrcSpan]

Original and resulting ASTs differ

OrmoluNonIdempotentOutput TextDiff

Formatted source code is not idempotent

OrmoluUnrecognizedOpts (NonEmpty String)

Some GHC options were not recognized

OrmoluCabalFileParsingFailed FilePath (NonEmpty PError)

Cabal file parsing failed

OrmoluMissingStdinInputFile

Missing input file path when using stdin input and accounting for .cabal files

OrmoluFixityOverridesParseError (ParseErrorBundle Text Void)

A parse error in a fixity overrides file

withPrettyOrmoluExceptions Source #

Arguments

:: ColorMode

Color mode

-> IO ExitCode

Action that may throw an exception

-> IO ExitCode 

Inside this wrapper OrmoluException will be caught and displayed nicely.