David Garcia Quintas | 45484b3 | 2016-01-14 18:59:20 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2016 gRPC authors. |
David Garcia Quintas | 45484b3 | 2016-01-14 18:59:20 -0800 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 4 | # 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 Quintas | 45484b3 | 2016-01-14 18:59:20 -0800 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
David Garcia Quintas | 45484b3 | 2016-01-14 18:59:20 -0800 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 10 | # 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 Quintas | 45484b3 | 2016-01-14 18:59:20 -0800 | [diff] [blame] | 15 | |
| 16 | # change to root directory |
| 17 | cd $(dirname $0)/../.. |
| 18 | |
| 19 | function 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 | |
| 41 | if [[ $# == 1 && $1 == '--fix' ]]; then |
| 42 | ERRORS=$(find_without_newline true) |
| 43 | else |
| 44 | ERRORS=$(find_without_newline false) |
| 45 | fi |
| 46 | |
| 47 | if [[ "$ERRORS" != '' ]]; then |
| 48 | echo "$ERRORS" |
| 49 | if ! $FIX; then |
| 50 | exit 1 |
| 51 | fi |
| 52 | fi |