|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | using System;
|
@@ -220,14 +220,19 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
|
220 | 220 | }
|
221 | 221 | }
|
222 | 222 |
|
223 |
| - bool lineHasPipelineBeforeToken = LineHasPipelineBeforeToken(tokens, tokenIndex, token); |
| 223 | + if (pipelineIndentationStyle == PipelineIndentationStyle.None && PreviousLineEndedWithPipe(tokens, tokenIndex, token)) |
| 224 | + { |
| 225 | + continue; |
| 226 | + } |
224 | 227 |
|
| 228 | + bool lineHasPipelineBeforeToken = LineHasPipelineBeforeToken(tokens, tokenIndex, token); |
225 | 229 | AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine, lineHasPipelineBeforeToken);
|
226 | 230 | }
|
227 | 231 | break;
|
228 | 232 | }
|
229 | 233 |
|
230 |
| - if (pipelineIndentationStyle == PipelineIndentationStyle.None) { break; } |
| 234 | + if (pipelineIndentationStyle == PipelineIndentationStyle.None) { continue; } |
| 235 | + |
231 | 236 | // Check if the current token matches the end of a PipelineAst
|
232 | 237 | PipelineAst matchingPipeLineAstEnd = MatchingPipelineAstEnd(pipelineAsts, ref minimumPipelineAstIndex, token);
|
233 | 238 | if (matchingPipeLineAstEnd == null)
|
@@ -284,6 +289,35 @@ private static bool PipelineIsFollowedByNewlineOrLineContinuation(Token[] tokens
|
284 | 289 | return false;
|
285 | 290 | }
|
286 | 291 |
|
| 292 | + private static bool PreviousLineEndedWithPipe(Token[] tokens, int tokenIndex, Token token) |
| 293 | + { |
| 294 | + if (tokenIndex < 2 || token.Extent.StartLineNumber == 1) |
| 295 | + { |
| 296 | + return false; |
| 297 | + } |
| 298 | + |
| 299 | + int searchIndex = tokenIndex - 2; |
| 300 | + int searchLine; |
| 301 | + do |
| 302 | + { |
| 303 | + searchLine = tokens[searchIndex].Extent.StartLineNumber; |
| 304 | + if (tokens[searchIndex].Kind == TokenKind.Comment) |
| 305 | + { |
| 306 | + searchIndex--; |
| 307 | + } |
| 308 | + else if (tokens[searchIndex].Kind == TokenKind.Pipe) |
| 309 | + { |
| 310 | + return true; |
| 311 | + } |
| 312 | + else |
| 313 | + { |
| 314 | + break; |
| 315 | + } |
| 316 | + } while (searchLine == token.Extent.StartLineNumber - 1 && searchIndex >= 0); |
| 317 | + |
| 318 | + return false; |
| 319 | + } |
| 320 | + |
287 | 321 | private static bool LineHasPipelineBeforeToken(Token[] tokens, int tokenIndex, Token token)
|
288 | 322 | {
|
289 | 323 | int searchIndex = tokenIndex;
|
|
0 commit comments