Click or drag to resize

How To: Suppress Analysis Rule Violations

Suppression Mark

All exiting 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 for has the format IGNORE:RULENAME and it can be changed using the RuleSuppressionMark rule parameter.

Note Note

The rule suppression applies only for Batch rules. The Context Only rules cannot be suppressed in the same way.

General rules for suppression
  1. To suppress a specific violation in the SQL code, the suppression mark must be placed just after to 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, the suppression comment can be anywhere inside or just after the statement. In this case it can be also after the statement delimiting semicolon. Usually when a statement is marked, its main keyword is highlighted (for example: SELECT, DELETE, CREATE, ALTER and etc.). In this case it is possible to put the suppression comment not only after the marked keyword, but anywhere in the statement or just after the statement.

    1SELECT     *
    2WHERE      CustomerID=@CustomerID
    3       AND ShippedDate!=NULL /*IGNORE:SA0001 - suppression will be cosidered */ 
    4       AND /*IGNORE:DR0034 - suppression not visible and won't be considered */ RequiredDate != NULL
  3. If the matched by the rule element is in a comma separated list, the suppression comment must be placed after the matched element, but before the comma. For example the first COUNT DISTINCT will be suppressed, but the second suppression will be missed:

    1SELECT 
    2COUNT(DISTINCT Quantity) /*IGNORE:DR0002*/, 
    3ProductId
    4COUNT(DISTINCT Quantity2), /*IGNORE:DR0002*/
  4. When the matched element is an operator of some kind, the rule suppression mark can be added either next to the first or second operand, or to next to the operator.

    1SELECT * FROM Asset A           
    2WHERE  A.IsArchived != 0 /* IGNORE:SA0023 */ AND 
    3(@Category IS NULL OR /*IGNORE:DR0006*/ A.CategoryId = @Category)
  5. If a function call is to be suppressed, the mark can be after the second parenthesis, inside the parenthesis or next to the function name.

    1SELECT * FROM Table1 WHERE dbo.SomeFunc('120,00$') /*IGNORE:SA0028*/ > 5
Suppression Mark Scope

Suppression mark can be applied for specific rule violation, for all rule violations on a line, for statement or for whole batch.

Line

To suppress a rule 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 which appear on the line:

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

Statement

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:

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

Batch

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.

 1 GO
 2-- IGNORE:SA0001(BATCH)
 3 SELECT     *
 4 FROM       Orders
 5 WHERE     ShippedDate !=NULL AND RequiredDate != NULL 
 6
 7     SELECT     *
 8 FROM       Orders
 9 WHERE     ShippedDate !=NULL AND RequiredDate != NULL 
10 GO

All rules at once suppression

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:

    1/*IGNORE:*(BATCH)*/

    In the example all rules will be suppressed.

    1-- IGNORE:*(BATCH)
    2SELECT     *
    3FROM       Orders
    4WHERE     ShippedDate !=NULL AND RequiredDate != NULL  dbo.SomeFunc('120,00$') > 5
  • Suppress all rules on a line:

    1/*IGNORE:*(STATEMENT)*/

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

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

    1/*IGNORE:*(LINE)*/

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

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

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

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 form the SQL Enlight Settings, for the analysis in general.

See Analysis Settings for details.