Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 2d4a7e2

Browse files
committed
Merge pull request #44 from ellismg/disable-verbatim-string-rewriter
Disable NonAsciiCharacter Rule on verbatim strings
2 parents b7627a4 + 9ed44d4 commit 2d4a7e2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/NonAsciiCharactersAreEscapedInLiteralsRuleTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ public void DoNotAllowUnicodeInLiterals()
3636
class Test
3737
{{
3838
public static readonly string BadString = ""This has {0} and {1}, which are both bad."";
39-
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad."";
39+
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad, but we don't rewrite yet."";
4040
public const char BadChar = '{0}';
4141
}}
4242
", '\u2713', "\U0001F308");
4343

44-
var expected = @"
44+
var expected = string.Format(@"
4545
using System;
4646
4747
class Test
48-
{
48+
{{
4949
public static readonly string BadString = ""This has \u2713 and \U0001F308, which are both bad."";
50-
public static readonly string AnotherBadString = @""This has \u2713 and \U0001F308, which are both bad."";
50+
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad, but we don't rewrite yet."";
5151
public const char BadChar = '\u2713';
52-
}
53-
";
52+
}}
53+
", '\u2713', "\U0001F308");
54+
5455
Verify(text, expected);
5556
}
5657

src/Microsoft.DotNet.CodeFormatting/Rules/NonAsciiCharactersAreEscapedInLiteralsRule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ private static SyntaxNode RewriteStringLiteralExpression(LiteralExpressionSyntax
5151
{
5252
Debug.Assert(node.CSharpKind() == SyntaxKind.StringLiteralExpression);
5353

54+
if (node.Token.IsVerbatimStringLiteral())
55+
{
56+
// We do not correctly rewrite verbatim string literals yet. Once Issue 39 is
57+
// fixed we can remove this early out.
58+
return node;
59+
}
60+
5461
if (HasNonAsciiCharacters(node.Token.Text))
5562
{
5663
string convertedText = EscapeNonAsciiCharacters(node.Token.Text);

0 commit comments

Comments
 (0)