Salesforce CLI Command Reference
Release Notes
Deprecation Policy
code-analyzer ast-dump
code-analyzer config
code-analyzer rules
code-analyzer run
Dump the Abstract Syntax Tree (AST) for a given source file.
Generate and display the AST that PMD produces when parsing a source file. This is useful for understanding how PMD interprets your code and for developing custom PMD rules. The command supports Apex, Visualforce, HTML, XML, and JavaScript files.
| Flag Name (Long) | Flag Name (Short) | Description |
|---|---|---|
‑‑file | N/A | Type: Value Required Path to the source file to parse. The file whose AST you want to generate. The file must exist and be a regular file (not a directory). If you don’t specify the --language flag, the language is auto-detected from the file extension. |
‑‑flags‑dir | N/A | Type: Value Import flag values from a directory. |
‑‑format | N/A | Type: Value Valid Values: json, xmlDefault value: xmlOutput format for the AST. Choose between xml (default) or json. The XML format outputs the raw PMD AST XML, preserving the full tree structure. The JSON format provides a flat array of nodes with names, attributes, parent, and ancestor information. |
‑‑json | N/A | Type: Boolean Format output as json. |
‑‑language | ‑l | Type: Value Valid Values: apex, visualforce, html, xml, javascriptDefault value: apexLanguage of the source file. Explicitly specify the language of the source file. Defaults to apex. Supported languages are: apex, visualforce, html, xml, and javascript. |
‑‑output‑file | N/A | Type: Value Path to the file where the AST output is written. If specified, the AST output is written to this file instead of being displayed in the terminal. The content format depends on the --format flag. |
Dump the AST for an Apex class file in JSON format (default):
1sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.clsDump the AST in XML format:
1sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.cls --format xmlDump the AST and write the output to a file:
1sf code-analyzer ast-dump --file ./force-app/main/default/classes/MyClass.cls --output-file ast-output.jsonExplicitly specify the language when the file extension is ambiguous:
1sf code-analyzer ast-dump --file ./src/myfile.html --language html