Skip to content

Commit

Permalink
Refactor Remove-LineComment function to use $Line parameter instead o…
Browse files Browse the repository at this point in the history
…f $Test for clarity
  • Loading branch information
MariusStorhaug committed Feb 1, 2025
1 parent c92096e commit ad2089b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/functions/public/Lines/Remove-LineComment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
Mandatory,
ValueFromPipeline
)]
[string] $Test
[string] $Line
)

# Parse the single line using AST
$tokens = $null
$null = [System.Management.Automation.Language.Parser]::ParseInput($Test, [ref]$tokens, [ref]$null)
$null = [System.Management.Automation.Language.Parser]::ParseInput($Line, [ref]$tokens, [ref]$null)

# Find comment tokens in the line
$commentToken = $tokens | Where-Object { $_.Kind -eq 'Comment' }
Expand All @@ -50,9 +50,9 @@
$commentStart = $commentToken.Extent.StartColumnNumber - 1 # Convert to zero-based index

# Remove the comment by trimming the line up to the comment start position
return $Test.Substring(0, $commentStart)
return $Line.Substring(0, $commentStart)
}

# Return original line if no comment was found
return $Test
return $Line
}

0 comments on commit ad2089b

Please sign in to comment.