-
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
Tiny Refactoring CA1824 #5124
Tiny Refactoring CA1824 #5124
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5124 +/- ##
=======================================
Coverage 95.53% 95.54%
=======================================
Files 1202 1202
Lines 275961 276035 +74
Branches 16641 16641
=======================================
+ Hits 263648 263731 +83
- Misses 10119 10124 +5
+ Partials 2194 2180 -14 |
{ | ||
if (!CheckAttribute(nc.Node)) | ||
var attributeSyntax = (AttributeSyntax)context.Node; |
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.
Previous code was having the possibility that the Node
isn't a AttributeSyntax
, it also doesn't look possible but I am wondering if that was done for a specific reason or just by "node is generic so let's work in the generic case".
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.
@Evangelink It should always be AttributeSyntax
since we do RegisterSyntaxNodeAction(...., SyntaxKind.Attribute)
@@ -53,9 +53,26 @@ public override void Initialize(AnalysisContext context) | |||
|
|||
context.RegisterCompilationStartAction(cc => | |||
{ | |||
var hasResource = false; | |||
INamedTypeSymbol? generatedCode = cc.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCodeDomCompilerGeneratedCodeAttribute); |
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.
[cosmetic][minor] You could use the TryGetXXX
instead of doing get then null check.
@@ -53,9 +53,26 @@ public override void Initialize(AnalysisContext context) | |||
|
|||
context.RegisterCompilationStartAction(cc => |
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.
As you have done some extra refactorings, it might be worth also renaming cc
into context
.
Thanks for review @Evangelink. I addressed your feedback. |
Closes #5123
First commit:
Main idea is to move the line:
from
CheckResxGeneratedFile
toRegisterCompilationStartAction
and bail-out early if needed.Extra cleanups:
SyntaxKind.Attribute
.nc
tocontext
Second commit:
Move
TryCheckNeutralResourcesLanguageAttribute
to compilation start to avoid unnecessary callbacks when we're sure there is no diagnostics to be produced.