Skip to content

Commit

Permalink
add script to remove trailing whitespace
Browse files Browse the repository at this point in the history
<!-- ps-id: 925b1ad7-6f77-4af7-9bcc-67adb5a6f2f9 -->

Signed-off-by: Ali Caglayan <[email protected]>
  • Loading branch information
Alizter committed Mar 6, 2024
1 parent 4df3475 commit 7648faa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/whitespace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: Check for trailing whitespaces
run: |
if git grep --cached -n --ignore-case --perl-regexp '\s$' :; then
echo "Trailing whitespaces found. Please remove with:\n\
git grep -l -z -E '\s+$' | xargs -0 sed -i 's/\s\+$//'"
echo "Trailing whitespaces found. Please remove with:\
etc/fix_trailing_whitespace.sh"
exit 1
fi
Expand All @@ -28,9 +28,9 @@ jobs:
# Check if the file is a regular file and not in the .git directory
if [ -f "$file" ] && [ "$(dirname "$file")" != ".git" ]; then
if [ -n "$(tail -c 1 "$file")" ]; then
echo "File $file does not end with a newline. Adding newline..."
echo >> "$file"
git add "$file"
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)
5 changes: 5 additions & 0 deletions etc/fix_trailing_whitespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# This command removes trailing whitespace from all files in the repository.

git grep -l -z -E '\s+$' | xargs -0 sed -i 's/\s\+$//'

0 comments on commit 7648faa

Please sign in to comment.