[sanity] Ignore .gitignored files in trailing newline check (#35655)

See https://source.cloud.google.com/results/invocations/912189e8-824c-4f20-bef4-24416a2b666c

Closes #35655

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35655 from drfloob:check-fewer-things-for-newlines 3eb0a2bc3a
PiperOrigin-RevId: 601223154
pull/35660/head
AJ Heller 10 months ago committed by Copybara-Service
parent 870a66d9a0
commit c4ebfc0ed0
  1. 28
      tools/distrib/check_trailing_newlines.sh

@ -17,25 +17,19 @@
cd $(dirname $0)/../.. cd $(dirname $0)/../..
function find_without_newline() { function find_without_newline() {
find . -type f -not -path './third_party/*' -and \( \ git ls-files |
-name '*.c' \ sed -En -e '/^third_party/d' -e '/\.(c|cc|proto|rb|py|cs|sh)$/p' |
-or -name '*.cc' \ while IFS= read -r -d '' f; do
-or -name '*.proto' \ if [[ ! -z $f ]]; then
-or -name '*.rb' \ if [[ $(tail -c 1 "$f") != $NEWLINE ]]; then
-or -name '*.py' \ echo "Error: file '$f' is missing a trailing newline character."
-or -name '*.cs' \ if $1; then # fix
-or -name '*.sh' \) -print0 \ sed -i -e '$a\' $f
| while IFS= read -r -d '' f; do echo 'Fixed!'
if [[ ! -z $f ]]; then fi
if [[ $(tail -c 1 "$f") != $NEWLINE ]]; then
echo "Error: file '$f' is missing a trailing newline character."
if $1; then # fix
sed -i -e '$a\' $f
echo 'Fixed!'
fi fi
fi fi
fi done
done
} }
if [[ $# == 1 && $1 == '--fix' ]]; then if [[ $# == 1 && $1 == '--fix' ]]; then

Loading…
Cancel
Save