github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/check-whitespace.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2020 syzkaller project authors. All rights reserved.
     3  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     4  
     5  FILES=0
     6  FAILED=""
     7  RE="[[:space:]]$"
     8  LAST_EMPTY=""
     9  for F in $(find . -name "*.sh" -o -name "*.S" -o -name "*.py" -o -name "*.yml" -o -name "*.yaml" -o -name "*.md" | \
    10  		egrep -v "/vendor/|/gen/"); do
    11  	((FILES+=1))
    12  	L=0
    13  	while IFS= read -r LINE; do
    14  		((L+=1))
    15  		if [[ $LINE =~ $RE ]]; then
    16  			echo "$F:$L:1: Trailing whitespace at the end of the line. Please remove."
    17  			echo "$LINE"
    18  			FAILED="1"
    19  		fi
    20  		LAST_EMPTY=""
    21  		if [ "$LINE" == "" ]; then
    22  			LAST_EMPTY="1"
    23  		fi
    24  	done < "$F"
    25  	if [ "$LAST_EMPTY" != "" ]; then
    26  		echo "$F:$L:1: Trailing empty line at the end of the file. Please remove."
    27  		FAILED="1"
    28  	fi
    29  done
    30  if [ "$FAILED" != "" ]; then exit 1; fi
    31  echo "$FILES files checked for whitespaces"