xixiaofinland / afmt

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

Allow comment directive to enable/disable formatting vs. literal printing #9

Open aheber opened 1 month ago

aheber commented 1 month ago

This might not be an issue as much as a discussion. Feel free to convert.

IntelliJ IDE supports explicit formatter enable/disable comments which is used by Illuminated Cloud

// @formatter:off
String   val  =    'whatever code I feel like here and IntelliJ won\'t touch it';
String            val2 = 'more code with weird indenting because I feel like it';
// @formatter:on

Prettier supports next-node disablement

{
    // prettier-ignore
    String   val  =    'whatever code I feel like here and IntelliJ won\'t touch it';
    // prettier-ignore
    String           val2  = 'more code with weird indenting because I feel like it'
}

Should afmt have a way to prevent formatting from acting on a portion of the file? Should it have it's own pattern? Should it respect the keywords from the other formatters?

I expect it will be needed, already as I use this to take a formatting pass at my own files I see areas I've already disabled formatting being changed in ways I wouldn't want, but not things that I would expect the tool to accommodate.

I'm sure there are pros & cons to any strategy, most likely I'd imagine that those formatters were disabled because of their quirks and maybe afmt won't have the same quirks so it wouldn't need those anymore. Would need a larger sample size I'm sure.