---
schema_version: "1"
id: 30186d116c5b1ce75c04aa45cfbff7aea61875449537d261e0c97dc2848e27c1
title: Suppress Violations
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/code-analyzer/salesforce-code-analyzer/guides/suppress-violations.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/suppress-violations.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8476ef18b92940275b143a2567408c8d80e37705372a3259ab2e39222e9ff1b9
products:
  - Salesforce Code Analyzer
---
# Suppress Violations
Ignore known or low-priority violations to reduce noise in scan results. Focus on fixing critical issues instead of reviewing expected or acceptable patterns. Use suppression markers within specific code blocks to isolate analysis, so violations in other lines do not interfere.
You can suppress violations in a file, in an entire code block, or at the engine level. You can target specific types of violations and severity levels.

To manage violation suppression effectively and maintain code quality, follow these guidelines:
- Use specific selectors whenever possible.
- Document why you are suppressing.
- Unsuppress to limit scope.
- Use configuration instead of widespread suppression.

## Ignore or Disable Violations in a File

Use the `ignores` section in the `code-analyzer.yml` file to ignore violations from a specific file or a group of files. 
To ignore violations from a specific file, enter the relative path of the file. For example, `"**/utils.js"` ignores violations in `utils.js` in your project.

```
ignores:
  files:
    - "**/utils.js"
```

Use the `disabled` property in the `rules` object to ignore violations of a specific type in all the files of your workspace. For example, use this code in `code-analyzer.yml` to ignore the trailing whitespace violations.


```
rules:
  regex:
    NoTrailingWhitespace:
    severity: 2
    disabled: true
```
## Suppress Violations in a File or Folder

Suppress violations at the configuration level without modifying source code. For example, suppress all false positive violations in a specific file or folder. Define violations to suppress in the `code-analyzer.yml` file. Use comma-separated rule selectors to suppress multiple rules at one time.
Specify the target file or folder path, the maximum number of violations to suppress, and the reason for suppression.

For example, this code suppresses specific rules from ESLint and PMD engines. The folder path must end with / and be absolute or relative to `workspace_root`.

```yaml
suppressions:
  disable_suppressions: false
  
  "src/legacy/utils.js":
    - rule_selector: "eslint:no-console"
      max_suppressed_violations: 5
      reason: "Legacy code - refactor planned"
    - rule_selector: "pmd:UnusedVariable"
      max_suppressed_violations: null
      reason: "Generated code with required unused params"
  
  "src/controllers/":
    - rule_selector: "eslint:complexity,pmd:CyclomaticComplexity"
      max_suppressed_violations: 50
      reason: "Technical debt from v1.0 - tracked in JIRA-1234"
  
  "src/generated/":
    - rule_selector: "all"
      max_suppressed_violations: null
      reason: "Auto-generated code - cannot modify"
```
The properties of the `suppressions` object include:

- **File or Folder Path:** Specify the path to a file or folder. Folder paths must end with /. Path is absolute or relative to `workspace_root`.
- **rule_selector:** The `rule_selector` field supports multiple formats.
    - Single rules ("`eslint:no-console`")
    - Multiple comma-separated rules ("`eslint:no-console,pmd:UnusedVariable`")
    - Engine specific ("`pmd:all`")
    - Severity based ("`1,2,3`"), or "`all`" for everything.
- **max_suppressed_violations:** Set the maximum number of violations allowed to be suppressed. Specify a number for a limit, null for unlimited, and 0 to disable suppression. Once the limit is exhausted, additional violations are reported normally. This prevents technical debt from growing beyond the specified limit. It is optional but recommended.
- **reason:** Provide a brief explanation for the suppression. It is optional but recommended.

## Suppress a Violation in a Code Block

You can suppress violations within a code block by dividing the code into sections and analyzing each section independently so that violations in other lines do not affect the analysis.
Use the `Code-analyzer-suppress` and `Code-analyzer-unsuppress` tags in your code to suppress and restore violations. 


```
// Code-analyzer-suppress(all)
export function formatPrice(price, currency = 'USD') 
{
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}
// Code-analyzer-unsuppress(all)
/**
 * Calculate mortgage payment
 * @param {number} principal - Loan amount
 * @param {number} annualRate - Annual interest rate (e.g., 0.05 for 5%)
 * @param {number} years - Loan term in years
 * @returns {number} Monthly payment
 */

export function calculateMortgage(principal, annualRate, years) 
{
    const monthlyRate = annualRate / 12;
    const numPayments = years * 12;
    
    if (monthlyRate === 0) {
        return principal / numPayments;
    }
    
    const payment = principal * 
        (monthlyRate * Math.pow(1 + monthlyRate, numPayments)) / 
        (Math.pow(1 + monthlyRate, numPayments) - 1);
    
    return Math.round(payment * 100) / 100;
}
```
## Suppress a Violation Type in a Code Block

