How to ignore a specific rule on a single line (JS/TS/CSS/HTML)

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: Typescript, javascript, CSS, HTML

I have configured SonarCloud to scan an Angular application. Some of the issues that are being raised are not relevant for the framework (e.g. SonarCloud complains about using ::ng-deep pseudo selector even though it is a valid Angular pseudo selector).

I do not want to disable the rule globally and I do not want to stop SonarCloud from scanning the files that have “issues” in them. I want a way to tell SonarCloud to ignore a specific rule for a specific line.

Is there a way to do this? If not, is this something that can be added to your backlog?

Hi @jturner and welcome to the community.

If this is a false positive to you, then can you please give use the rule number and a quick repro step so we can have a look ?

It’s not always the good choice to ignore rules on a specific line, especially if this is a FP on our side.

Thank you !

Hi @mickaelcaro,

The rule number is css:S4660.

This is the code that is breaking the rule:

::ng-deep .mat-horizontal-content-container { ... }

I don’t think it’s a FP on your side. The “::ng-deep” pseudo element selector is a valid pseudo element within an Angular application, but if it was in a React application then it would be an error.

Hi,

It’s more valuable to fix FPs than ignore them. Here is the ticket which will exclude ::ng-deep from this rule.