-
Notifications
You must be signed in to change notification settings - Fork 19
Add or improve existing PMD rules
TODO: Introduce PMD so people understand its a framework written in Java that parses code to an AST and analyses its nodes. Tell them that we are using a parser used by the Force IDE (reference all our discussions). Tell then that the parser and or Apex has a few differences to regular parsers. Tell them that we ported Java rules that a) we liked in general b) were easily portable with the nodes we understood and c) were the required info exists in the AST. Name a few Java rules that weren't portable at all and say why.
PMD is a Maven project and composed of different modules. Beside some general modules like the pmd-core module, there are modules for every supported language, for example pmd-apex. This modules vary in complexity. Some of them just offer a simple Copy/Paste Detector (CPD), like pmd-perl. Others provide complete language-specific static code analysis tools, like pmd-apex.
This modules are all designed the same. A Parser parses the source code into a abstract syntax tree (AST), every generated node have to be represented as a Java class. Based on this ASTs and their nodes it is possible to apply rules. The Avoid-deeply-nested-if-statements rule for example checks if there are if-statement nodes with more than one if-statement node above them in the tree. If that is true the rule adds a violation.
If you want to add rules that work similarly to the ones we already have you will have to extend PMD itself. Those are the steps you need to do:
