xixiaofinland / afmt

Salesforce Apex code formatter written in Rust
MIT License
23 stars 3 forks source link

๐Ÿš€ A Blazingly Fast Salesforce Apex Formatter

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.

โœจ Highlights

Blazingly fast - parsing speed of largest open-source Apex files report


๐Ÿ“Ÿ Project Progress

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


๐Ÿ”ง How to use

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

Simplest use scenario:

ยป 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


๐Ÿ“ก Technical parts

Technical Doc

Config Doc