Skip to content

Commit

Permalink
Add a lint check to complain about trailing whitespace
Browse files Browse the repository at this point in the history
As mentioned below, this whitespace can be annoying because some editors like to delete it by
default, causing spurious diffs if someone is working on an unrelated thing. Let's avoid this by
standardizing on no trailing whitespace
  • Loading branch information
hugomg committed Apr 22, 2022
1 parent ece6873 commit 6403d1f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions run-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh

space=' '
tab=' '
ok=yes

Expand All @@ -22,11 +23,19 @@ for file in \
examples/*/*.lua examples/*/*.pln \
vm/src/pallene_core.c vm/src/pallene_core.h
do
if grep "^$tab" "$file"; then
if grep --line-number "[$space$tab]$" "$file"; then
# Forbid trailing whitespace because some editors like to automatically delete it.
# Such whitespace can cause spurious diffs later down the road, when someone is working on
# an unrelated pull request and their editor "helpfully" deletes the trailing whitespace.
error "File $file has a line that ends in whitespace"
fi

if grep --line-number "^$tab" "$file"; then
# Standardize on spaces because mixing tabs and spaces is endless pain.
error "File $file has tab-based indentation"
fi

if ! grep --quiet 'SPDX-License-Identifier' "$file"; then
if ! grep --line-number --quiet 'SPDX-License-Identifier' "$file"; then
error "File $file is missing a copyright header"
fi
done
Expand Down

0 comments on commit 6403d1f

Please sign in to comment.