diff --git a/Meta.Tests.ps1 b/Meta.Tests.ps1 index c9cf89cd..b28a915b 100644 --- a/Meta.Tests.ps1 +++ b/Meta.Tests.ps1 @@ -135,6 +135,31 @@ try $totalTabsCount | Should Be 0 } } + + Context 'New Lines' { + + It 'Should end with a new line' { + $noNewLineCount = 0 + + foreach($file in $allTextFiles) + { + $content = Get-Content $file.FullName -Raw + + if(($content[-1] -ne "`n") -and ($content[-2] -ne "`r")) + { + if($noNewLineCount -eq 0) + { + Write-Warning "To improve consistency across multiple environments and editors each text file is required to end with a new line." + } + + Write-Warning "$($file.FullName) does not end with a new line. Use Fixer 'Add-NewLine'" + $noNewLineCount++ + } + } + + $noNewLineCount | should be 0 + } + } } Describe 'PowerShell DSC resource modules' { diff --git a/MetaFixers.psm1 b/MetaFixers.psm1 index cea7522d..780cdb40 100644 --- a/MetaFixers.psm1 +++ b/MetaFixers.psm1 @@ -97,3 +97,19 @@ function Get-UnicodeFilesList() Get-TextFilesList $root | ? { Test-FileUnicode $_ } } +function Add-NewLine() +{ + [CmdletBinding()] + [OutputType([void])] + param( + [Parameter(ValueFromPipeline=$true, Mandatory=$true)] + [System.IO.FileInfo]$fileInfo + ) + + process + { + $content = Get-Content -Raw -Path $fileInfo.FullName + $content += "`r`n" + [System.IO.File]::WriteAllText($fileInfo.FullName, $content) + } +}