rules repository

G-1910

🆓
Info

Avoid using the NOSONAR marker.

Reason

SonarQube uses the NOSONAR marker to quickly exclude false positives. But when used often and increasingly this is a potential sign of hidden quality issues.

Furthermore, a NOSONAR marker hides all issues on a line. Without a comment, the reader does not know why it was introduced. A more powerful alternative is to use the dbLinter marker, which can be set for various scopes (file, statement, function or procedure). The syntax is @DBLINTER IGNORE(rule1 [, rule2]...) [comment].

Examples

Non-Compliant Example

declare
   l_value pls_integer := null; -- NOSONAR G-2140: False positive
begin
   sys.dbms_output.put_line(l_value);
end;
/
Issues
LineColumnMessage
236NOSONAR marker.

Hides the G-2140 violation (Never initialize variables with NULL).

Compliant Solution - ★☆☆☆☆

declare
   l_value pls_integer := null; -- @dbLinter ignore(G-2140) False positive
begin
   sys.dbms_output.put_line(l_value);
end;
/

The NOSONAR marker has been replaced with a @dbLinter ignore marker. This indicates that a G-2140 violation has been ignored. However, this is not a false positive.

Compliant Solution - ★★★☆☆

declare
   l_value pls_integer := null;
begin
   sys.dbms_output.put_line(l_value);
end;
/

The NOSONAR marker is removed. The G-2140 violation is not hidden anymore.

Compliant Solution - ★★★★★

declare
   l_value pls_integer;
begin
   sys.dbms_output.put_line(l_value);
end;
/

The G-2140 violation is resolved. Code is not unnecessarily initialized with null anymore.

Parameters

Use parameters to customize the rule to your needs.

ParameterDescriptionDefault Value
AllowNosonarMarkersComma-separated list of rules for which a NOSONAR marker is allowed.Core G-1910, Core G-1920, Core G-7460

References