How to exclude files from lint rules
Some files legitimately fail a rule — generated metadata, vendored code, descriptions Salesforce writes for you. Pick the exclusion mechanism by scope — a single violation, one rule across file types, or whole files — then regenerate the baseline.
Suppress a single violation in source
Code Analyzer's inline markers work in any text file and for every engine — the marker is a plain comment in whatever comment syntax the file has:
// Code-analyzer-suppress(pmd:AvoidDebugStatements)
System.debug(LoggingLevel.INFO, 'probe');
// Code-analyzer-unsuppress(pmd:AvoidDebugStatements)
<!-- Code-analyzer-suppress(pmd:DescriptionWrongFormat) -->
<description>a description Salesforce generated</description>
A suppression runs from its marker line to the end of the file unless closed with the matching
Code-analyzer-unsuppress(...) — close it, or the rest of the file is exempt too. The selector
takes a rule (engine:rule), a whole engine (pmd), or all. See the
Code Analyzer suppression docs
for the full syntax.
Ruleset <exclude-pattern> does not work
It has no effect under Code Analyzer (pmd/pmd#5758). Do not use it — pick one of the mechanisms below.
Exclude files from a single PMD rule
Add a violationSuppressXPath property to the rule in the ruleset under .pmd/, matching file
names with pmd:fileName():
<property
name="violationSuppressXPath"
value=".[ends-with(pmd:fileName(), '.email-meta.xml') or ends-with(pmd:fileName(), '.bot-meta.xml')]"
/>
pmd:fileName() returns the bare file name, not the path — match on suffixes (file type) or exact
names, not folders. The DescriptionWrongFormat rule in .pmd/metadata-ruleset.xml carries a
working example.
Exclude files from every engine and rule
Add the paths to ignores.files in code-analyzer/code-analyzer.yml (glob syntax):
This removes the files from the whole analysis — PMD, CPD, eslint, all of it. Use it for vendored or generated content; prefer the per-rule suppression when only one rule misfires.
What the analysis scans in the first place is in related ignore files.
For eslint-specific scoping, use the ignores entries of the root eslint.config.js instead.
Regenerate the baseline
A new exclusion changes what the scan reports, so the recorded caps drift:
Review the diff — entries for the now-excluded files should disappear — and commit the baseline together with the exclusion.
The baseline is not an exclusion mechanism — see how to baseline the code analyzer.