Skip to content

Commit 7648faa

Browse files
committed
add script to remove trailing whitespace
<!-- ps-id: 925b1ad7-6f77-4af7-9bcc-67adb5a6f2f9 --> Signed-off-by: Ali Caglayan <[email protected]>
1 parent 4df3475 commit 7648faa

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.github/workflows/whitespace.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
- name: Check for trailing whitespaces
1818
run: |
1919
if git grep --cached -n --ignore-case --perl-regexp '\s$' :; then
20-
echo "Trailing whitespaces found. Please remove with:\n\
21-
git grep -l -z -E '\s+$' | xargs -0 sed -i 's/\s\+$//'"
20+
echo "Trailing whitespaces found. Please remove with:\
21+
etc/fix_trailing_whitespace.sh"
2222
exit 1
2323
fi
2424
@@ -28,9 +28,9 @@ jobs:
2828
# Check if the file is a regular file and not in the .git directory
2929
if [ -f "$file" ] && [ "$(dirname "$file")" != ".git" ]; then
3030
if [ -n "$(tail -c 1 "$file")" ]; then
31-
echo "File $file does not end with a newline. Adding newline..."
32-
echo >> "$file"
33-
git add "$file"
31+
echo "File $file does not end with a newline. Please fix with:\
32+
bash ./etc/fix_end_newlines.sh"
33+
exit 1
3434
fi
3535
fi
3636
done < <(git ls-files)

etc/fix_trailing_whitespace.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# This command removes trailing whitespace from all files in the repository.
4+
5+
git grep -l -z -E '\s+$' | xargs -0 sed -i 's/\s\+$//'

0 commit comments

Comments
 (0)