Skip to content

Documentation

Formatting

Iris includes a formatter for PureScript. Run iris format to format a Spago workspace, check formatting in CI, or format a file without a workspace. You can also format an open document in your editor.

Format a workspace#

To format a workspace, run iris format from a directory inside it:

Terminal
iris format

Iris formats the src and test sources of every workspace package and writes changes in place. It skips downloaded dependencies in .spago, symlinks, nested workspaces, and files outside package sources. Formatting does not fetch dependencies or compile the workspace.

Check formatting in CI#

To check formatting without changing files, add --check:

Terminal
iris format --check

Iris lists files that need formatting on standard error and exits with status 1. It exits with status 0 when all files are formatted, or status 2 for an error such as invalid source or options.

Format a single file#

Use --file to format a single file. The formatted source code is printed to standard output.

Terminal
iris format --file src/Main.purs

Use --write to update the file and --check to check it. You can repeat --file to select multiple files. --write cannot be used with --check and vice versa.

If you use --file for multiple distinct inputs, add either --write or --check.

Terminal
iris format --write --file src/Main.purs --file test/Main.purs

Use --file - to read from standard input.

Terminal
cat src/Main.purs | iris format --file -

Format in your editor#

When your editor is connected to the Iris language server, the editor's Format Document command formats the open document, including unsaved changes. It uses the same formatter as iris format.

The editor sends tabSize to set the indentation width, which may differ from the command-line default of two spaces. Iris uses spaces even when insertSpaces is false. The editor preserves existing ASCII and Unicode spellings; it cannot enable the command-line --unicode option.

To match the command-line indentation in Visual Studio Code, add these settings for PureScript files to settings.json:

settings.json
{  "[purescript]": {    "editor.tabSize": 2,    "editor.detectIndentation": false  }}

The preferred line width defaults to 100 columns. LSP clients that send custom formatting options can set options.lineWidth to a positive integer. The Visual Studio Code extension does not send this option. Iris returns no edits for invalid source.

Options and layout#

On the command line, Iris defaults to a preferred width of 100 columns and two spaces per indentation level. Set these options on the command line:

Terminal
iris format --width 100 --indent 4 --unicode
  • --width COLUMNS sets the preferred line width to a positive integer. Long comments and indivisible tokens can exceed it.
  • --indent SPACES sets the indentation width from 1 to 65535 spaces.
  • --unicode uses Unicode for built-in signatures, arrows, constraints, and forall. Without it, Iris preserves the original spellings, including Unicode. The flag does not convert literals, comments, record labels, or user-defined operators.

Iris has no project-level formatter configuration. Use the same options when formatting and checking a project. Iris normalizes CRLF line endings in whitespace and comments to LF, so --check can report a CRLF file as needing formatting.

Iris sorts imports by module name, placing an open, unaliased import Prelude first. It does not sort or merge import lists. For example, given this file:

src/Main.purs
module Main where import Effectimport Prelude main :: Effect Unitmain= pure unit

Iris produces:

Formatted output
module Main where import Prelude import Effect main :: Effect Unitmain = pure unit

The formatter wraps expressions, types, and lists to fit the preferred width. It preserves comments and section separation outside the import block. For the full layout conventions, see the formatter reference.

Iris validates every result before writing any files. If a file has invalid source, Iris stops without writing any files. Writes are not atomic, so an interrupted or failed write can leave a file partially written or an earlier file already updated.