Skip to content
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

Merged
merged 3 commits into from
Sep 21, 2015

Conversation

pdelvo
Copy link
Member

@pdelvo pdelvo commented Sep 20, 2015

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:

/// <summary>
/// Initializes a new instance of the Foo class.
/// </summary>

->

/// <summary>
/// Initializes a new instance of the <see cref="Foo"/> class.
/// </summary>

It fixes a wrong see tag:

/// <summary>
/// Initializes a new instance of the <see cref="Bar"/> class.
/// </summary>

->

/// <summary>
/// Initializes a new instance of the <see cref="Foo"/> class.
/// </summary>

And it fixes a wrong class text with the correct class name:

/// <summary>
/// Initializes a new instance of the Bar class.
/// </summary>

->

/// <summary>
/// Initializes a new instance of the <see cref="Foo"/> class.
/// </summary>

@sharwell sharwell added this to the 1.0.0 Beta 13 milestone Sep 20, 2015
}
else
{
var xmlEmptyElementSyntax = node as XmlEmptyElementSyntax;
Copy link
Member

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.

@sharwell sharwell self-assigned this Sep 20, 2015
@@ -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;
Copy link
Member

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);

@pdelvo
Copy link
Member Author

pdelvo commented Sep 21, 2015

@sharwell i implemented your feedback

@sharwell sharwell merged commit 2febf0b into DotNetAnalyzers:master Sep 21, 2015
sharwell added a commit that referenced this pull request Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SA1642 (constructor summary text) special case for incorrect class name
2 participants