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

Commit 7a93c15

Browse files
author
Lakshmi Priya Sekar
committed
Fix bugs in the rules
1 parent e00fac7 commit 7a93c15

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ private IEnumerable<SyntaxTrivia> GetLeadingTriviaWithEndNewLines(IEnumerable<Sy
8484
private IEnumerable<SyntaxTrivia> GetLeadingTriviaWithEndStructure(IEnumerable<SyntaxTrivia> trivia)
8585
{
8686
int index = trivia.Count() - 1;
87-
while (index >= 0 && trivia.ElementAt(index).HasStructure)
87+
while (index >= 0 &&
88+
(trivia.ElementAt(index).HasStructure ||
89+
trivia.ElementAt(index).CSharpKind() == SyntaxKind.DisabledTextTrivia))
8890
index--;
8991

9092
if (index < 0)
@@ -98,7 +100,7 @@ private IEnumerable<SyntaxTrivia> GetLeadingTriviaWithEndStructure(IEnumerable<S
98100
return trivia.Take(index + 1).AddTwoNewLines().Concat(trivia.Skip(index + 1));
99101

100102
// Insert one new line before the structured trivia, previous element is new line
101-
if (SyntaxKind.EndOfLineTrivia != trivia.ElementAt(index - 1).CSharpKind())
103+
if (index != 0 && SyntaxKind.EndOfLineTrivia != trivia.ElementAt(index - 1).CSharpKind())
102104
return trivia.Take(index + 1).AddNewLine().Concat(trivia.Skip(index + 1));
103105

104106
// Already has the right format

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public static Document GetOriginalDocumentWithPreprocessorSymbols(this Document
5454

5555
public static void WriteConsoleError(this string msg, int lineNo, string documentName)
5656
{
57+
Console.ForegroundColor = ConsoleColor.Red;
5758
Console.WriteLine("Error (Line: " + lineNo + ", " + documentName + ") " + msg);
59+
Console.ResetColor();
5860
}
5961
}
6062
}

0 commit comments

Comments
 (0)