From eac3bbf03b52950c37e7c86fc1285407d1ed4b21 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 24 May 2021 14:34:44 -0700 Subject: [PATCH 1/2] Added checked for empty line at the end of the file --- .build/CodeFormatter.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.build/CodeFormatter.ps1 b/.build/CodeFormatter.ps1 index 9c02c10106..f50a8fffce 100644 --- a/.build/CodeFormatter.ps1 +++ b/.build/CodeFormatter.ps1 @@ -61,8 +61,9 @@ foreach ($file in $scriptFiles) { } } + $reloadFile = $false $before = Get-Content $file -Raw - $after = Invoke-Formatter -ScriptDefinition (Get-Content $file -Raw) -Settings $repoRoot\PSScriptAnalyzerSettings.psd1 + $after = Invoke-Formatter -ScriptDefinition $before -Settings $repoRoot\PSScriptAnalyzerSettings.psd1 if ($before -ne $after) { Write-Warning ("{0}:" -f $file) @@ -71,6 +72,7 @@ foreach ($file in $scriptFiles) { try { Set-Content -Path $file -Value $after -Encoding utf8NoBOM Write-Information "Saved $file with formatting corrections." + $reloadFile = $true } catch { $filesFailed = $true Write-Warning "Failed to save $file with formatting corrections." @@ -81,6 +83,16 @@ foreach ($file in $scriptFiles) { } } + if ($reloadFile) { + $before = Get-Content -Path $file -Raw + } + + if (-not ([string]::IsNullOrWhiteSpace($before[-1]))) { + Write-Warning $file + Write-Warning "Failed to have a whitespace at the end of the file" + $filesFailed = $true + } + $analyzerResults = Invoke-ScriptAnalyzer -Path $file -Settings $repoRoot\PSScriptAnalyzerSettings.psd1 if ($null -ne $analyzerResults) { $filesFailed = $true From 70fdcc10e4002de4a494201fbc1cd7a44442ee97 Mon Sep 17 00:00:00 2001 From: David Paulson Date: Mon, 24 May 2021 14:38:05 -0700 Subject: [PATCH 2/2] Fixed file format to have empty line at the end of file. --- .../Write/Write-CheckSearchProcessState.ps1 | 2 +- Search/Troubleshoot-ModernSearch/Write/Write-Error.ps1 | 2 +- Search/Troubleshoot-ModernSearch/Write/Write-Warning.ps1 | 2 +- Shared/Get-ServerPendingReboot.ps1 | 2 +- Shared/Tests/Get-NETFrameworkVersion.Tests.ps1 | 2 +- Shared/Tests/Get-ServerPendingReboot.Tests.ps1 | 2 +- Shared/Tests/Invoke-ScriptBlockHandler.Tests.ps1 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Search/Troubleshoot-ModernSearch/Write/Write-CheckSearchProcessState.ps1 b/Search/Troubleshoot-ModernSearch/Write/Write-CheckSearchProcessState.ps1 index 4b47571562..c4de3c4483 100644 --- a/Search/Troubleshoot-ModernSearch/Write/Write-CheckSearchProcessState.ps1 +++ b/Search/Troubleshoot-ModernSearch/Write/Write-CheckSearchProcessState.ps1 @@ -65,4 +65,4 @@ Function Write-CheckSearchProcessState { Write-ScriptOutput "----------------------------------------" Write-ScriptOutput "" } -} \ No newline at end of file +} diff --git a/Search/Troubleshoot-ModernSearch/Write/Write-Error.ps1 b/Search/Troubleshoot-ModernSearch/Write/Write-Error.ps1 index cf3039e1c6..09c1c91e42 100644 --- a/Search/Troubleshoot-ModernSearch/Write/Write-Error.ps1 +++ b/Search/Troubleshoot-ModernSearch/Write/Write-Error.ps1 @@ -10,4 +10,4 @@ Function Write-Error { Write-LogInformation "Error - $Message" Microsoft.PowerShell.Utility\Write-Error $Message } -} \ No newline at end of file +} diff --git a/Search/Troubleshoot-ModernSearch/Write/Write-Warning.ps1 b/Search/Troubleshoot-ModernSearch/Write/Write-Warning.ps1 index fc7bbf8e8a..fc9d4082e5 100644 --- a/Search/Troubleshoot-ModernSearch/Write/Write-Warning.ps1 +++ b/Search/Troubleshoot-ModernSearch/Write/Write-Warning.ps1 @@ -10,4 +10,4 @@ Function Write-Warning { Write-LogInformation "Warning - $Message" Microsoft.PowerShell.Utility\Write-Warning $Message } -} \ No newline at end of file +} diff --git a/Shared/Get-ServerPendingReboot.ps1 b/Shared/Get-ServerPendingReboot.ps1 index c5e3d21701..b919a2a8e6 100644 --- a/Shared/Get-ServerPendingReboot.ps1 +++ b/Shared/Get-ServerPendingReboot.ps1 @@ -93,4 +93,4 @@ Function Get-ServerRebootPending { PendingRebootLocations = $pendingRebootLocations } } -} \ No newline at end of file +} diff --git a/Shared/Tests/Get-NETFrameworkVersion.Tests.ps1 b/Shared/Tests/Get-NETFrameworkVersion.Tests.ps1 index c1e3e3f174..0e65c96b95 100644 --- a/Shared/Tests/Get-NETFrameworkVersion.Tests.ps1 +++ b/Shared/Tests/Get-NETFrameworkVersion.Tests.ps1 @@ -129,4 +129,4 @@ Describe "Testing $scriptName" { Assert-MockCalled -CommandName Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Write-CustomScriptBlock" } } } -} \ No newline at end of file +} diff --git a/Shared/Tests/Get-ServerPendingReboot.Tests.ps1 b/Shared/Tests/Get-ServerPendingReboot.Tests.ps1 index 6ef5e83a44..45c7f3ef23 100644 --- a/Shared/Tests/Get-ServerPendingReboot.Tests.ps1 +++ b/Shared/Tests/Get-ServerPendingReboot.Tests.ps1 @@ -96,4 +96,4 @@ Describe "Testing Get-ServerRebootPending" { $results.PendingReboot | Should -Be $true } } -} \ No newline at end of file +} diff --git a/Shared/Tests/Invoke-ScriptBlockHandler.Tests.ps1 b/Shared/Tests/Invoke-ScriptBlockHandler.Tests.ps1 index fc1b403321..58af9c6439 100644 --- a/Shared/Tests/Invoke-ScriptBlockHandler.Tests.ps1 +++ b/Shared/Tests/Invoke-ScriptBlockHandler.Tests.ps1 @@ -187,4 +187,4 @@ Describe "Testing $scriptName" { Assert-MockCalled -CommandName Write-Host -Exactly 1 -ParameterFilter { $Object -eq "Test-PesterCatchAction" } } } -} \ No newline at end of file +}