-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add analyzer for detecting mismatched endpoint parameter optionality #36154
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
Conversation
src/Framework/Analyzer/src/DelegateEndpoints/DelegateEndpointFixer.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/src/DelegateEndpoints/DetectMismatchedParameterOptionality.Fixer.cs
Outdated
Show resolved
Hide resolved
|
||
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; | ||
|
||
public partial class DelegateEndpointFixer : CodeFixProvider |
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.
Why do we need to split this across two different files?
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 was following the pattern we currently use for analyzers because I think it makes sense. One main file where all the definitions are registered and then each codefix in its own file.
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's far less likely we would re-use a single codefix for all of these scenarios. The analyzers were useful to share because they were detecting the same thing - viz calls to MapGet. It's less common to want to do that with the codefix. In addition, code fixes aren't on a hot path
src/Framework/Analyzer/src/DelegateEndpoints/DetectMismatchedParameterOptionality.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/src/DelegateEndpoints/DetectMismatchedParameterOptionality.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/test/Verifiers/CSharpAnalyzerVerifier.cs
Outdated
Show resolved
Hide resolved
|
||
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; | ||
|
||
public partial class DetectMismatchedParameterOptionalityTest |
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.
Could you add unit tests for the tokenizer e.g. : https://github.com/dotnet/aspnetcore/pull/35732/files#diff-742e27fb1eae81bcb0bfd8113ccc306c0add53e7ee7c13b85d9c1917c974b9b5R14-R34?
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.
Ah forgot we talked about this! I coped over the test cases here and included a few interesting ones from https://github.com/dotnet/aspnetcore/blob/b46c5d5e15bdc6e4babd5194e0a1723d3e9cfc46/src/Http/Routing/test/UnitTests/Template/TemplateParserTests.cs
58aea48
to
d93e1c1
Compare
d93e1c1
to
1ab519c
Compare
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.
Looks good to me. Could we make the one change to separate out analyzers and codefixes to separate assembly before getting this merged?
|
||
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; | ||
|
||
public partial class DelegateEndpointFixer : CodeFixProvider |
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's far less likely we would re-use a single codefix for all of these scenarios. The analyzers were useful to share because they were detecting the same thing - viz calls to MapGet. It's less common to want to do that with the codefix. In addition, code fixes aren't on a hot path
|
||
namespace Microsoft.AspNetCore.Analyzers.DelegateEndpoints; | ||
|
||
public partial class DelegateEndpointFixer : CodeFixProvider |
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.
Sam's suggestion was to put code fixes in a different assembly since it depends on the workspaces assembly. Could we do that?
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.
Yep -- I recall this now.
@sharwell Can you sanity check that the packaging was done directly here?
Also, do they still need to be split out even if the CodeFixes don't take an explicit dependency on the Microsoft.CodeAnalysis.Workspaces
assembly?
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.
Also, do they still need to be split out even if the CodeFixes don't take an explicit dependency on the
CodeFixProvider is defined in Microsoft.CodeAnalysis.Workspaces, so it's impossible to avoid.
src/Framework/Analyzer/src/DelegateEndpoints/DetectMismatchedParameterOptionality.cs
Outdated
Show resolved
Hide resolved
src/Framework/Analyzer/test/MinimalActions/DetectMismatchedParameterOptionalityTest.cs
Outdated
Show resolved
Hide resolved
3927aae
to
a208204
Compare
src/Framework/AspNetCoreAnalyzers/src/Analyzers/Microsoft.AspNetCore.App.Analyzers.csproj
Outdated
Show resolved
Hide resolved
src/Framework/AspNetCoreAnalyzers/src/CodeFixes/DetectMismatchedParameterOptionalityFixer.cs
Show resolved
Hide resolved
src/Framework/AspNetCoreAnalyzers/src/CodeFixes/DetectMismatchedParameterOptionalityFixer.cs
Outdated
Show resolved
Hide resolved
a208204
to
6d083a0
Compare
@dotnet/aspnet-build Can I get help merging? |
No 😀 |
…36154) * Add analyzer for detecting mismatched endpoint parameter optionality * Address feedback from code review * Factor out CodeFixes and Analyzers to separate assemblies * Address more feedback from review * Address code checks
…rectories (#36379) * Add analyzer for detecting mismatched endpoint parameter optionality (#36154) * Add analyzer for detecting mismatched endpoint parameter optionality * Address feedback from code review * Factor out CodeFixes and Analyzers to separate assemblies * Address more feedback from review * Address code checks * Clean up folder structure * Update solution file and address feedback * Update src/Framework/Framework.slnf Co-authored-by: Doug Bunting <6431421+dougbu@users.noreply.github.com> * Add test project to solution file Co-authored-by: Doug Bunting <6431421+dougbu@users.noreply.github.com>
Fixes #34553.