Skip to content

Commit

Permalink
fix - reg|prt - Make colors work again in mod stan...
Browse files Browse the repository at this point in the history
...dalone analyzer

---

We've fixed a regression where we would no longer print messages to the console with colors.

---

Type: fix
Breaking: False
Doc Required: False
Backport Required: False
Part: 2/2
  • Loading branch information
AptiviCEO committed Sep 9, 2024
1 parent dba6f4d commit 49ecb3b
Show file tree
Hide file tree
Showing 50 changed files with 303 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool Analyze(Document document)
if (expression.Keyword.Text == "string" && name.Identifier.Text == nameof(string.Format))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses string.Format() instead of TextTools.FormatString()", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses string.Format() instead of TextTools.FormatString()", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand All @@ -64,7 +64,7 @@ public bool Analyze(Document document)
if (identifier.Identifier.Text == nameof(String) && name.Identifier.Text == nameof(string.Format))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses string.Format() instead of TextTools.FormatString()", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses string.Format() instead of TextTools.FormatString()", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down Expand Up @@ -97,9 +97,9 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
// Actually replace
var node = await document.GetSyntaxRootAsync(cancellationToken);
var finalNode = node?.ReplaceNode(syntaxNode, replacedSyntax);
TextWriterColor.Write("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.Write($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.Write($" + {replacedSyntax.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($" + {replacedSyntax.ToFullString()}", true, ConsoleColors.Green);

// Check the imports
var compilation = finalNode as CompilationUnitSyntax;
Expand All @@ -111,8 +111,8 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
SyntaxFactory.IdentifierName("Misc")),
SyntaxFactory.IdentifierName("Text"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public bool Analyze(Document document)
if (wrapperFunctions.Contains(idName))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console instead of ConsoleWrapper", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console instead of ConsoleWrapper", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down Expand Up @@ -124,9 +124,9 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
// Actually replace
var node = await document.GetSyntaxRootAsync(cancellationToken);
var finalNode = node?.ReplaceNode(exp, replacedSyntax);
TextWriterColor.Write("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.Write($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.Write($" + {replacedSyntax.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($" + {replacedSyntax.ToFullString()}", true, ConsoleColors.Green);

// Check the imports
var compilation = finalNode as CompilationUnitSyntax;
Expand All @@ -136,8 +136,8 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
SyntaxFactory.IdentifierName(AnalysisTools.rootNameSpace),
SyntaxFactory.IdentifierName("ConsoleBase"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool Analyze(Document document)
if (idName == nameof(Console.Title))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.Title instead of SetTitle()", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.Title instead of SetTitle()", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down Expand Up @@ -95,9 +95,9 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
// Actually replace
var node = await document.GetSyntaxRootAsync(cancellationToken);
var finalNode = node?.ReplaceNode(parentSyntax, resultSyntax);
TextWriterColor.Write("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.Write($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.Write($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);

// Check the imports
var compilation = finalNode as CompilationUnitSyntax;
Expand All @@ -107,8 +107,8 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
SyntaxFactory.IdentifierName(AnalysisTools.rootNameSpace),
SyntaxFactory.IdentifierName("ConsoleBase"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Additionally, the suggested fix will add the following using statement:", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool Analyze(Document document)
if (idName == nameof(Console.ForegroundColor))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.ForegroundColor instead of SetConsoleColor(Color)", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.ForegroundColor instead of SetConsoleColor(Color)", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down Expand Up @@ -95,9 +95,9 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
// Actually replace
var node = await document.GetSyntaxRootAsync(cancellationToken);
var finalNode = node?.ReplaceNode(parentSyntax, resultSyntax);
TextWriterColor.Write("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.Write($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.Write($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);

// Check the imports
var compilation = finalNode as CompilationUnitSyntax;
Expand All @@ -109,16 +109,16 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
SyntaxFactory.IdentifierName("ConsoleBase")),
SyntaxFactory.IdentifierName("Colors"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write("Additionally, the suggested fix will add the following using statements:", true, ConsoleColors.Yellow);
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Additionally, the suggested fix will add the following using statements:", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
if (compilation?.Usings.Any(u => u.Name?.ToString() == "Terminaux.Colors") == false)
{
var name = SyntaxFactory.QualifiedName(
SyntaxFactory.IdentifierName("Terminaux"),
SyntaxFactory.IdentifierName("Colors"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool Analyze(Document document)
if (idName == nameof(Console.BackgroundColor))
{
var lineSpan = location.GetLineSpan();
TextWriterColor.Write($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.BackgroundColor instead of SetConsoleColor(Color, true)", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($"{GetType().Name}: {document.FilePath} ({lineSpan.StartLinePosition} -> {lineSpan.EndLinePosition}): Caller uses Console.BackgroundColor instead of SetConsoleColor(Color, true)", true, ConsoleColors.Yellow);
if (!string.IsNullOrEmpty(document.FilePath))
LineHandleRangedWriter.PrintLineWithHandle(document.FilePath, lineSpan.StartLinePosition.Line + 1, lineSpan.StartLinePosition.Character + 1, lineSpan.EndLinePosition.Character);
found = true;
Expand Down Expand Up @@ -96,9 +96,9 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
// Actually replace
var node = await document.GetSyntaxRootAsync(cancellationToken);
var finalNode = node?.ReplaceNode(parentSyntax, resultSyntax);
TextWriterColor.Write("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.Write($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.Write($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Here's what the replacement would look like (with no Roslyn trivia):", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" - {exp}", true, ConsoleColors.Red);
TextWriterColor.WriteColor($" + {resultSyntax.ToFullString()}", true, ConsoleColors.Green);

// Check the imports
var compilation = finalNode as CompilationUnitSyntax;
Expand All @@ -110,16 +110,16 @@ public async Task SuggestAsync(Document document, CancellationToken cancellation
SyntaxFactory.IdentifierName("ConsoleBase")),
SyntaxFactory.IdentifierName("Colors"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write("Additionally, the suggested fix will add the following using statements:", true, ConsoleColors.Yellow);
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor("Additionally, the suggested fix will add the following using statements:", true, ConsoleColors.Yellow);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
if (compilation?.Usings.Any(u => u.Name?.ToString() == "Terminaux.Colors") == false)
{
var name = SyntaxFactory.QualifiedName(
SyntaxFactory.IdentifierName("Terminaux"),
SyntaxFactory.IdentifierName("Colors"));
var directive = SyntaxFactory.UsingDirective(name).NormalizeWhitespace();
TextWriterColor.Write($" + {directive.ToFullString()}", true, ConsoleColors.Green);
TextWriterColor.WriteColor($" + {directive.ToFullString()}", true, ConsoleColors.Green);
}
}
}
Expand Down
Loading

0 comments on commit 49ecb3b

Please sign in to comment.