Skip to content

Commit

Permalink
ci: add whitespace check
Browse files Browse the repository at this point in the history
This adds a whitespace check to the CI that fails if there is trailing
white space or a file does not end with a newline.

Signed-off-by: Ali Caglayan <[email protected]>

<!-- ps-id: f0c063fd-98da-45ac-8ad8-a79a093f737b -->
  • Loading branch information
Alizter committed Mar 6, 2024
1 parent 3b693fa commit 062a2df
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/whitespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Whitespace Check

on:
pull_request:
push:
branches:
- master

jobs:
whitespace-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Check for trailing whitespace
run: |
TRAILING_WHITESPACE=$(git grep -l -z -E '\s+$' | xargs -0 sed -n '/\s$/p')
if [ -n "$TRAILING_WHITESPACE" ]; then
echo "Trailing whitespace found. Please fix with:\
bash ./etc/fix_trailing_whitespace.sh"
exit 1
fi
- name: Check that every file ends correctly
run: |
while IFS= read -r file; do
# Check if the file is a regular file
if [ -f "$file" ]; then
if [ -n "$(tail -c 1 "$file")" ]; then
echo "File $file does not end with a newline. Please fix with:\
bash ./etc/fix_end_newlines.sh"
exit 1
fi
fi
done < <(git ls-files)

0 comments on commit 062a2df

Please sign in to comment.