-
Notifications
You must be signed in to change notification settings - Fork 10.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
Implement BL0007: Component parameters should be auto property #30102
Implement BL0007: Component parameters should be auto property #30102
Conversation
689c9ef
to
f1dcb04
Compare
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
f1dcb04
to
7794171
Compare
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
dff7fe1
to
53a8cc4
Compare
}); | ||
} | ||
|
||
private async Task<bool> IsSameSemanticAsAutoPropertyAsync(IPropertySymbol symbol, CancellationToken cancellationToken) |
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 method attempts to handle #26230 (comment).
Feel free if you want me to revert and not handle it.
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/Analyzers/src/UseParameterAttributeCorrectlyAnalyzer.cs
Outdated
Show resolved
Hide resolved
var setterAccessor = syntax.AccessorList.Accessors[1]; | ||
if (getterAccessor.IsKind(SyntaxKind.SetAccessorDeclaration)) | ||
{ | ||
// Swap if necessary. |
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 deserves a comment.
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.
@pranavkm Did you mean a more explanatory comment?
(getterAccessor, setterAccessor) = (setterAccessor, getterAccessor); | ||
} | ||
|
||
if (!getterAccessor.IsKind(SyntaxKind.GetAccessorDeclaration) || !setterAccessor.IsKind(SyntaxKind.SetAccessorDeclaration)) |
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 didn't read the rest of this method, but is there a way to detect this by inspecting if the getters / setters are compiled generated?
@sharwell in case you have suggestions. We're basically trying to determine that a property is an auto-property. public string Prop1 { get; set; }
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.
@pranavkm This method isn't for detecting auto property, but full-properties with the same semantics. See the comments in the linked issue.
e25039f
to
f32b747
Compare
41206a8
to
7c830ae
Compare
1c6492d
to
2f1ed38
Compare
src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertyTest.cs
Outdated
Show resolved
Hide resolved
src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertiesTest.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.
New files need MIT license headers.
@Youssef1313 sorry this PR has been sitting in the backburner so far. While we would like to take this change, there's some concern about adding it to the default set of analyzers and producing warnings in 3.1 or 5.0 Blazor apps. There's a couple of options we could approach this (including shipping analyzers in the runtime pack) which might mitigate this. Unfortunately I haven't been able to follow up on this. Given how close we're to calling 6.0 done, I'm hoping to get back to this early in 7.0 so we give any choice we make enough time to bake. |
@pranavkm looks like this is still relevant and you want to get back to this soon, don't you? |
This is an attempt to resolve the open dotnet#30102 PR. Microsoft.AspNetCore.Components.Analyzers ships as a part of the .NET SDK and the analysis applies to all apps starting in .NET 3.1 or newer. Adding new analyzers to this assembly was problematic since it would result in new warnings in existing apps when users updated the SDK. This PR forks the Component.Analyzers to produce a new Components.SDKAnalyzers analyzer assembly. Components.Analyzers is also added to the targeting pack so it allows us to produce TFM specific analysis.
* Fork component analyzers This is an attempt to resolve the open #30102 PR. Microsoft.AspNetCore.Components.Analyzers ships as a part of the .NET SDK and the analysis applies to all apps starting in .NET 3.1 or newer. Adding new analyzers to this assembly was problematic since it would result in new warnings in existing apps when users updated the SDK. This PR forks the Component.Analyzers to produce a new Components.SDKAnalyzers analyzer assembly. Components.Analyzers is also added to the targeting pack so it allows us to produce TFM specific analysis. * Apply suggestions from code review Co-authored-by: Tanay Parikh <TanayParikh@users.noreply.github.com> Co-authored-by: Tanay Parikh <TanayParikh@users.noreply.github.com>
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.
Other than the lovely MIT license and trailing whitespace, anything you need me to look at @pranavkm❔
Nope. Thanks for fixing up the whitespace. |
Hi @Youssef1313. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Fixes #26230
TODOs:
Wanted to get an initial review before proceeding.