Skip to content

Commit 1ba0ce3

Browse files
committed
Updated code and tests.
1 parent 6673e09 commit 1ba0ce3

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1514UnitTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,5 +1169,64 @@ public class TestClass
11691169

11701170
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
11711171
}
1172+
1173+
[Fact]
1174+
public async Task TestClassInGlobalNamespaceWithoutNewlineAsync()
1175+
{
1176+
var testCode = @"/// <summary>
1177+
/// X.
1178+
/// </summary>
1179+
public class TestClass
1180+
{
1181+
}
1182+
";
1183+
1184+
var expected = DiagnosticResult.EmptyDiagnosticResults;
1185+
1186+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1187+
}
1188+
1189+
[Fact]
1190+
public async Task TestClassInGlobalNamespaceWithCommentAsync()
1191+
{
1192+
var testCode = @"
1193+
// Normal comment
1194+
{|#0:///|} <summary>
1195+
/// X.
1196+
/// </summary>
1197+
public class TestClass
1198+
{
1199+
}
1200+
";
1201+
1202+
var expected = new[]
1203+
{
1204+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
1205+
};
1206+
1207+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1208+
}
1209+
1210+
[Fact]
1211+
public async Task TestClassInGlobalNamespaceWithPreprocessorDirectiveAsync()
1212+
{
1213+
var testCode = @"
1214+
#if DEBUG
1215+
#endif
1216+
{|#0:///|} <summary>
1217+
/// X.
1218+
/// </summary>
1219+
public class TestClass
1220+
{
1221+
}
1222+
";
1223+
1224+
var expected = new[]
1225+
{
1226+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
1227+
};
1228+
1229+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1230+
}
11721231
}
11731232
}

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1514ElementDocumentationHeaderMustBePrecededByBlankLine.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,8 @@ private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
174174
// Logic to handle global namespace case
175175
if (prevToken.IsKind(SyntaxKind.None))
176176
{
177-
// Check if the node is the first non-trivia element in the file
178-
var firstToken = context.Node.SyntaxTree.GetRoot().GetFirstToken();
179-
if (firstToken == context.Node.GetFirstToken())
180-
{
181-
// Node is the first element in the global namespace
182-
return;
183-
}
177+
// Node is the first element in the global namespace
178+
return;
184179
}
185180
}
186181

0 commit comments

Comments
 (0)