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.
1ignores:2 files:3 - "**/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.
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.
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.
1// Code-analyzer-suppress(all)2export function formatPrice(price, currency = 'USD') 3{4 return new Intl.NumberFormat('en-US', {5 style: 'currency',6 currency: currency7 }).format(price);8}9// Code-analyzer-unsuppress(all)10/**11 * Calculate mortgage payment12 * @param {number} principal - Loan amount13 * @param {number} annualRate - Annual interest rate (e.g., 0.05 for 5%)14 * @param {number} years - Loan term in years15 * @returns {number} Monthly payment16 */1718export function calculateMortgage(principal, annualRate, years) 19{20 const monthlyRate = annualRate / 12;21 const numPayments = years * 12;2223 if (monthlyRate === 0) {24 return principal / numPayments;25 }2627 const payment = principal * 28 (monthlyRate * Math.pow(1 + monthlyRate, numPayments)) / 29 (Math.pow(1 + monthlyRate, numPayments) - 1);3031 return Math.round(payment * 100) / 100;32}
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.
1// Code-analyzer-suppress(eslint:no-magic-numbers)2export function formatPrice(price, currency = 'USD')3{4 return new Intl.NumberFormat('en-US', {5 style: 'currency',6 currency: currency7 }).format(price);8}
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.
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.
1// Code-analyzer-suppress(eslint)2export function formatPrice(price, currency = 'USD') {3 return new Intl.NumberFormat('en-US', {4 style: 'currency',5 currency: currency6 }).format(price);7}8// Code-analyzer-unsuppress(sfge)9/**10 * Calculate mortgage payment11 * @param {number} principal - Loan amount12 * @param {number} annualRate - Annual interest rate (e.g., 0.05 for 5%)13 * @param {number} years - Loan term in years14 * @returns {number} Monthly payment15 */1617export function calculateMortgage(principal, annualRate, years)18 {19 const monthlyRate = annualRate / 12;20 const numPayments = years * 12;2122 if (monthlyRate === 0) {23 return principal / numPayments;24 }2526 const payment = principal * 27 (monthlyRate * Math.pow(1 + monthlyRate, numPayments)) / 28 (Math.pow(1 + monthlyRate, numPayments) - 1);2930 return Math.round(payment * 100) / 100;31}
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.
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.
1// Code-analyzer-suppress(eslint:(3,4))2export function formatPrice(price, currency = 'USD') 3{4 return new Intl.NumberFormat('en-US', {5 style: 'currency',6 currency: currency7 }).format(price);8}
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.
1suppressions:2 disable_suppressions: true
To disable suppression markers from the command line, use this command.
1sf 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.