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

Fix SA1514: Do not report when documenting types declared in the global namespace #3863

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1151,5 +1151,23 @@ public enum TestEnum

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3849, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3849")]
public async Task TestClassInGlobalNamespaceAsync()
{
var testCode = @"
/// <summary>
MattFromRVA marked this conversation as resolved.
Show resolved Hide resolved
/// X.
/// </summary>
public class TestClass
{
}
";

var expected = DiagnosticResult.EmptyDiagnosticResults;

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
// no leading blank line necessary at start of scope.
return;
}

// Logic to handle global namespace case
if (prevToken.IsKind(SyntaxKind.None))
{
// Check if the node is the first non-trivia element in the file
var firstToken = context.Node.SyntaxTree.GetRoot().GetFirstToken();
if (firstToken == context.Node.GetFirstToken())
MattFromRVA marked this conversation as resolved.
Show resolved Hide resolved
{
// Node is the first element in the global namespace
return;
MattFromRVA marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

context.ReportDiagnostic(Diagnostic.Create(Descriptor, GetDiagnosticLocation(documentationHeader)));
Expand Down