Skip to content

Commit

Permalink
Invoke-DbatoolsFormatter, fix #5790 (#5791)
Browse files Browse the repository at this point in the history
  • Loading branch information
niphlod authored and potatoqualitee committed Jun 19, 2019
1 parent f28df5e commit 72cc18c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions functions/Invoke-DbatoolsFormatter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function Invoke-DbatoolsFormatter {
$CBHRex = [regex]'(?smi)\s+<#[^#]*#>'
$CBHStartRex = [regex]'(?<spaces>[ ]+)<#'
$CBHEndRex = [regex]'(?<spaces>[ ]*)#>'
$OSEOL = "`n"
if ($psVersionTable.Platform -ne 'Unix') {
$OSEOL = "`r`n"
}
}
process {
if (Test-FunctionInterrupt) { return }
Expand All @@ -57,7 +61,7 @@ function Invoke-DbatoolsFormatter {

$content = Get-Content -Path $realPath -Raw -Encoding UTF8
#strip ending empty lines
$content = $content -replace "(?s)`r`n\s*$"
$content = $content -replace "(?s)$OSEOL\s*$"
try {
$content = Invoke-Formatter -ScriptDefinition $content -Settings CodeFormattingOTBS -ErrorAction Stop
} catch {
Expand All @@ -83,7 +87,7 @@ function Invoke-DbatoolsFormatter {
foreach ($line in $content.Split("`n")) {
$realContent += $line.TrimEnd()
}
[System.IO.File]::WriteAllText($realPath, ($realContent -Join "`r`n"), $Utf8NoBomEncoding)
[System.IO.File]::WriteAllText($realPath, ($realContent -Join "$OSEOL"), $Utf8NoBomEncoding)
}
}
}

0 comments on commit 72cc18c

Please sign in to comment.