- π Introduction
- π Playground
- β Features
- β¨ vs. Prettier Apex
- π₯ Installation
- π» Usage
- π§ Configuration
- β FAQ
- π€ Contribution
afmt
(Apex formatting tool) is written in Rust π¦ and leverages the tree-sitter sfapex parser.
Note
We're looking for contributors to help create a VSCode plugin! Feel free to join the discussion!
Try the browser version playground, and its source code here.
- Performant
- Configurable: via
.afmt.toml
. - Standalone: CLI with no dependencies.
- Open Source
While both afmt
and Prettier Apex aim to format Salesforce Apex code, they differ fundamentally in their design philosophies:
- Prettier Apex: Maintains an opinionated approach with limited customization to ensure consistency.
- afmt: Focuses on extensibility, offering more configuration options to cater to diverse user preferences.
This means afmt
will progressively introduce more configuration options, addressing user customization needs that Prettier's design intentionally avoids.
Feature | afmt | Prettier Apex |
---|---|---|
Maturity | Brand new | Battle tested for years |
Dependencies | N/A (standalone binary) | Node.js + Prettier package |
Performance | Fast (Rust) | Relatively slower (Node.js) |
Parser | sfapex (C / Open Source) | Jorje (Java / Closed Source) |
Open Source | Yes | Yes |
curl -sL https://raw.githubusercontent.com/xixiaofinland/afmt/main/scripts/install-afmt.sh | bash
iwr -useb https://raw.githubusercontent.com/xixiaofinland/afmt/main/scripts/install-afmt.ps1 | iex
afmt
is published in creates.io here.
Run cmd below if you have the Cargo
tool.
cargo install sf-afmt
Visit the release page and download the appropriate binary for your operating system (Linux, macOS, or Windows).
Create a file.cls
file with valid Apex code.
Run afmt ./file.cls
to preview the formatting result.
> afmt ./file.cls
Result 0: Ok
global class PluginDescribeResult {
{
[SELECT FIELDS(STANDARD) FROM Organization LIMIT 1];
}
}
Run afmt -w ./file.cls
to format the file and overwrite it with the
formatted code.
> afmt -w ./file.cls
Formatted content written back to: ./file.cls
Afmt completed successfully.
-c
parameter can read configuration settings from a toml file.
Example: afmt -c .afmt.toml
In .afmt.toml
config file, two options are supported
# Maximum line width
max_width = 80
# Indentation size in spaces
indent_size = 4
-
"TLTR, what features afmt has?" Run
afmt -h
. -
"How do I set up afmt in VSCode?" Setup in VSCode
-
"Can afmt formats exactly the same as Prettier Apex?" No.
We greatly value contributions! You can help by reporting issues or submitting PRs.
Scenarios (e.g., new features, bug fixes) must be covered by tests, and cargo test
passes.
Refer to *.in
(before format) and *.cls
(after format) files in the test folder.
Also, our CI pipeline ensures high-quality contributions.
CI Rules:
- Use conventional commit for commit messages. Example: the project commit history
- Ensure code passes rustfmt and clippy:
cargo fmt -- --check
andcargo clippy
- Run and pass all unit tests:
cargo test --all-features
- Pass battle tests by running
afmt
on a list of popular Apex repos