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 #33 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 Mar 24, 2016
2 parents b367d4b + 90e8bb8 commit 73ba873
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Meta.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
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 73ba873

Please sign in to comment.