[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)/../..
function find_without_newline() {
find . -type f -not -path './third_party/*' -and \( \
-name '*.c' \
-or -name '*.cc' \
-or -name '*.proto' \
-or -name '*.rb' \
-or -name '*.py' \
-or -name '*.cs' \
-or -name '*.sh' \) -print0 \
| while IFS= read -r -d '' f; do
if [[ ! -z $f ]]; then
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!'
git ls-files |
sed -En -e '/^third_party/d' -e '/\.(c|cc|proto|rb|py|cs|sh)$/p' |
while IFS= read -r -d '' f; do
if [[ ! -z $f ]]; then
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
done
done
}
if [[ $# == 1 && $1 == '--fix' ]]; then

Loading…
Cancel
Save