@@ -16,6 +16,8 @@ export const FIELDS = {
1616 ROOT_WORKING_FOLDER : 'root_working_folder' , // Hidden
1717 CUSTOM_ENGINE_PLUGIN_MODULES : 'custom_engine_plugin_modules' , // Hidden
1818 PRESERVE_ALL_WORKING_FOLDERS : 'preserve_all_working_folders' , // Hidden
19+ SUPPRESSIONS : 'suppressions' ,
20+ DISABLE_SUPPRESSIONS : 'disable_suppressions' ,
1921 RULES : 'rules' ,
2022 ENGINES : 'engines' ,
2123 SEVERITY : 'severity' ,
@@ -48,13 +50,21 @@ export type Ignores = {
4850 files : string [ ]
4951}
5052
53+ /**
54+ * Object containing the user specified suppressions configuration
55+ */
56+ export type Suppressions = {
57+ disable_suppressions : boolean
58+ }
59+
5160type TopLevelConfig = {
5261 config_root : string
5362 log_folder : string
5463 log_level : LogLevel
5564 rules : Record < string , RuleOverrides >
5665 engines : Record < string , EngineOverrides >
5766 ignores : Ignores
67+ suppressions : Suppressions
5868 root_working_folder : string , // INTERNAL USE ONLY
5969 preserve_all_working_folders : boolean // INTERNAL USE ONLY
6070 custom_engine_plugin_modules : string [ ] // INTERNAL USE ONLY
@@ -65,6 +75,7 @@ export const DEFAULT_CONFIG: TopLevelConfig = {
6575 config_root : process . cwd ( ) ,
6676 log_folder : os . tmpdir ( ) ,
6777 log_level : LogLevel . Debug ,
78+ suppressions : { disable_suppressions : false } , // Suppressions enabled by default
6879 rules : { } ,
6980 engines : { } ,
7081 ignores : { files : [ ] } ,
@@ -156,11 +167,12 @@ export class CodeAnalyzerConfig {
156167 validateAbsoluteFolder ( rawConfig . config_root , FIELDS . CONFIG_ROOT ) ;
157168 const configExtractor : engApi . ConfigValueExtractor = new engApi . ConfigValueExtractor ( rawConfig , '' , configRoot ) ;
158169 configExtractor . addKeysThatBypassValidation ( [ FIELDS . CUSTOM_ENGINE_PLUGIN_MODULES , FIELDS . PRESERVE_ALL_WORKING_FOLDERS , FIELDS . ROOT_WORKING_FOLDER ] ) ; // Hidden fields bypass validation
159- configExtractor . validateContainsOnlySpecifiedKeys ( [ FIELDS . CONFIG_ROOT , FIELDS . LOG_FOLDER , FIELDS . LOG_LEVEL , FIELDS . RULES , FIELDS . ENGINES , FIELDS . IGNORES ] ) ;
170+ configExtractor . validateContainsOnlySpecifiedKeys ( [ FIELDS . CONFIG_ROOT , FIELDS . LOG_FOLDER , FIELDS . LOG_LEVEL , FIELDS . RULES , FIELDS . ENGINES , FIELDS . IGNORES , FIELDS . SUPPRESSIONS ] ) ;
160171 const config : TopLevelConfig = {
161172 config_root : configRoot ,
162173 log_folder : configExtractor . extractFolder ( FIELDS . LOG_FOLDER , DEFAULT_CONFIG . log_folder ) ! ,
163174 log_level : extractLogLevel ( configExtractor ) ,
175+ suppressions : extractSuppressionsValue ( configExtractor ) ,
164176 custom_engine_plugin_modules : configExtractor . extractArray ( FIELDS . CUSTOM_ENGINE_PLUGIN_MODULES ,
165177 engApi . ValueValidator . validateString ,
166178 DEFAULT_CONFIG . custom_engine_plugin_modules ) ! ,
@@ -239,6 +251,15 @@ export class CodeAnalyzerConfig {
239251 return this . config . log_level ;
240252 }
241253
254+ /**
255+ * Returns whether suppression markers should be processed.
256+ * When enabled, code-analyzer-suppress/unsuppress markers in source files will filter out violations.
257+ * Returns true by default unless explicitly disabled via suppressions.disable_suppressions config.
258+ */
259+ public getSuppressionsEnabled ( ) : boolean {
260+ return ! this . config . suppressions . disable_suppressions ;
261+ }
262+
242263 /**
243264 * Returns the absolute path folder where all path based values within the configuration may be relative to.
244265 * Typically, this is set as the folder where a configuration file was loaded from, but doesn't have to be.
@@ -358,6 +379,13 @@ function extractIgnoresValue(configExtractor: engApi.ConfigValueExtractor): Igno
358379 return { files } ;
359380}
360381
382+ function extractSuppressionsValue ( configExtractor : engApi . ConfigValueExtractor ) : Suppressions {
383+ const suppressionsExtractor : engApi . ConfigValueExtractor = configExtractor . extractObjectAsExtractor ( FIELDS . SUPPRESSIONS , DEFAULT_CONFIG . suppressions ) ;
384+ suppressionsExtractor . validateContainsOnlySpecifiedKeys ( [ FIELDS . DISABLE_SUPPRESSIONS ] ) ;
385+ const disable_suppressions : boolean = suppressionsExtractor . extractBoolean ( FIELDS . DISABLE_SUPPRESSIONS , DEFAULT_CONFIG . suppressions . disable_suppressions ) || false ;
386+ return { disable_suppressions } ;
387+ }
388+
361389/**
362390 * Validates that a value is a string and is a valid glob pattern.
363391 * Throws an error if the pattern is empty or has unbalanced brackets/braces/parentheses.
0 commit comments