PMD language module that provides static code analysis capabilities for Salesforce Visualforce pages and components
npx @tessl/cli install tessl/maven-net-sourceforge-pmd--pmd-visualforce@7.13.0PMD Visualforce is a specialized language module for PMD that enables static code analysis of Salesforce Visualforce markup files (.page and .component). It extends PMD's core functionality to parse and analyze Visualforce pages and components, providing developers with code quality analysis capabilities specific to Visualforce development within the Salesforce ecosystem.
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-visualforce</artifactId>
<version>7.13.0</version>
</dependency>import net.sourceforge.pmd.lang.visualforce.VfLanguageModule;
import net.sourceforge.pmd.lang.visualforce.ast.*;
import net.sourceforge.pmd.lang.visualforce.rule.AbstractVfRule;import net.sourceforge.pmd.lang.visualforce.VfLanguageModule;
import net.sourceforge.pmd.lang.visualforce.ast.VfParser;
import net.sourceforge.pmd.lang.visualforce.VfLanguageProperties;
// Get the Visualforce language module instance
VfLanguageModule languageModule = VfLanguageModule.getInstance();
// Create parser with properties
VfLanguageProperties properties = new VfLanguageProperties();
VfParser parser = new VfParser(properties);
// Parse Visualforce content (typically done by PMD framework)
// ASTCompilationUnit ast = parser.parse(visualforceContent);PMD Visualforce follows PMD's standard language module architecture:
VfLanguageModule registers the language with PMD and provides core servicesVfParser and VfHandler handle parsing Visualforce markup into ASTAbstractVfRule base class for creating custom analysis rulesVfCpdLexer enables copy-paste detection in Visualforce filesThe package integrates seamlessly with PMD's analysis engine and depends on the Apex language module for comprehensive Salesforce analysis workflows.
Core language module registration and configuration for integrating Visualforce analysis into PMD.
public class VfLanguageModule extends SimpleLanguageModuleBase implements CpdCapableLanguage {
public static VfLanguageModule getInstance();
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
public LanguagePropertyBundle newPropertyBundle();
}
public class VfLanguageProperties extends LanguagePropertyBundle {
public static final PropertyDescriptor<List<String>> APEX_DIRECTORIES_DESCRIPTOR;
public static final PropertyDescriptor<List<String>> OBJECTS_DIRECTORIES_DESCRIPTOR;
}Complete Abstract Syntax Tree generation with specialized node types for parsing and representing Visualforce markup structures.
public final class VfParser extends JjtreeParserAdapter<ASTCompilationUnit> {
public VfParser(VfLanguageProperties vfProperties);
}
public interface VfNode extends JjtreeNode<VfNode> {}
public final class ASTCompilationUnit extends AbstractVfNode implements RootNode {
public AstInfo<ASTCompilationUnit> getAstInfo();
}
public final class ASTElement extends AbstractVfNode {
public boolean isHasNamespacePrefix();
public String getName();
public boolean isEmpty();
public boolean isUnclosed();
}Infrastructure for creating custom PMD rules to analyze Visualforce code quality and security issues.
public abstract class AbstractVfRule extends AbstractRule implements VfVisitor<Object, Object> {
public void apply(Node target, RuleContext ctx);
public Object visitNode(Node node, Object param);
}
public abstract class VfVisitorBase<P, R> extends AstVisitorBase<P, R> implements VfVisitor<P, R> {}Type system integration with Salesforce metadata for context-aware analysis of Visualforce expressions and data binding.
public enum DataType {
AutoNumber, Checkbox, Currency, Date, DateTime, Email, Text, /* ... */;
public final boolean requiresEscaping;
public static DataType fromString(String value);
public static DataType fromTypeName(String value);
}
public class VfExpressionTypeVisitor {
// Internal visitor for adding type information to AST
}Type Analysis and Salesforce Integration
// Core AST interfaces
public interface VfNode extends JjtreeNode<VfNode> {}
public interface VfVisitor<P, R> {
R visit(ASTCompilationUnit node, P data);
R visit(ASTElement node, P data);
R visit(ASTElExpression node, P data);
R visit(ASTAttribute node, P data);
// ... visitor methods for all AST node types
}
// Language properties
public class VfLanguageProperties extends LanguagePropertyBundle {
public VfLanguageProperties();
}
// Rule context
public abstract class AbstractVfRule extends AbstractRule implements VfVisitor<Object, Object> {}