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-FileTab.ps1
OCram85 8fd180b776
Some checks reported errors
continuous-integration/drone/tag Build was killed
initial migration
2022-07-13 13:59:25 +02:00

57 lines
1.1 KiB
PowerShell

function Test-FileTab {
<#
.SYNOPSIS
Returns false if tab char is used in file.
.DESCRIPTION
Test the given file if tabs are used. Returns false if any tabs were found.
.PARAMETER Path
elative or full path to an existing file.
.INPUTS
[none]
.OUTPUTS
[bool]
.EXAMPLE
Test-FileTab -Path './testfile.txt'
.NOTES
#>
[CmdletBinding()]
[OutputType([bool])]
param (
[Parameter(Mandatory = $true)]
[ValidateScript(
{
Test-Path -Path $_
}
)]
[string]$Path
)
begin {
}
process {
$content = Get-Content -Path $Path -Raw -Encoding 'utf8'
$Tabs = ([regex]::Matches($content, "`t")).Count
if ($Tabs -ne 0 ) {
Write-Debug -Message ('Tabs: {0} -> false' -f $Tabs)
Write-Output $false
}
else {
Write-Debug -Message ('Tabs: {0} -> true' -f $Tabs)
Write-Output $true
}
}
end {
}
}