Skip to content

Commit

Permalink
add script to remove trailing whitespace
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Caglayan <[email protected]>

<!-- ps-id: 925b1ad7-6f77-4af7-9bcc-67adb5a6f2f9 -->
  • Loading branch information
Alizter committed Mar 6, 2024
1 parent 02c994a commit a241ac5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 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)
done < <(git ls-files)
2 changes: 1 addition & 1 deletion etc/fix_end_newlines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This command fixes the end-of-file newlines for all files in the repository.

while IFS= read -r file; do
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
Expand Down
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 a241ac5

Please sign in to comment.