Skip to content

Commit 062a2df

Browse files
committed
ci: add whitespace check
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 -->
1 parent 3b693fa commit 062a2df

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

.github/workflows/whitespace.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Whitespace Check
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
whitespace-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Check for trailing whitespace
18+
run: |
19+
TRAILING_WHITESPACE=$(git grep -l -z -E '\s+$' | xargs -0 sed -n '/\s$/p')
20+
if [ -n "$TRAILING_WHITESPACE" ]; then
21+
echo "Trailing whitespace found. Please fix with:\
22+
bash ./etc/fix_trailing_whitespace.sh"
23+
exit 1
24+
fi
25+
26+
- name: Check that every file ends correctly
27+
run: |
28+
while IFS= read -r file; do
29+
# Check if the file is a regular file
30+
if [ -f "$file" ]; then
31+
if [ -n "$(tail -c 1 "$file")" ]; then
32+
echo "File $file does not end with a newline. Please fix with:\
33+
bash ./etc/fix_end_newlines.sh"
34+
exit 1
35+
fi
36+
fi
37+
done < <(git ls-files)

0 commit comments

Comments
 (0)