63 lines
1.3 KiB
PowerShell
63 lines
1.3 KiB
PowerShell
function Test-FileTailingWhitespace {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns false if there are any tailing whitespace in lines.
|
|
|
|
.DESCRIPTION
|
|
Tests the given file for tailing whitespace. Returns true if not found.
|
|
|
|
.PARAMETER Path
|
|
Relative or full path to an existing file.
|
|
|
|
.INPUTS
|
|
[none]
|
|
|
|
.OUTPUTS
|
|
[bool]
|
|
|
|
.EXAMPLE
|
|
Test-FileTailingWhitespace.ps1 -Path './testfile.txt'
|
|
|
|
.NOTES
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
[OutputType([Bool])]
|
|
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateScript(
|
|
{
|
|
Test-Path -Path $_
|
|
}
|
|
)]
|
|
[string]$Path
|
|
)
|
|
|
|
begin {
|
|
}
|
|
|
|
process {
|
|
$content = Get-Content -Path $Path -Encoding 'utf8'
|
|
$WhiteSpace = 0
|
|
foreach ($line in $content) {
|
|
$c = ([regex]::Matches($line, "\s+$")).Count
|
|
if ( $c -gt 0 ) {
|
|
$WhiteSpace++
|
|
}
|
|
}
|
|
|
|
if ($WhiteSpace -ne 0 ) {
|
|
Write-Debug -Message ('WhiteSpace: {0} -> false' -f $WhiteSpace)
|
|
Write-Output $false
|
|
}
|
|
else {
|
|
Write-Debug -Message ('WhiteSpace: {0} -> true' -f $WhiteSpace)
|
|
Write-Output $true
|
|
}
|
|
}
|
|
|
|
end {
|
|
}
|
|
}
|