Skip to content

Commit

Permalink
Fix lint workflow, remove pipe errors
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Maruseac <mihaimaruseac@google.com>
  • Loading branch information
mihaimaruseac committed Jun 5, 2024
1 parent ad549a8 commit 40eefdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,30 @@ jobs:
set -euxo pipefail # No -x here!
failed=0
# First, check for empty files at end
for file in $(git ls-files --eol | grep 'i/[cr]*lf' | awk '{print $4}'); do
lines=$(tac "$file" | awk 'NF{exit};END{print NR?NR-1:0}')
if [[ $lines -ne 0 ]]; then
line=$(wc -l "$file" | cut -d' ' -f1)
echo "::error file=$file,line=$line::File $file has $lines empty lines at end. Please remove."
failed=$((failed + 1))
fi
for file in $(for f in $(git ls-files --eol | grep 'i/[cr]*lf' | awk '{print $4}'); do egrep -l "^$" $file; done); do
line=$(wc -l "$file" | cut -d ' ' -f1)
echo "::error file=$file,line=$line::File $file has empty lines at end. Please remove."
failed=$((failed + 1))
done
# Next, check for files with whitespace at end of line. Remove CRLF files.
for file in $(git ls-files --eol | grep 'i/lf' | awk '{print $4}'); do
for line in $(grep -n '[[:space:]]$' "$file" | cut -d: -f1); do
echo "::error file=$file,line=$line::File $file has trailing whitespace at line $line. Please remove."
failed=$((failed + 1))
done
done
# Finally, check for missing endline at end of file, for any file.
for file in $(git ls-files); do
if [[ -n "$(tail -c 1 "$file")" ]]; then
line=$(wc -l "$file" | cut -d ' ' -f1)
echo "::error file=$file,line=$line::File $file needs an endline at the end. Please add."
failed=$((failed + 1))
fi
done
# Report status
if [[ $failed -ne 0 ]]; then
echo "::error Found $failed whitespace errors, failing"
exit 1
Expand Down
1 change: 1 addition & 0 deletions file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asd

Check failure on line 1 in file

View workflow job for this annotation

GitHub Actions / Lint

File file needs an endline at the end. Please add.

0 comments on commit 40eefdf

Please sign in to comment.