CSS scanner throwing errors on Razor template files

Since a few weeks, sonar lint throws the following errors on code analysis. It looks like there is something doing checks for CSS files on cshtml (Razor Template) files, but is bugged out by the Razor syntax. I’m not sure what to do about it and would like the false errors to disappear. If the css parser can’t handle Razor files, it probably shouldn’t scan such files in the first place. An excerpt from the build output:

##[section]Starting: Run code analysis
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.6.3
Author       : sonarsource
Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
[command]C:\VSTS2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.7.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.6.2
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
12:11:40.749  12:11:40.749  WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.
Calling the SonarQube Scanner...
INFO: Scanner configuration file: C:\VSTS2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.7.0\classic-sonar-scanner-msbuild\sonar-scanner-3.3.0.1492\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\VSTS2\_work\36\.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
...
INFO: ------------- Run sensors on module ...
INFO: Sensor SonarCSS Metrics [cssfamily]
INFO: Sensor SonarCSS Metrics [cssfamily] (done) | time=72ms
INFO: Sensor SonarCSS Rules [cssfamily]
##[error]ERROR: Failed to parse [...]/site.css, line 106, Unknown word
ERROR: Failed to parse [...]/site.css, line 106, Unknown word
##[error]ERROR: Failed to parse [...].cshtml, line 106, Unclosed bracket
ERROR: Failed to parse [...].cshtml, line 106, Unclosed bracket
##[error]ERROR: Failed to parse [...].cshtml, line 34, At-rule without name
ERROR: Failed to parse [...].cshtml, line 34, At-rule without name
##[error]ERROR: Failed to parse [...].cshtml, line 64, At-rule without name
ERROR: Failed to parse [...].cshtml, line 64, At-rule without name
##[error]ERROR: Failed to parse [...].cshtml, line 147, At-rule without name
ERROR: Failed to parse [...].cshtml, line 147, At-rule without name
##[error]ERROR: Failed to parse [...].cshtml, line 14, At-rule without name
ERROR: Failed to parse [...].cshtml, line 14, At-rule without name
##[error]ERROR: Failed to parse [...].cshtml, line 60, Unclosed bracket
ERROR: Failed to parse [...].cshtml, line 60, Unclosed bracket
##[error]ERROR: Failed to parse [...].cshtml, line 59, Unclosed bracket
ERROR: Failed to parse [...].cshtml, line 59, Unclosed bracket
##[error]ERROR: Failed to parse [...].cshtml, line 17, At-rule without name
ERROR: Failed to parse [...].cshtml, line 17, At-rule without name
##[error]ERROR: Failed to parse [...].cshtml, line 60, Unclosed bracket
ERROR: Failed to parse [...].cshtml, line 60, Unclosed bracket
##[error]ERROR: Failed to parse [...].cshtml, line 38, Unclosed bracket
ERROR: Failed to parse [...].cshtml, line 38, Unclosed bracket
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=6742ms
3 Likes

Commenting to hopefully gain some traction on this problem.

This is still happening. I would love to see a fix for this!

Hi!

I’m just getting started with SonarCloud, and I’ve hit the same issue - for me, it looks like it’s preventing any analysis being published (using SC as part of an automated build process).

It looks like the same issue is being reported hereby @Andrei_Epure :

I’m going to see if, for now, I can find a way to exclude the affected files from analysis. Otherwise, we may not be moving ahead with SonarCloud…

Thanks,

Andrew

hi @AndrewStevens . Thanks for raising the point.

Could you please share:

  • the verbose output of the command (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of END step)?
  • a file where the problem occurs (so we can repro on our side)?

Hi @Andrei_Epure

Is there a private address where I can send the logs / sample file? I’m not able to upload that to the forum.

Thanks,

Andrew

I’ve just re-run the analysis including CSHTML files, and this time it worked!

Hi,

This issue will tackle your problem

1 Like