From edd9c2ca848d619646da342b79c38cf7ba612094 Mon Sep 17 00:00:00 2001 From: Michael Best Date: Fri, 13 Apr 2012 12:16:59 -1000 Subject: [PATCH] Change check scripts so they work exactly the same. Change normaliseAllFiles.ps1 to strip all trailing spaces (even on blank lines). --- build/tools/check-trailing-space-linux | 2 +- build/tools/check-trailing-space-windows.bat | 22 ++++++++++---------- build/tools/normaliseAllFiles.ps1 | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build/tools/check-trailing-space-linux b/build/tools/check-trailing-space-linux index ffa62efe6..bb938b2aa 100644 --- a/build/tools/check-trailing-space-linux +++ b/build/tools/check-trailing-space-linux @@ -3,7 +3,7 @@ # Check that all files have trailing spaces stripped OutTrailingSpaceListFile='output/knockout-files-to-clean.txt' cd .. -grep -nrI '[^ ][ ]\+$' * | grep -rv "^build/output/" > build/$OutTrailingSpaceListFile +grep -nrI '[^ ][ ]\+$' `find * |grep -E "\.(js|html|css|bat|ps1)$"` | grep -v "^build/output/" > build/$OutTrailingSpaceListFile cd build if [ -s $OutTrailingSpaceListFile ] then diff --git a/build/tools/check-trailing-space-windows.bat b/build/tools/check-trailing-space-windows.bat index e5060e74d..e295e8416 100644 --- a/build/tools/check-trailing-space-windows.bat +++ b/build/tools/check-trailing-space-windows.bat @@ -3,17 +3,17 @@ @rem Check that all files have trailing spaces stripped set OutTrailingSpaceListFile=output\knockout-files-to-clean.txt cd .. - -@rem Totally outlandish way to detect trailing whitespace on non-whitespace-only lines, because the DOS "findstr" command can't handle spaces in regexes. -@rem We should consider changing the whole Windows build script to PowerShell, where this would be trivial and clean. -set foundTrailingWhitespace=0 -findstr -rsen -c:" " *.js *.html *.css *.bat *.ps1 > build\%OutTrailingSpaceListFile% -cscript build\tools\searchReplace.js " {2,}" "" build\%OutTrailingSpaceListFile% >nul -for /f "tokens=1,2,* delims=:" %%i in (build\%OutTrailingSpaceListFile%) do @if "%%k" NEQ "" ( - echo Error: Trailing whitespace on %%i line %%j - set foundTrailingWhitespace=1 -) +findstr -nrs -c:"[^ ][ ][ ]*$" *.js *.html *.css *.bat *.ps1 |findstr -rv "^build\\output" > build\%OutTrailingSpaceListFile% cd build +for %%R in (%OutTrailingSpaceListFile%) do if %%~zR gtr 0 goto :NeedFixTrailingSpace +del %OutTrailingSpaceListFile% +goto :TrailingSpaceOkay + +:NeedFixTrailingSpace +echo The following files have trailing spaces that need to be cleaned up: +echo. +type %OutTrailingSpaceListFile% del %OutTrailingSpaceListFile% +exit /b 1 -if %foundTrailingWhitespace% EQU 1 exit /b 1 \ No newline at end of file +:TrailingSpaceOkay diff --git a/build/tools/normaliseAllFiles.ps1 b/build/tools/normaliseAllFiles.ps1 index 6e60c2465..a61b6e106 100644 --- a/build/tools/normaliseAllFiles.ps1 +++ b/build/tools/normaliseAllFiles.ps1 @@ -6,6 +6,6 @@ $allFiles | %{ # Read file, remove trailing spaces/tabs, output back to file in CP1252 format (default for Git on Windows) # This will also ensure the file has a trailing linebreak Write-Host "Processing $_..." - $fileContent = (Get-Content $_) -replace "^(.*[^ \t])[ \t]+$", '$1' + $fileContent = (Get-Content $_) -replace "[ \t]+$", "" [System.IO.File]::WriteAllLines($_, $fileContent, [System.Text.Encoding]::GetEncoding(1252)) } \ No newline at end of file