-
Notifications
You must be signed in to change notification settings - Fork 508
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
Improve SA1642 and SA1643 code fix #1517
Conversation
} | ||
else | ||
{ | ||
var xmlEmptyElementSyntax = node as XmlEmptyElementSyntax; |
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.
💡 Don't assume the result of as
is non-null. Either use a normal cast instead, or include a null check.
@@ -53,13 +54,19 @@ public override FixAllProvider GetFixAllProvider() | |||
continue; | |||
} | |||
|
|||
var node = root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true) as XmlElementSyntax; | |||
if (node == null) | |||
var node = root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true) as XmlNodeSyntax; |
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.
We've had some problems in the past where failing to specify getInnermostNodeForTie: true
resulted in exceptions when running the code fix on documents with syntax errors. In addition, the as XmlNodeSyntax
appears to be unnecessary. I recommend the following:
SyntaxNode node = root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true);
@sharwell i implemented your feedback |
Fixes #415.
With these changes the code fix does a better job detecting mistakes in the standard text. If the standard text has the wrong class name in its text it will fix that instead of inserting a new standard text at the beginning of the summary. Examples:
It replaces a text form of the class name with a see tag:
->
It fixes a wrong see tag:
->
And it fixes a wrong class text with the correct class name:
->