Skip to content

Commit cef4b3a

Browse files
authored
Merge pull request #2874 from sharwell/fix-global-namespace
Fix SA1135 getting reported for top-level namespaces
2 parents b40215f + feddb3e commit cef4b3a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1135UnitTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,17 @@ namespace Test
307307

308308
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
309309
}
310+
311+
[Fact]
312+
public async Task TestFullyQualifiedTopLevelNamespaceAsync()
313+
{
314+
var testCode = @"
315+
namespace MyNamespace {
316+
using System;
317+
}
318+
";
319+
320+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
321+
}
310322
}
311323
}

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/SymbolNameHelpers.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ private static void AppendQualifiedSymbolName(StringBuilder builder, ISymbol sym
8585
break;
8686

8787
default:
88-
builder
89-
.Append(symbol.ContainingNamespace.ToDisplayString())
90-
.Append(".")
91-
.Append(symbol.Name);
88+
if (!symbol.ContainingNamespace.IsGlobalNamespace)
89+
{
90+
builder
91+
.Append(symbol.ContainingNamespace.ToDisplayString())
92+
.Append(".");
93+
}
94+
95+
builder.Append(symbol.Name);
9296
break;
9397
}
9498
}

0 commit comments

Comments
 (0)