0

I've inherited a messy repo full of legacy apex code - trying to get it cleaned up and readable for some more junior devs on my team. What linting tools do you all use on your apex classes to enforce standards? Is it possible to just grab a java linter and run with that? All recommendations welcome - Thanks!

5

While there are commercial tools in this space, I'd start with Apex PMD. It's free and open source, and there's an excellent plugin for Visual Studio Code to run it right in the IDE. There's also an Eclipse plugin if you're using the Force.com IDE, although I find the user experience much better in VS Code.

PMD is a static analyzer and it will catch a lot of key code issues like DML and SOQL in loops, while also allowing you to set some basic stylistic parameters - requiring braces on loop bodies, for example. The rule set that you apply can be customized by editing an XML definition file.

There's no pure style linter/formatter for Apex just yet. You can use Uncrustify (a Java formatter), although I admit I haven't fiddled with it enough to produce an Apex style that I particularly like. My understanding is that there is an Apex formatter for Visual Studio Code coming to the Salesforce tools in a future release, but it's not officially promised or anything just yet.

I previously wrote a blog post on setting up PMD in Eclipse, VSC, and in a CI context.

3
  • You mentioned Clayton.io in your blog post - have you used it recently?
    – Isaac V
    Dec 14 '18 at 15:28
  • @IsaacV I haven't used it recently. I hear it's been updated substantially since I last used it.
    – David Reed
    Dec 14 '18 at 15:29
  • 1
    PMD now appears to be included with VS Code if you use the Salesforce Extension Pack, too.
    – sfdcfox
    Dec 14 '18 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.