Skip to content

Commit c379a3d

Browse files
Copilotbergmeister
andauthored
Optimize DSC separator detection
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent e679aff commit c379a3d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎Rules/AvoidAlias.cs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst)
348348
&& bodyPipeline.PipelineElements.Count == 1
349349
&& bodyPipeline.PipelineElements[0] is CommandExpressionAst bodyExpression)
350350
{
351-
if (HasStatementTerminator(pipeline, bodyPipeline)
351+
if (HasSemicolonSeparator(pipeline, bodyPipeline)
352352
|| bodyExpression.Redirections.Count != 0)
353353
{
354354
return null;
@@ -364,7 +364,7 @@ private ScriptBlockExpressionAst GetDscResourceBody(CommandAst cmdAst)
364364
return null;
365365
}
366366

367-
private bool HasStatementTerminator(Ast statement, Ast nextStatement)
367+
private bool HasSemicolonSeparator(Ast statement, Ast nextStatement)
368368
{
369369
int separatorStart = statement.Extent.EndOffset;
370370
int separatorLength = nextStatement.Extent.StartOffset - separatorStart;
@@ -375,6 +375,11 @@ private bool HasStatementTerminator(Ast statement, Ast nextStatement)
375375

376376
string script = statement.Extent.EndScriptPosition.GetFullScript();
377377
string separator = script.Substring(separatorStart, separatorLength);
378+
if (separator.IndexOf(';') < 0)
379+
{
380+
return false;
381+
}
382+
378383
Parser.ParseInput(separator, out Token[] tokens, out ParseError[] errors);
379384
return tokens.Any(token => token.Kind == TokenKind.Semi);
380385
}

0 commit comments

Comments
 (0)