> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ubx fmt

> Format .iac files canonically.

`ubx fmt` formats `.iac` files in place using the canonical ubx style. Similar to `terraform fmt` or `gofmt`.

## Usage

```bash theme={null}
ubx fmt [path] [flags]
```

## Examples

```bash theme={null}
ubx fmt                   # format all .iac files in current directory
ubx fmt main.iac          # format specific file
ubx fmt ./stacks/         # format all files in directory
ubx fmt --dry-run         # show what would change without writing
ubx fmt --check           # exit 1 if any files need formatting (CI mode)
```

## Flags

| Flag        | Description                         |
| ----------- | ----------------------------------- |
| `--dry-run` | Show diff without writing files     |
| `--check`   | Exit 1 if any files need formatting |

## Formatting Rules

* Consistent 2-space indentation
* Aligned `=` signs within a block
* Single blank line between blocks
* Sorted attribute keys (alphabetically within each block)
* Canonical quoting (double quotes for strings)

## Example

Before:

```hcl theme={null}
unit "aws_s3_bucket_v2" "assets" {
    bucket="my-assets"
  force_destroy=true
  tags={env="prod", team="platform"}
}
```

After `ubx fmt`:

```hcl theme={null}
unit "aws_s3_bucket_v2" "assets" {
  bucket        = "my-assets"
  force_destroy = true
  tags = {
    env  = "prod"
    team = "platform"
  }
}
```

## CI Usage

```bash theme={null}
# Fail CI if files aren't formatted
ubx fmt --check || exit 1
```

## `.ubxignore` Respected

Files excluded via `.ubxignore` are not formatted.
