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-FileEOL.ps1

62 lines
1.3 KiB
PowerShell

function Test-FileEOL {
<#
.SYNOPSIS
Returns false if EOL isn't CRLF
.DESCRIPTION
Tests given file against valid EOL. Returns true if CRLF is used.
.PARAMETER Path
Relative or full path to an existing file.
.INPUTS
[None]
.OUTPUTS
[bool]
.EXAMPLE
Test-FileEOL -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'
$CRLFCount = ([regex]::Matches($content, "`r`n$")).Count
$LFCount = ([regex]::Matches($content, "`n$")).Count
if ($CRLFCount -eq $LFCount) {
Write-Debug -Message 'EOL: CRLFCount = LFCount -> true'
Write-Output $true
}
elseif ($CRLFCount -gt $LFCount) {
Write-Debug -Message 'EOL: CRLFCount > LFCount -> false'
Write-Output $false
}
elseif ($LFCount -gt $CRLFCount) {
Write-Debug -Message 'EOL: CRLFCount < LFCount -> false'
Write-Output $false
}
}
end {
}
}