Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #36 from dcrreynolds/New-Line-Test
Browse files Browse the repository at this point in the history
Resolves #31, Added test and fixer for text files ending with new lines
  • Loading branch information
TravisEz13 committed Apr 12, 2016
2 parents 8771d65 + 3c4fff1 commit 168d7d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Meta.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ 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")
{
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++
}
}

if(!$env:AppVeyor)
{
$noNewLineCount | should be 0
}
}
}
}

Describe 'PowerShell DSC resource modules' {
Expand Down
16 changes: 16 additions & 0 deletions MetaFixers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 168d7d8

Please sign in to comment.