# `jadpo fmt`

Format source files.

Rewrite Jadpo files in the one layout the formatter owns: indentation, spacing, blank lines and one member per line. In a project it first fixes each file's `use` lines: adds a missing import, removes an unused one and sorts them. With --layout it also moves each declaration another file uses into a file of its own, as layout.promotion_required asks. With --check, change nothing and fail if any file would change. Without a path, the project is found by walking up to app.jadpo.

Also: `jadpo format`.

```text
jadpo fmt [path]
```

## Arguments

- `path` (optional): A file or folder instead of the whole project

## Flags

- `--check`: Report unformatted files and change nothing
- `--layout`: Also make the moves promotion asks for

## On every command

- `--json`: Print data for tools instead of text
- `--full`: Show everything a report shortens
- `--help`: Show every flag, with examples
- `--color <when>`: Choose when to use colour

`jadpo fmt --json` writes one JSON document to standard output instead of text, with the same exit code. The document has `schemaVersion`, `command` (`"fmt"`), `ok`, `data` (what the command produced, `null` when it failed) and `diagnostics` (each error with its `rule`, `reason`, `next` and `help`). A command that needs a terminal refuses `--json` and names the flags that do the same job.

## Examples

```text
# Format the project you are in
jadpo fmt
# Make the moves layout.promotion_required asks for, then format
jadpo fmt --layout
# Check formatting without changing anything, as CI does
jadpo fmt --check
# Format one file
jadpo fmt app.jadpo
```

## Errors

- [`cli.fmt_arguments`](/docs/errors/cli.fmt_arguments.md): A `jadpo fmt` command names a path that isn't there or isn't a `.jadpo` file
- [`format.changes_required`](/docs/errors/format.changes_required.md): A file `jadpo fmt --check` read isn't laid out as `jadpo fmt` would write it
- [`format.unsafe`](/docs/errors/format.unsafe.md): A file was left as it was, because what the formatter made of it didn't read back as the same code, which is a mistake in Jadpo's formatter
- [`format.write_failed`](/docs/errors/format.write_failed.md): A file `jadpo fmt` formatted couldn't be written, usually because it is read-only
- [`layout.promotion_required`](/docs/errors/layout.promotion_required.md): Declaration is used beyond the file that holds it
- [`toolchain.project_not_found`](/docs/errors/toolchain.project_not_found.md): You ran a command that works on a project in a folder with no `app.jadpo`, in it or in any folder above it
- [`toolchain.source_read_failed`](/docs/errors/toolchain.source_read_failed.md): A `.jadpo` file in the project couldn't be read, because it isn't UTF-8 text or you aren't allowed to read it
