Skip to content

Commit 813da65

Browse files
author
Kapil Borle
committed
Add logic to indent the line after backtick
1 parent 60774d2 commit 813da65

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Rules/UseConsistentIndentation.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
9191
break;
9292

9393
case TokenKind.NewLine:
94+
case TokenKind.LineContinuation:
9495
onNewLine = true;
9596
break;
9697

@@ -101,18 +102,26 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
101102
{
102103
var tempIndentationLevel = indentationLevel;
103104

104-
// Ignore comments
105-
// Since the previous token is a newline token we start
106-
// looking for comments at the token before the newline token.
107-
int j = k - 2;
108-
while (j > 0 && tokens[j].Kind == TokenKind.Comment)
105+
// Check if the preceding character is an escape character
106+
if (k > 0 && tokens[k - 1].Kind == TokenKind.LineContinuation)
109107
{
110-
--j;
108+
++tempIndentationLevel;
111109
}
112-
113-
if (j >= 0 && tokens[j].Kind == TokenKind.Pipe)
110+
else
114111
{
115-
++tempIndentationLevel;
112+
// Ignore comments
113+
// Since the previous token is a newline token we start
114+
// looking for comments at the token before the newline token.
115+
int j = k - 2;
116+
while (j > 0 && tokens[j].Kind == TokenKind.Comment)
117+
{
118+
--j;
119+
}
120+
121+
if (j >= 0 && tokens[j].Kind == TokenKind.Pipe)
122+
{
123+
++tempIndentationLevel;
124+
}
116125
}
117126

118127
AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine);

0 commit comments

Comments
 (0)