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
Add code fix for MarkMembersStatic (CA1822) #1982
Conversation
I borrowed the code from Fred's original PR dotnet#1116, and extended it to fix the references along with the declaration. We conservatively bail out for cases where the replacement can potentially lead to semantic changes - these will be very rare cases and still cause explicit build break, so I think we should be fine. Fixes dotnet#471 Fixes dotnet#1929
Tagging @Neme12 |
Is it possible that this could in any way be shared with dotnet/roslyn#31838, and if so, should it? That fix would be different in that there shouldn't be any usages to worry about, so maybe it's OK to have completely separate implementations. |
@Neme12 Unfortunately, not as the code is in different repos, and this one is based off a CAXXXX diagnostic generated in FxCop analyzers NuGet package. We can certainly borrow test/product code as appropriate, but sharing seems unlikely. |
Yeah I was thinking the code fix in Roslyn could say it fixes CA1822 in addition to CS0708 through FixableDiagnosticIds but that's way too ugly. |
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Outdated
Show resolved
Hide resolved
...deQuality.Analyzers/Core/QualityGuidelines/MicrosoftQualityGuidelinesAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Outdated
Show resolved
Hide resolved
… inside operation block start. Without this change, the operation block start and nested actions never seem to execute within live analysis in IDE (I will file a separate Roslyn bug for it)
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Outdated
Show resolved
Hide resolved
...rosoft.CodeQuality.Analyzers/VisualBasic/QualityGuidelines/BasicMarkMembersAsStatic.Fixer.vb
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/MarkMembersAsStatic.Fixer.cs
Show resolved
Hide resolved
...icrosoft.CodeQuality.Analyzers/UnitTests/QualityGuidelines/MarkMembersAsStaticTests.Fixer.cs
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.
LGTM. It'd be nice to have some cross language tests.
I borrowed the code from Fred's original PR #1116, and extended it to fix the references along with the declaration. We still conservatively bail out for cases where the replacement can potentially lead to semantic changes (such as say the instance receiver of method invocation itself is an invocation). However, these will be very rare cases and still cause explicit build break, so I think we should be fine. We can refine this behavior in future based on customer feedback.
Fixes #471
Fixes #1929