---
title: Formatting
canonical_url: https://mew-lang.org/compiler/formatting/
sidecar_url: https://mew-lang.org/compiler/formatting.md
content_hash: sha256:ac13bae45ccfb34f5aa133f9ed62ce2eeb64f2d66cf302257bd4e09695093709
tokens: 385
uid: compiler.formatting
reading_time_minutes: 2
---

Compiler
# Formatting

 
Mew has one formatter, and it is the same code whether it runs in an editor or on the command line. There is nothing to configure.

 
## What it decides

 
The formatter decides indentation and the spacing between tokens. It does not decide what goes on which line, so a line break you wrote is a line break it keeps.

 
```mew
// Before
pub type Point{
pub field x:i32;
}
```

 
```mew
// After
pub type Point {
    pub field x: i32;
}
```

 
Runs of blank lines collapse to one, and a file that has any content at all ends with a single newline.

 
## Running it

 
```shell
mew fmt                # every .mew file under the current directory
mew fmt src            # or under a directory you name
mew fmt main.mew       # or a single file
mew fmt --check .      # report what is unformatted, write nothing, exit 1
```

 
`--check` is what a build runs. Mew's own build uses it to hold the sample programs to the style the formatter produces.

 
## Why it is safe to run

 
The formatter lexes its own output and compares it token by token against the input. If anything differs it returns the original unchanged, so a formatting rule cannot drop or reorder code.

 
> [!IMPORTANT]
> A file that does not parse still formats. The formatter works off the token stream rather than the syntax tree, which is the normal case while you are still typing.

 
[Previous
                
                Compiler](/compiler/)[Next
                    
                Completion](https://mew-lang.org/compiler/completion.md)