-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analysis results paths are pointing to generated code instead of the Razor files #71449
Comments
@jaredpar I'm not super familiar with the Sarif stuff, but I would assume it's just reporting the It doesn't seem too out there but would need new roslyn APIs to support this. |
@costin-zaharia-sonarsource We're working on fixing the GetMappedLineSpan issues in an upcoming release. With those fixed, would you still need to use the sarif paths? |
I don't think I follow this request. It seems like maybe the ask is for Roslyn to change GetLocation to honour Also, it seems to me like if the
Isn't this exactly what Seems like either the analyzer should report locations in the generated C# file, and let the user deal with that (it's non-trivial to get a |
Hi @chsienki, that's great, thanks for working on this. If the GetMappedLineSpan returns the right locations, it will fix a couple of issues on our side. We will be able to display the right location in SQ, and SC and improve the precision for the highlighting we show on the server. Do you have maybe an issue we can track? #69248 seems to be closed. At the same time, since we import our data from the Sarif reports, we will still have to report on the actual .razor/.cshtml files instead of the generated ones. So we can correctly map the diagnostics to the code, on the SQ\SC server side. Using manual mapping is not a big problem for us (if the returned paths are correct), but, if I understand correctly from @davidwengier in this comment, this works against the compiler design and might be a source of issues and unexpected behavior. My understanding is that issues like dotnet/razor#9308 and dotnet/razor#9108 are caused by the fact that our diagnostics point to the .razor files instead of the generated ones. Please correct me if I misunderstood. |
No, this request is about having in SARIF report the paths to the .razor/.cshtml files instead of the generated one.
This is my concern, that by doing manual mappings we are not using the compiler API in the way it was designed. |
Looking at this today it seems that when emitting the file.uri property the SARIF logger is using the original location not the mapped location. That is contrary to how we display the diagnostic during build where we use the mapped span. Essentially:
Is this a deliberate decision or something we can change? |
In discussion with @mavasani it appears that it's an oversight that we can fix here. @RikkiGibson can you try and get this in for 17.9? It should be a pretty straight forward change. |
Resolved in #71454 |
For the diagnostics reported in
.razor
files, the locations are pointing to the generated files instead of the actual razor files.E.g. when a diagnostic is reported on the
IncrementCount
identifier from the following code (Counter.razor
file)The Sarif report contains:
You can find here a reproducer. It contains already the generated Sarif report (
BlazorWebApp\BuildOutput.sarif
)When working on custom code analyzers and development tools in general, it is very useful to have access to the original location of the syntax. For sonar-dotnet analyzers, we need the correct locations to be able to import and display the issues on SonarQube and SonarCloud.
We tried to do the mapping ourselves (by using GetMappedLineSpan) but the API offers limited functionality, and we often encounter issues like #69248. This has also unexpected behavior in the IDE like dotnet/razor#9308 or dotnet/razor#9108.
@davidwengier explained here that:
tl;dr
Would it be possible to change paths for the diagnostics in razor files to point to the original files instead of the generated ones?
The text was updated successfully, but these errors were encountered: