This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
DroneHelper/src/FileLinter/Test-FileTailingWhitespace.ps1
OCram85 8fd180b776
Some checks reported errors
continuous-integration/drone/tag Build was killed
initial migration
2022-07-13 13:59:25 +02:00

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 {
}
}