Suppress specific types of violations while continuing to check for others. For example, ignore the magic numbers rule in the ESLint engine.


```
// Code-analyzer-suppress(eslint:no-magic-numbers)
export function formatPrice(price, currency = 'USD')
{
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}
```
You can also restore violations within a section of the block, even if you ignore all violations from the specific code block. For example, you can restore violations from the magic numbers rule.

```
// Code-analyzer-suppress(eslint)
export function formatPrice(price, currency = 'USD') 
{
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}


// Code-analyzer-unsuppress(eslint:no-magic-numbers)


/**
* A mortgage calculator component
*/
export function MortgageCalculator({ propertyPrice }) 
{
   const [downPayment, setDownPayment] = useState(20);
   const [interestRate, setInterestRate] = useState(6.5);
   const [loanTerm, setLoanTerm] = useState(30);
  
   const loanAmount = propertyPrice * (1 - downPayment / 100);
}
```
## Apply Engine-Specific Suppression

To maintain precise and flexible control over code analysis, suppress violations for an individual engine while keeping checks active for others. For example, suppress violations for the ESLint engine while restoring violations for the SFGE engine.

```
// Code-analyzer-suppress(eslint)
export function formatPrice(price, currency = 'USD') {
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}
//  Code-analyzer-unsuppress(sfge)
/**
 * Calculate mortgage payment
 * @param {number} principal - Loan amount
 * @param {number} annualRate - Annual interest rate (e.g., 0.05 for 5%)
 * @param {number} years - Loan term in years
 * @returns {number} Monthly payment
 */

export function calculateMortgage(principal, annualRate, years)
 {
    const monthlyRate = annualRate / 12;
    const numPayments = years * 12;
    
    if (monthlyRate === 0) {
        return principal / numPayments;
    }
    
    const payment = principal * 
        (monthlyRate * Math.pow(1 + monthlyRate, numPayments)) / 
        (Math.pow(1 + monthlyRate, numPayments) - 1);
    
    return Math.round(payment * 100) / 100;
}
```
You can also suppress all violations from a specific analysis engine while allowing selected rules from that engine to remain active. This strategy is useful when you want to ignore most checks from an engine but continue enforcing critical rules that are relevant to your code.

```
// Code-analyzer-suppress(eslint)
export function formatPrice(price, currency = 'USD') 
{
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}


// Code-analyzer-unsuppress(eslint:no-magic-numbers)


/**
* A mortgage calculator component
*/
export function MortgageCalculator({ propertyPrice }) 
{
   const [downPayment, setDownPayment] = useState(20);
   const [interestRate, setInterestRate] = useState(6.5);
   const [loanTerm, setLoanTerm] = useState(30);
  
   const loanAmount = propertyPrice * (1 - downPayment / 100);
}
```
## Suppress Violations by Severity Level

Instead of disabling all violations, selectively ignore violations that match the defined severity levels. For example, suppress warnings or low-priority issues, while continuing to enforce higher-severity violations. This strategy helps maintain code quality by focusing attention on critical issues without being distracted by less important ones.

```
// Code-analyzer-suppress(eslint:(3,4))
export function formatPrice(price, currency = 'USD') 
{
   return new Intl.NumberFormat('en-US', {
       style: 'currency',
       currency: currency
   }).format(price);
}
```
## Disable Suppress and Unsuppress Markers
You can disable suppression markers from the command line or add code to the code-analyzer.yml file. To disable suppression markers across the entire codebase, add this code to the code-analyzer.yml file.

 ```
 suppressions:
  disable_suppressions: true
```
To disable suppression markers from the command line, use this command.

```
sf code-analyzer run --no-suppressions
```

## Considerations
When using suppression and unsuppression markers keep these considerations in mind.
- Use inner parentheses only for severities and not for rule names.
- Only text files are scanned for suppress and unsuppress markers.
- A suppression begins at the marker line and applies to the end of file or until unsuppressed.
- You can’t suppress violations by using tags. Use the same format as the `--rule-selector` flag for `sf code-analyzer` rules or `sf code-analyzer run`.

## See Also
- [Engines](https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/engines.md)
- [Customize the Configuration](https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/config-custom.md)