root / autotools / check-python-code @ 11c684bf
History | View | Annotate | Download (1.4 kB)
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 -n -H -F $'\t' "$script"; then |
25 |
let ++problems |
26 |
echo "Found tabs in $script" >&2 |
27 |
fi |
28 |
|
29 |
if grep -n -H -E '[[:space:]]$' "$script"; then |
30 |
let ++problems |
31 |
echo "Found end-of-line-whitespace in $script" >&2 |
32 |
fi |
33 |
|
34 |
# FIXME: This will also match "foo.xrange(...)" |
35 |
if grep -n -H -E '^[^#]*\<xrange\>' "$script"; then |
36 |
let ++problems |
37 |
echo "Forbidden function 'xrange' used in $script" >&2 |
38 |
fi |
39 |
|
40 |
if [[ "$(wc --max-line-length < "$script")" -gt 80 ]]; then |
41 |
let ++problems |
42 |
echo "Longest line in $script is longer than 80 characters" >&2 |
43 |
fi |
44 |
done |
45 |
|
46 |
if [[ "$problems" -gt 0 ]]; then |
47 |
echo "Found $problems problem(s) while checking code." >&2 |
48 |
exit 1 |
49 |
fi |