Skip to content

Commit

Permalink
Change check scripts so they work exactly the same. Change normaliseA…
Browse files Browse the repository at this point in the history
…llFiles.ps1 to strip all trailing spaces (even on blank lines).
  • Loading branch information
mbest committed Apr 13, 2012
1 parent ac96a71 commit edd9c2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/tools/check-trailing-space-linux
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions build/tools/check-trailing-space-windows.bat
Expand Up @@ -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%

This comment has been minimized.

Copy link
@SteveSanderson

SteveSanderson Apr 14, 2012

Contributor

Well found! I tried about a dozen ways of expressing this regex - none of which were supported by findstr - but I didn't try that one.

Though now if we trim trailing whitespace everywhere, we won't actually need this anyway. Looks like I wasted a lot of time yesterday :(

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
:TrailingSpaceOkay
2 changes: 1 addition & 1 deletion build/tools/normaliseAllFiles.ps1
Expand Up @@ -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))
}

0 comments on commit edd9c2c

Please sign in to comment.