Skip to content

Metrics analyzer for Razor: Lines of code are outside the range of the file#9299

Merged
gregory-paidis-sonarsource merged 3 commits intomasterfrom
costin/fix-out-of-range
May 22, 2024
Merged

Metrics analyzer for Razor: Lines of code are outside the range of the file#9299
gregory-paidis-sonarsource merged 3 commits intomasterfrom
costin/fix-out-of-range

Conversation

@costin-zaharia-sonarsource
Copy link
Member

@costin-zaharia-sonarsource costin-zaharia-sonarsource commented May 17, 2024

Fixes #9288

For performance reasons, I want to avoid counting the file lines in the utility analyzers. To reduce the IO operations during analysis. An additional reason is that any information we get about invalid data will be lost during analysis (we don't have logs).

The idea is to do a check on the plugin side to see if the data we send to the server is valid. If it's not, we will log a debug message with the file name and the line number.

@costin-zaharia-sonarsource costin-zaharia-sonarsource force-pushed the costin/fix-out-of-range branch 2 times, most recently from 57b9c6b to a37fa52 Compare May 17, 2024 15:58
@@ -1 +1 @@
Roslyn version: 4.8.0.0Language version: CSharp12!Concurrent execution: enabled��File 'Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\OverlapSymbolReferences_razor.g.cs' was recognized as razor generated��File 'Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Cases_razor.g.cs' was recognized as razor generatedvrFile 'C:\Users\martin.strecker\Desktop\WebAss\obj\Debug\net8.0\WebAss.AssemblyInfo.cs' was recognized as generated��File 'C:\Users\martin.strecker\Desktop\WebAss\obj\Debug\net8.0\.NETCoreApp,Version=v8.0.AssemblyAttributes.cs' was recognized as generated No newline at end of file
Copy link
Contributor

@andrei-epure-sonarsource andrei-epure-sonarsource May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep the old tests as well? (for regression testing)

Copy link
Member Author

@costin-zaharia-sonarsource costin-zaharia-sonarsource May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reflect the behavior of both versions of Roslyn?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

- and update the pb files with data produced by dotnet 8.0.5
@sonarqubecloud
Copy link

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed for 'SonarAnalyzer for .NET'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey dude, this looks very nice and well-tested.
I left a couple of questions, mostly for curious/educational reasons.
I don't assume many changes will be needed, after my questions it will probably be approved. :)

.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

for (int groupKey : groups.keySet()){
verify(context, times(groups.get(groupKey).intValue())).setIntValue(key, groupKey, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit hard to understand what you are doing here.
Why do you group the lines and then do times?
From debugging they are always the unique.
How could it be that a group has more than one occurrence of each line?

Do you want to make sure exactly this? That every line appears ONLY once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple files with test cases are added to the context, we can have lines reported multiple times. This was the behavior before my changes when the test base class added files to the context.

Strictly speaking, this is now used only to check that each element is added only once, and the query can be simplified. I wanted to have this method able to check duplicates, so we can easily add test cases in the future.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the explanations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics analyzer for Razor: Lines of code are outside the range of the file

3 participants