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

Commit 0486516

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bug-fixes
Conflicts: src/CodeFormatter/Program.cs src/Microsoft.DotNet.CodeFormatting/IFormattingEngine.cs
2 parents a68c4f5 + 2d4a7e2 commit 0486516

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed

src/CodeFormatter/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private static int Main(string[] args)
1919
{
2020
if (args.Length < 1)
2121
{
22-
Console.WriteLine("CodeFormatter <project or solution> [<rule types>] [/file <filename>]");
22+
Console.WriteLine("CodeFormatter <project or solution> [<rule types>] [/file <filename>] [/nocopyright]");
2323
Console.WriteLine(" <rule types> - Rule types to use in addition to the default ones.");
2424
Console.WriteLine(" Use ConvertTests to convert MSTest tests to xUnit.");
2525
Console.WriteLine(" <filename> - Only apply changes to files with specified name.");
@@ -81,7 +81,6 @@ private static async Task RunAsync(string projectOrSolutionPath, IEnumerable<str
8181
{
8282
var workspace = MSBuildWorkspace.Create();
8383
var engine = FormattingEngine.Create(ruleTypes, filenames);
84-
engine.Verbose = true;
8584
engine.PreprocessorConfigurations = preprocessorConfigurations;
8685

8786
if (disableCopright)

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/FormattingEngineImplementation.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal sealed class FormattingEngineImplementation : IFormattingEngine
2929
private readonly IEnumerable<ILocalSemanticFormattingRule> _localSemanticRules;
3030
private readonly IEnumerable<IGlobalSemanticFormattingRule> _globalSemanticRules;
3131
private readonly Stopwatch _watch = new Stopwatch();
32-
private bool _verbose;
3332

3433
public ImmutableArray<string> CopyrightHeader
3534
{
@@ -49,12 +48,6 @@ public IFormatLogger FormatLogger
4948
set { _options.FormatLogger = value; }
5049
}
5150

52-
public bool Verbose
53-
{
54-
get { return _verbose; }
55-
set { _verbose = value; }
56-
}
57-
5851
[ImportingConstructor]
5952
internal FormattingEngineImplementation(
6053
Options options,
@@ -159,15 +152,7 @@ private void StartDocument()
159152
private void EndDocument(Document document)
160153
{
161154
_watch.Stop();
162-
if (_verbose && _watch.Elapsed.TotalSeconds > 1)
163-
{
164-
FormatLogger.WriteLine();
165-
FormatLogger.WriteLine(" {0} {1} seconds", document.Name, _watch.Elapsed.TotalSeconds);
166-
}
167-
else
168-
{
169-
FormatLogger.Write(".");
170-
}
155+
FormatLogger.WriteLine(" {0} {1} seconds", document.Name, _watch.Elapsed.TotalSeconds);
171156
}
172157

173158
/// <summary>
@@ -200,7 +185,6 @@ private async Task<Solution> RunSyntaxPass(Solution originalSolution, IReadOnlyL
200185
}
201186
}
202187

203-
FormatLogger.WriteLine();
204188
return currentSolution;
205189
}
206190

@@ -222,7 +206,6 @@ private async Task<Solution> RunLocalSemanticPass(Solution solution, IReadOnlyLi
222206
solution = await RunLocalSemanticPass(solution, documentIds, localSemanticRule, cancellationToken);
223207
}
224208

225-
FormatLogger.WriteLine();
226209
return solution;
227210
}
228211

@@ -249,7 +232,6 @@ private async Task<Solution> RunLocalSemanticPass(Solution originalSolution, IRe
249232
}
250233
}
251234

252-
FormatLogger.WriteLine();
253235
return currentSolution;
254236
}
255237

@@ -261,7 +243,6 @@ private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyL
261243
solution = await RunGlobalSemanticPass(solution, documentIds, globalSemanticRule, cancellationToken);
262244
}
263245

264-
FormatLogger.WriteLine();
265246
return solution;
266247
}
267248

@@ -282,7 +263,6 @@ private async Task<Solution> RunGlobalSemanticPass(Solution solution, IReadOnlyL
282263
EndDocument(document);
283264
}
284265

285-
FormatLogger.WriteLine();
286266
return solution;
287267
}
288268
}

src/Microsoft.DotNet.CodeFormatting/IFormatLogger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ public void WriteLine(string format, params object[] args)
3131

3232
public void WriteErrorLine(string format, params object[] args)
3333
{
34+
Console.ForegroundColor = ConsoleColor.Red;
3435
Console.Write("Error: ");
3536
Console.WriteLine(format, args);
37+
Console.ResetColor();
3638
}
3739

3840
public void WriteLine()

src/Microsoft.DotNet.CodeFormatting/IFormattingEngine.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public interface IFormattingEngine
1414
{
1515
ImmutableArray<string> CopyrightHeader { get; set; }
1616
ImmutableArray<string[]> PreprocessorConfigurations { get; set; }
17-
bool Verbose { get; set; }
18-
1917
Task FormatSolutionAsync(Solution solution, CancellationToken cancellationToken);
2018
Task FormatProjectAsync(Project porject, CancellationToken cancellationToken);
2119
}
22-
}
20+
}

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)