• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2016 gRPC authors.
3#
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
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15
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
53