Afmt is written in Rust ๐ฆ. It uses tree-sitter apex parser to traverse AST nodes.
Note. this is a project in its early phase, don't expect to use it in production code yet.
Blazingly fast - parsing speed of largest open-source Apex files report
Feature | Progress | Difficulty |
---|---|---|
Recognize Apex nodes | โโโโโโโโโโโโ 100% | Easy |
Support .afmt.toml for configuration |
โโโโโโโโโโโโ 100% | Easy |
Proper indentation | โโโโโโโโโโโ 80% | Easy |
Support SOQL | โโโโโโโโโโโโ 100% | Medium |
Support SOSL | โโโโโโโโโโโ 50% | Medium |
Reformat lines beyond max_width |
โโโโโโโโโโ 10% | Challenging |
Support comment (line comment and block comment) | โโโโโโโโโโ 10% | Challenging |
Download the binary from the release page. It supports Linux, MacOS, and Linux.
Extract and run afmt -h
to check the supported parameters.
Format Apex file v0.0.7
Usage: afmt [OPTIONS]
Options:
-f, --file <FILE> The relative path to the file to parse [default: test.cls]
-c, --config <CONFIG> Path to the .afmt.toml configuration file
-w, --write Write the formatted result back to the file
-h, --help Print help
-V, --version Print version
test.cls
file next to binary with Apex codeafmt
to dry-check the format resultafmt -w
to write the format result into the file (test.cls
)ยป afmt
Result 0: Ok
public class S {
{
rd.RecurringDonationSchedules__r?.get(0)?.nextDonationDate;
}
}
"public class S {\n {\n rd.RecurringDonationSchedules__r?.get(0)?.nextDonationDate;\n }\n}\n"
Afmt completed successfully.
Execution time: 585.1โฌโกs
ยป afmt -w
Result 0: Ok
public Date getExpectedDonationDate(RD2_ScheduleService scheduleService) {
return rd.RecurringDonationSchedules__r?.get(0)?.nextDonationDate;
}
Formatted content written back to: test.cls
Afmt completed successfully.
Execution time: 724.826โฌโกs