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.
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.
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.
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.
Suppress specific types of violations while continuing to check for others. For example, ignore the magic numbers rule in the ESLint engine.
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.
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.
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.
To disable suppression markers from the command line, use this command.
When using suppression and unsuppression markers keep these considerations in mind.
- Don’t use comma-separated selectors instead use separate markers for individual rule-names.
- 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-selectorflag forsf code-analyzerrules orsf code-analyzer run.