-
Notifications
You must be signed in to change notification settings - Fork 232
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
Fix S4200 FN: Add support for LibraryImportAttribute; run only on non-generated code #6603
Fix S4200 FN: Add support for LibraryImportAttribute; run only on non-generated code #6603
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.
This introduces a difference in the existing behavior of the rule --> please update the PR title description, as this will show up in the github history
analyzers/tests/SonarAnalyzer.UnitTest/Rules/NativeMethodsShouldBeWrappedTest.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/NativeMethodsShouldBeWrapped.CSharp11.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/NativeMethodsShouldBeWrapped.CSharp11.cs
Outdated
Show resolved
Hide resolved
...ts/SonarAnalyzer.UnitTest/TestCases/NativeMethodsShouldBeWrapped.CSharp11.SourceGenerator.cs
Show resolved
Hide resolved
@@ -34,20 +34,28 @@ public sealed class NativeMethodsShouldBeWrapped : SonarDiagnosticAnalyzer | |||
protected override void Initialize(SonarAnalysisContext context) | |||
{ | |||
context.RegisterSymbolAction(ReportPublicExternalMethods, SymbolKind.Method); | |||
context.RegisterSyntaxNodeAction(ReportTrivialWrappers, SyntaxKind.MethodDeclaration); | |||
context.RegisterSyntaxNodeActionInNonGenerated(ReportTrivialWrappers, SyntaxKind.MethodDeclaration); |
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.
[education] why is this necessary to not be raised on generated code?
I get why it's necessary for the case of LibraryImport
(to not raise the issue twice + users don't control the source generator) - is it the case that in general we should not raise on generated code ever?
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.
Yes. It was requested by Pavel at one point that we should fix this here. I added it as item 4 on the todo list here #6488 when he suggested it. It is also needed to properly support the LibraryImport attribute.
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.
the PR name should reflect that IMO because it's a change of functionality for the whole rule and it's not only related to adding support for a new attribute
8f42977
to
eaa35c1
Compare
eaa35c1
to
88283c0
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
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, I will update the PR name and put in the message the info about non generated detection change of functionality
@@ -34,20 +34,28 @@ public sealed class NativeMethodsShouldBeWrapped : SonarDiagnosticAnalyzer | |||
protected override void Initialize(SonarAnalysisContext context) | |||
{ | |||
context.RegisterSymbolAction(ReportPublicExternalMethods, SymbolKind.Method); | |||
context.RegisterSyntaxNodeAction(ReportTrivialWrappers, SyntaxKind.MethodDeclaration); | |||
context.RegisterSyntaxNodeActionInNonGenerated(ReportTrivialWrappers, SyntaxKind.MethodDeclaration); |
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.
the PR name should reflect that IMO because it's a change of functionality for the whole rule and it's not only related to adding support for a new attribute
Part of #6488
Related to #6476
Rule S4200 should support LibraryImportAttribute.