OCram85/DroneHelper
OCram85
/
DroneHelper
Archived
1
0
Fork 0
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

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