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!
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.