Check for tabs and long lines in Python code
[ganeti-local] / autotools / check-python-code
1 #!/bin/bash
2 #
3
4 # Copyright (C) 2009 Google Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 let problems=0
22
23 for script; do
24   if grep -H -F $'\t' "$script"; then
25     let ++problems
26     echo "Found tabs in $script" >&2
27   fi
28   if [[ "$(wc --max-line-length < "$script")" -gt 80 ]]; then
29     let ++problems
30     echo "Longest line in $script is longer than 80 characters" >&2
31   fi
32 done
33
34 if [[ "$problems" -gt 0 ]]; then
35   echo "Found $problems problems while checking code." >&2
36   exit 1
37 fi