-
Notifications
You must be signed in to change notification settings - Fork 231
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
S3900: Fix issue message for constructors #7018
S3900: Fix issue message for constructors #7018
Conversation
d1fa962
to
d6211d9
Compare
37fcc37
to
0b3df44
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.
LGTM
As discussed offline, I wonder whether this change is really needed.
I understand that in principle this is required to align the new implementation to the old one, which used to emit a different message for the specific scenario where the method parameter dereference is done in a this
constructor initializer, or in a base
constructor initialized.
However, this change requires using the syntactic model in the implementation of the rule, coupling (more) the rule to the underlying language, whereas the previous check was at symbolic level and it was quite clean (SemanticModel.GetDeclaredSymbol(Node).IsConstructor
). Moreover the new implementation requires navigating the AST upwards, which is not ideal.
So I would challenge the need for this change.
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, please address the comments before merging
static bool IsUsedInBaseConstructorCall(SyntaxNode node) => | ||
node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() != null; |
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 simple single-line condition is not worth extracting. Embed it on the call site. It reads pretty fluently.
static bool IsUsedInBaseConstructorCall(SyntaxNode node) => | ||
node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() != null; |
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.
static bool IsUsedInBaseConstructorCall(SyntaxNode node) => | |
node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() != null; | |
static bool IsUsedInBaseConstructorCall(SyntaxNode node) => | |
node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() is not null; |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Task 12 of #6997