-
Notifications
You must be signed in to change notification settings - Fork 468
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
Detection of PLINQ nops analyzer #4126
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking as request changes due to few reasons:
- Even though New rule: Detection of PLINQ nops #2812 was marked approved, we now have a process where you will need to file an issue on dotnet/runtime repo for analyzer suggestion. THe issue needs to be approved and also get an approval on the default
RuleLevel
. Note the bar for an analyzer to be a warning by default is very high, it should be only for correctness issues. - We are holding off on more .NET API analyzers for .NET5 - @jeffhandley to confirm. We will need a new branch for post .NET5 analyzers
I see, does that include the analyzers already approved on the dotnet/runtime repo? As a learning exercise I whipped up analyzers for most issue there, if that applies to those analyzer suggestions as well I would stop working on integrating them into roslyn analyzers for a while until point number two is resolved :) |
Codecov Report
@@ Coverage Diff @@
## master #4126 +/- ##
==========================================
+ Coverage 95.78% 95.83% +0.04%
==========================================
Files 1163 1173 +10
Lines 262725 266864 +4139
Branches 15829 16160 +331
==========================================
+ Hits 251656 255738 +4082
- Misses 9064 9077 +13
- Partials 2005 2049 +44 |
…o replaced text based comparison to symbol based
…nto feature/DetectPLINQNops # Conflicts: # src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to be written as an IOperation analyzer, and should not be a build warning by default. I haven't reviewed the code fix provider yet.
…n more in process
@mavasani I migrated the analyzer to an IOperationAnalyzer which worked rather seemlessly. I will have to work on the fixer though, this is the first time coming into contact with the IOperation analyzer and fixer api |
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
{ | ||
var newExpression = ((possibleInvocation as InvocationExpressionSyntax)!.Expression as MemberAccessExpressionSyntax)!.Expression; | ||
possibleInvocation = newExpression; | ||
} while (possibleInvocation is InvocationExpressionSyntax nestedInvocation && nestedInvocation.Expression is MemberAccessExpressionSyntax member && removableEnds.Contains(member.Name.Identifier.ValueText)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to have only a check on the method name as a string? It might be better to check for the method symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I was unclear about as it also came up in my other pr, do we have to recheck everything in the fixer that we already did in the analyzer? I.E. if we warn here we already checked the symbol in the actual analyzer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also bit unclear for me how much needs to be rechecked for the fixer.
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
…jeff/roslyn-analyzers into feature/DetectPLINQNops # Conflicts: # src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsTest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
Closing and re-opening PR to retrigger tests, as we checked in new CI validation step for generated files. |
|
||
context.RegisterCodeFix( | ||
new AsParallelCodeAction( | ||
title: MicrosoftNetCoreAnalyzersResources.RemoveRedundantCall, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we do want to reuse this message or create a new specific one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, I'll adapt this to whatever is decided. It seemed to accurately reflect what the code fix does so I just chose that
src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNops.Fixer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Usage/DetectPLINQNopsAnalyzer.cs
Outdated
Show resolved
Hide resolved
@Mrnikbobjeff FYI, you need to run |
Some unanswered questions remain: Should we create a new Title for the code fix as we are currently reusing |
@Mrnikbobjeff the analyzer has been approved today: dotnet/runtime#33769 Please take a look at the video when you can. The analyzer has been approved for the Performance category, with Warning severity. The message/title/description can be decided/confirmed in the PR. Whether we want all cases to be covered by one ruleID or more than one, can also be decided here, depending on the complexity of each case to cover. We should make sure to verify all the possible combinations:
Besides adding good unit tests, we must ensure to test actual usage in Visual Studio, to double check that the behavior makes sense, and we don't end up offering an empty or incorrect fix. |
Should building the FxCopAnalyzers solution work? the normal analyzer solution builds just fine, FxCopAnalyzers throw some errors though. I do not know whether the files were generated correctly |
@Mrnikbobjeff It should build fine. Have you fixed the merge conflicts? |
@@ -660,6 +660,18 @@ Calls to 'string.IndexOf' where the result is used to check for the presence/abs | |||
|CodeFix|True| | |||
--- | |||
|
|||
## [CA2250](https://docs.microsoft.com/visualstudio/code-quality/ca2250): 'AsParallel' at the end of a LINQ query does not have an effect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging the current master into your branch, you will need to re-run msbuild pack.
The documentation links have moved from VS docs to .NET docs.
In current master you'll see these links are from .NET docs (while your branch is still on the old VS docs links).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please retarget this PR to https://github.com/dotnet/roslyn-analyzers/tree/release/6.0.1xx-preview1
PR needs to target |
Fixes #2812
Fixes dotnet/runtime#33769