Skip to content

Commit d02f90f

Browse files
committed
Fix handling escaped identifiers in using directives
1 parent c61bb3e commit d02f90f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1208UnitTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class A
4444
await this.VerifyCSharpDiagnosticAsync(usingsInNamespaceDeclaration, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
4545
}
4646

47+
[Fact]
48+
public async Task TestSystemUsingDirectivesWithEscapeSequenceAsync()
49+
{
50+
string usingsInNamespaceDeclaration = @"namespace Test
51+
{
52+
using @System;
53+
using System.Diagnostics;
54+
using \u0053ystem.IO;
55+
using System.Threading;
56+
}";
57+
58+
await this.VerifyCSharpDiagnosticAsync(usingsInNamespaceDeclaration, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
59+
}
60+
4761
[Fact]
4862
public async Task TestWhenSystemUsingDirectivesAreNotOnTopInCompilationAsync()
4963
{

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/UsingDirectiveSyntaxHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static class UsingDirectiveSyntaxHelpers
2121
/// </summary>
2222
/// <param name="usingDirective">The <see cref="UsingDirectiveSyntax"/> that will be checked.</param>
2323
/// <returns>Return true if the <see cref="UsingDirectiveSyntax"/>is system using directive, otherwise false.</returns>
24-
internal static bool IsSystemUsingDirective(this UsingDirectiveSyntax usingDirective) => string.Equals(SystemUsingDirectiveIdentifier, GetFirstIdentifierInUsingDirective(usingDirective)?.Text, StringComparison.Ordinal);
24+
internal static bool IsSystemUsingDirective(this UsingDirectiveSyntax usingDirective) => string.Equals(SystemUsingDirectiveIdentifier, GetFirstIdentifierInUsingDirective(usingDirective)?.ValueText, StringComparison.Ordinal);
2525

2626
/// <summary>
2727
/// Check if <see cref="UsingDirectiveSyntax"/> is preceded by a preprocessor directive.

0 commit comments

Comments
 (0)