the-sett/elm-syntax-dsl/4.0.0

NOTE: the latest version is 6.0.5

Elm.Pretty

Elm.Pretty is a pretty printer for Elm syntax trees. It makes use of the-sett/elm-pretty-printer to best fit the code to a given character width.

It aims to output code that is fully stable with respect to elm-format in the sense that running elm-format on the output should have no effect at all. The advantage of this is that if generated code moves to being edited by hand, there will not be a large white-space only diff created when elm-format is applied.

To print the Doc created by the pretty functions, the-sett/elm-pretty-printer is used:

import Elm.Pretty
import Pretty


elmAsString =
    Elm.Pretty.pretty someFile
        |> Pretty.pretty 120


-- Fit to a page width of 120 characters

Pretty prints an entire Elm file.

pretty : File -> Doc

Pretty prints a file of Elm code.

Pretty printing snippets of Elm.

prettyImports : List Import -> Doc

Pretty prints a list of import statements.

The list will be de-duplicated and sorted.

prettyExposing : Exposing -> Doc

Pretty prints the contents of an exposing statement, as found on a module or import statement.

The exposed values will be de-duplicated and sorted.

prettyDeclaration : Declaration -> Doc

Pretty prints a single top-level declaration.

prettyFun : Function -> Doc

Pretty prints an Elm function, which may include documentation and a signature too.

prettyTypeAlias : TypeAlias -> Doc

Pretty prints a type alias definition, which may include documentation too.

prettyCustomType : Type -> Doc

Pretty prints a custom type declaration, which may include documentation too.

prettyPortDeclaration : Signature -> Doc

Pretty prints a port declaration.

prettyDestructuring : Pattern -> Expression -> Doc

Pretty prints a desctructuring declaration.

prettySignature : Signature -> Doc

Pretty prints a type signature.

prettyPattern : Pattern -> Doc

Pretty prints a pattern.

prettyExpression : Expression -> Doc

Pretty prints an expression.

prettyTypeAnnotation : TypeAnnotation -> Doc

Pretty prints a type annotation.