blob: 83348a5e87eacc3d146100705e1149f95872c85b [file] [log] [blame]
David Garcia Quintas45484b32016-01-14 18:59:20 -08001#!/bin/bash
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2016 gRPC authors.
David Garcia Quintas45484b32016-01-14 18:59:20 -08003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
David Garcia Quintas45484b32016-01-14 18:59:20 -08007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
David Garcia Quintas45484b32016-01-14 18:59:20 -08009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Garcia Quintas45484b32016-01-14 18:59:20 -080015
16# change to root directory
17cd $(dirname $0)/../..
18
19function find_without_newline() {
20 find . -type f -not -path './third_party/*' -and \( \
21 -name '*.c' \
22 -or -name '*.cc' \
23 -or -name '*.proto' \
24 -or -name '*.rb' \
25 -or -name '*.py' \
26 -or -name '*.cs' \
27 -or -name '*.sh' \) -print0 \
28 | while IFS= read -r -d '' f; do
29 if [[ ! -z $f ]]; then
30 if [[ $(tail -c 1 "$f") != $NEWLINE ]]; then
31 echo "Error: file '$f' is missing a trailing newline character."
32 if $2; then # fix
33 sed -i -e '$a\' $f
34 echo 'Fixed!'
35 fi
36 fi
37 fi
38 done
39}
40
41if [[ $# == 1 && $1 == '--fix' ]]; then
42 ERRORS=$(find_without_newline true)
43else
44 ERRORS=$(find_without_newline false)
45fi
46
47if [[ "$ERRORS" != '' ]]; then
48 echo "$ERRORS"
49 if ! $FIX; then
50 exit 1
51 fi
52fi