4

I have been searching the web to see if I could find a tool which can be used to analyze Salesforce code - including Apex, Visualforce, Javascript, and more importantly, Lightning. I have found a few tools out there, but none support Lightning.

I am looking for a tool which can produce a report on classes and components with information on (for example) best coding practices / irrelevant code. For example making sure that an if or while condition does not have a blank statement inside. Or making sure that there are no SOQL queries inside any for loops.

3 Answers 3

5

PMD is one of the very few static analysis tools that supports Apex. Its rule set is not vast, but does cover a lot of important areas like SOQL and DML in loops. It has a couple of rules for Visualforce as well. There are good plugins for Eclipse and Visual Studio Code, and it can be used in CI as well.

PMD also supports JavaScript, but I have not tried to use it on Lightning code yet.

2
  • I have looked into PMD, but it seems limited in what it can do for Apex and Javascript. I do not know if I am configuring it correctly, but my main question is, does it work with lightning? PMD was actually my first choice, thanks for the feedback!
    – Nicolas O
    Commented Feb 13, 2018 at 23:28
  • 1
    @NicolasO You should include that kind of info in your question. The rulesets are pretty decent and open source so you can always improve upon them if you have the requisite skills. I think we may need someone to step up in that regard for lightning, but haven't tried to run it on anything but classes yet.
    – Adrian Larson
    Commented Feb 14, 2018 at 0:18
4

I realize this post is months old, but you might check out https://www.getclayton.com/ which is a cloud based Static Analysis Tools specifically for Apex. It reads code from GitHub repos and is highly customizable. I'm relatively new as a contributor here, and forgot to mention I have no affiliation or incentive to recommend the project, however I do personally know the creator and have great respect for his expertise and integrity.

5
  • 1
    Hey Don! I know you are not a spammer and suspect you are not affiliated with Clayton, but community guidelines here indicate you should disclose any affiliation or lack thereof with any products you recommend. Could you please edit your post to do so? Thanks!
    – Adrian Larson
    Commented Nov 28, 2018 at 2:28
  • Thanks for joining our little corner of the internet. Always glad to see more MVPs contributing. :)
    – Adrian Larson
    Commented Nov 28, 2018 at 16:26
  • Happy to learn and follow the rules - just coming back to SE more and more and I will evolve. @Adrian can I mention and point to free online education content supporting the context of the question above?
    – DonRobins
    Commented Mar 9, 2020 at 20:20
  • 1
    Yeah it's not a problem at all, it's just always a good rule of thumb to be crystal clear about your affiliation or lack thereof to anything external. Full guidance on disclosure can be found here.
    – Adrian Larson
    Commented Mar 10, 2020 at 3:16
  • Thanks. I recorded a course with Robert and Lorenzo in my series that runs on Pluralsight.com all about static code analysis. The course is 100% Free (no Pluralsight account is required to watch) and can be found here: pluralsight.pxf.io/JvO5Q - hope it's of value.
    – DonRobins
    Commented Mar 11, 2020 at 6:41
3

There is the sfdx force:lightning:lint tool that is:

just like any other lint command-line tool

in that it flags errors and can also produce warnings. It is part of the (relatively) new Salesforce SFDX CLI tools.

PS

The the "Apex PMD" extension installed in VSCode I got problem reports like these on Apex:

file: 'file:///Users/keith/git/ux/sfdx-source/wiz/main/classes/WizController.cls'
severity: 'Warning'
message: 'The method 'searchRecordsByExample' has a Standard Cyclomatic Complexity of 11.'
at: '136,5'
source: ''
code: 'undefined'

and on SLDS:

file: 'file:///Users/keith/git/ux/sfdx-source/wiz/main/aura/wizGenericDetailsModal/wizGenericDetailsModal.cmp'
severity: 'Warning'
message: 'Deprecated SLDS class name (v2.3.1): Change slds-text-heading--medium to slds-text-heading_medium'
at: '22,36'
source: 'slds'
code: '0slds-text-heading_medium'

that combined with "sfdx force:lightning:lint" provide useful hints.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .