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

Resolves #31, Added test and fixer for text files ending with new lines #33

Merged
merged 3 commits into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}