# apexfmt

Format Apex code automatically.

## Usage

```bash
# Format file to stdout
apexfmt MyClass.cls

# Format and overwrite files
apexfmt -w *.cls *.trigger

# Check which files need formatting
apexfmt -l sfdx/main/default/classes/*.cls

# Format SOQL query
echo "SELECT Id, Name FROM Account WHERE Type = 'Customer'" | apexfmt -s

# Format from stdin
cat MyClass.cls | apexfmt
```

## What it does

- Uses tabs for indentation (like gofmt)
- Formats method chaining and parameters
- Properly indents conditionals and loops
- Formats SOQL queries with line breaks
- Preserves comments
- Handles collections and object initialization

## Options

- `-w, --write` \- Overwrite files in-place
- `-l, --list` \- List files that need formatting
- `-s, --soql` \- Format SOQL from stdin
- `-v, --verbose` \- Debug logging

## Installation

On macOS and Linux, install with [Homebrew](https://brew.sh/):

```bash
brew install octoberswimmer/tap/apexfmt
```

Or download a binary for your platform:

- [Linux](https://github.com/octoberswimmer/apexfmt/releases)
- [macOS Intel](https://github.com/octoberswimmer/apexfmt/releases)
- [macOS Apple Silicon](https://github.com/octoberswimmer/apexfmt/releases)
- [Windows](https://github.com/octoberswimmer/apexfmt/releases)

## Price

**Free** \- Open source

## Links

- [GitHub Repository](https://github.com/octoberswimmer/apexfmt)

## Docs

- [apexfmt command reference →](/content/tools/apexfmt/docs/apexfmt/index.html)
