Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- cfgColorMode :: !ColorMode
- cfgRegion :: !region
- cfgPrinterOpts :: !PrinterOptsTotal
- data ColorMode
- data RegionIndices = RegionIndices {
- regionStartLine :: !(Maybe Int)
- regionEndLine :: !(Maybe Int)
- defaultConfig :: Config RegionIndices
- newtype DynOption = DynOption {}
- data PrinterOpts f = PrinterOpts {
- poIndentation :: f Int
- poCommaStyle :: f CommaStyle
- poIndentWheres :: f Bool
- poRecordBraceSpace :: f Bool
- poDiffFriendlyImportExport :: f Bool
- poRespectful :: f Bool
- poHaddockStyle :: f HaddockPrintStyle
- poNewlinesBetweenDecls :: f Int
- type PrinterOptsPartial = PrinterOpts Maybe
- type PrinterOptsTotal = PrinterOpts Identity
- defaultPrinterOpts :: PrinterOptsTotal
- loadConfigFile :: FilePath -> IO ConfigFileLoadResult
- data ConfigFileLoadResult
- configFileName :: FilePath
- fillMissingPrinterOpts :: forall f. Applicative f => PrinterOptsPartial -> PrinterOpts f -> PrinterOpts f
- data OrmoluException
- withPrettyOrmoluExceptions :: ColorMode -> IO ExitCode -> IO ExitCode
Documentation
:: 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 requireIO
. There should be no visible side-effects though. - Takes file name just to use it in parse error messages.
- Throws
OrmoluException
.
:: 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
:: 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>"
Ormolu configuration.
Config | |
|
Whether to use colors and other features of ANSI terminals.
Instances
Bounded ColorMode Source # | |
Enum ColorMode Source # | |
Defined in Ormolu.Terminal succ :: ColorMode -> ColorMode # pred :: ColorMode -> ColorMode # fromEnum :: ColorMode -> Int # enumFrom :: ColorMode -> [ColorMode] # enumFromThen :: ColorMode -> ColorMode -> [ColorMode] # enumFromTo :: ColorMode -> ColorMode -> [ColorMode] # enumFromThenTo :: ColorMode -> ColorMode -> ColorMode -> [ColorMode] # | |
Eq ColorMode Source # | |
Show ColorMode Source # | |
data RegionIndices Source #
Region selection as the combination of start and end line numbers.
RegionIndices | |
|
Instances
Eq RegionIndices Source # | |
Defined in Ormolu.Config (==) :: RegionIndices -> RegionIndices -> Bool # (/=) :: RegionIndices -> RegionIndices -> Bool # | |
Show RegionIndices Source # | |
Defined in Ormolu.Config showsPrec :: Int -> RegionIndices -> ShowS # show :: RegionIndices -> String # showList :: [RegionIndices] -> ShowS # |
defaultConfig :: Config RegionIndices Source #
Default
.Config
RegionIndices
A wrapper for dynamic options.
data PrinterOpts f Source #
Options controlling formatting output.
PrinterOpts | |
|
Instances
type PrinterOptsPartial = PrinterOpts Maybe Source #
A version of PrinterOpts
where any field can be empty.
This corresponds to the information in a config file or in CLI options.
type PrinterOptsTotal = PrinterOpts Identity Source #
A version of PrinterOpts
without empty fields.
loadConfigFile :: FilePath -> IO ConfigFileLoadResult Source #
Read options from a config file, if found.
Looks recursively in parent folders, then in XdgConfig
,
for a file named fourmolu.yaml.
data ConfigFileLoadResult Source #
The result of calling loadConfigFile
.
ConfigLoaded FilePath PrinterOptsPartial | |
ConfigParseError FilePath (Pos, String) | |
ConfigNotFound [FilePath] |
Instances
Eq ConfigFileLoadResult Source # | |
Defined in Ormolu.Config (==) :: ConfigFileLoadResult -> ConfigFileLoadResult -> Bool # (/=) :: ConfigFileLoadResult -> ConfigFileLoadResult -> Bool # | |
Show ConfigFileLoadResult Source # | |
Defined in Ormolu.Config showsPrec :: Int -> ConfigFileLoadResult -> ShowS # show :: ConfigFileLoadResult -> String # showList :: [ConfigFileLoadResult] -> ShowS # |
configFileName :: FilePath Source #
Expected file name for YAML config.
fillMissingPrinterOpts :: forall f. Applicative f => PrinterOptsPartial -> PrinterOpts f -> PrinterOpts f Source #
Fill the field values that are Nothing
in the first argument
with the values of the corresponding fields of the second argument.
data OrmoluException Source #
Ormolu exception representing all cases when Ormolu can fail.
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 TextDiff | Formatted source code is not idempotent |
OrmoluUnrecognizedOpts (NonEmpty String) | Some GHC options were not recognized |
OrmoluCabalFileParsingFailed FilePath | Cabal file parsing failed |
OrmoluMissingStdinInputFile | Missing input file path when using stdin input and accounting for .cabal files |
Instances
Eq OrmoluException Source # | |
Defined in Ormolu.Exception (==) :: OrmoluException -> OrmoluException -> Bool # (/=) :: OrmoluException -> OrmoluException -> Bool # | |
Show OrmoluException Source # | |
Defined in Ormolu.Exception showsPrec :: Int -> OrmoluException -> ShowS # show :: OrmoluException -> String # showList :: [OrmoluException] -> ShowS # | |
Exception OrmoluException Source # | |
Defined in Ormolu.Exception |
withPrettyOrmoluExceptions Source #
Inside this wrapper OrmoluException
will be caught and displayed
nicely.