Skip to content

How To: Suppress Analysis Rule Violations

All existing standard batch rules can be suppressed using a suppression mark. The suppression mark is a single line or multiline comment containing a specific tag and the rule name.

The default rule suppression mark has the format IGNORE:RULELIST (SCOPE) - REASON and it can be changed using the RuleSuppressionMark rule parameter.

RULELIST - a comma-separated list that can contain rule names, group names, or * (Asterisk symbol) for specifying all active rules.

For example – IGNORE: SA0001,SA0023,EX0018, Design

REASON - can be any single line string that will be used as a reason for the suppression of the rules.

(SCOPE) - optional scope for the suppression mark. Can be any of the following: BATCH, STATEMENT, LINE, START, END

If a scope is not provided, the suppression mark will be applied to the last issue that appears before the suppression comment and is on the same line.

⚡ ** note: ** The issue suppression applies only to the code rules. The Context Only rules cannot be suppressed in the same way.

1.To suppress a specific violation in the SQL code, the suppression mark must be placed on the same line and somewhere after the highlighted token. A suppression mark added in front of the matched by the rule token will not be visible to the rule and will be ignored.

2.In case the rule marks a specific statement, it is recommended to use the STATEMNET scope.

SELECT *
WHERE CustomerID=@CustomerID
AND ShippedDate!=NULL /*IGNORE:SA0001 - suppression will be cosidered */
AND /*IGNORE:SA0001 - suppression not visible and won't be considered */ RequiredDate != NULL

Suppression marks can be applied for one or more rule violations and also for the rule violations on a line, for the statement, or for the whole batch.

To suppress a specific rule, the suppression mark must be placed on the same line and after the highlighted token - IGNORE:RULENAME - REASON . The example suppression mark will apply for the last SA0001 violation which appears on the line:

SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL -- IGNORE:SA0001

To suppress all rule violations on a given line, the suppression mark must be suffixed with (LINE) - IGNORE:RULENAME(LINE) . The example suppression mark will apply for all SA0001 violations that appear on the line:

SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL -- IGNORE:SA0001(LINE)

To suppress a rule in a statement, the suppression mark must be suffixed with (STATEMENT) - IGNORE:RULENAME(STATEMENT) . The suppression mark can appear anywhere in a comment inside the statement or just following the statement.

For example:

SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL
-- IGNORE:SA0001(STATEMENT)

For block suppression, a pair of (START) and (END) suppression scopes can be used.

/*IGNORE:SA0001,SA0028 (START) - example */
SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND
RequiredDate != NULL dbo.SomeFunc('120,00$') > 5
/*IGNORE: (END)*/

For example, to suppress issues in a block of SQL code:

In the example, both rules SA0001 and SA0028 will be suppressed.

-- IGNORE:SA0001,SA0028(START)
SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL dbo.SomeFunc('120,00$') > 5
-- IGNORE:(END)

To suppress a rule in a batch, the suppression mark must be suffixed with (BATCH) - IGNORE:RULENAME(BATCH) . The suppression mark can appear anywhere in a comment inside the batch.

In the example, the rule violations in both statements will be suppressed.

GO
-- IGNORE:SA0001(BATCH)
SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL
SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL
GO

To suppress not just a specific rule, but all rules in a scope, the * can be used instead of a rule name:

  • Suppress all rules in a batch:
/*IGNORE:*(BATCH)*/

In the example, all rules will be suppressed.

-- IGNORE:*(BATCH)
SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL dbo.SomeFunc('120,00$') > 5
  • Suppress all rules in a statement:
/*IGNORE:*(STATEMENT)*/

In the example, both rules SA0001 and SA0028 will be suppressed.

SELECT *
FROM Orders /*IGNORE:*(STATEMENT)*/
WHERE ShippedDate !=NULL AND RequiredDate != NULL dbo.SomeFunc('120,00$') > 5
  • Suppress all rules on a line:
/*IGNORE:*(LINE)*/

In the example, both rules SA0001 and SA0028 will be suppressed.

SELECT *
FROM Orders
WHERE ShippedDate !=NULL AND RequiredDate != NULL dbo.SomeFunc('120,00$') > 5 /*IGNORE:*(LINE)*/

The reporting of syntax errors in a batch can be suppressed using the /*IGNORE:ER*(BATCH)*/ comment.

SELECT x.$(ColumnName)
FROM Person.Person x
WHERE x.BusinessEntityID < 5; /*IGNORE:ER*(BATCH) - syntax errors expected due to SQLCMD variable usage*/

The /*IGNORE:*(BATCH)*/ comment, can also be used, but it has to be added as a first element in each SQL batch where the syntax errors should be suppressed.

/*IGNORE:*(BATCH)*/
SELECT x.$(ColumnName)
FROM Person.Person x
WHERE x.BusinessEntityID < 5;

The syntax error suppression can be useful in scenarios where the analyzed SQL script contains some SQLCMD specific commands.

SQL Enlight’s parser doesn’t recognize such commands and will produce syntax error messages in the analysis report.

In order to ignore such errors, the /*IGNORE:*(BATCH)*/ comment can be added inside each SQL batch.

The syntax errors can also be suppressed from the SQL Enlight Settings, for the analysis in general.

See for details.