Search code examples
salesforceapexpmd

Tool for checking Apex code formatting style


I want to find some tool for checking my Apex code for such things as tabs/spaces indents, braces position and so on.

Well, I've tried to implement such functionality using Checkstyle and PMD. So, Checkstyle throws exceptions when meet syntax tokens different from Java (switch statement, string literals ''). With PMD I just didn't find any ways to resolve my issue using custom Java classes, there are just no properties to get information about indents in code.

I need a tool for using it via command line.


Solution

  • The question is quite old but today if you'd need to check the code formatting, I think the best option is to use npm packages prettier and prettier-plugin-apex.

    The prettier-plugin-apex is opinionated formatter, meaning there are not many options to adjust the code formatting. Due to that I forked it and added a couple of additional options as part of this package @ilyamatsuev/prettier-plugin-apex.