root / autotools / check-python-code @ 8adfb141
History | View | Annotate | Download (1.4 kB)
1 | eed5c5df | Michael Hanselmann | #!/bin/bash |
---|---|---|---|
2 | eed5c5df | Michael Hanselmann | # |
3 | eed5c5df | Michael Hanselmann | |
4 | eed5c5df | Michael Hanselmann | # Copyright (C) 2009 Google Inc. |
5 | eed5c5df | Michael Hanselmann | # |
6 | eed5c5df | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify |
7 | eed5c5df | Michael Hanselmann | # it under the terms of the GNU General Public License as published by |
8 | eed5c5df | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or |
9 | eed5c5df | Michael Hanselmann | # (at your option) any later version. |
10 | eed5c5df | Michael Hanselmann | # |
11 | eed5c5df | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but |
12 | eed5c5df | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | eed5c5df | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | eed5c5df | Michael Hanselmann | # General Public License for more details. |
15 | eed5c5df | Michael Hanselmann | # |
16 | eed5c5df | Michael Hanselmann | # You should have received a copy of the GNU General Public License |
17 | eed5c5df | Michael Hanselmann | # along with this program; if not, write to the Free Software |
18 | eed5c5df | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | eed5c5df | Michael Hanselmann | # 02110-1301, USA. |
20 | eed5c5df | Michael Hanselmann | |
21 | eed5c5df | Michael Hanselmann | let problems=0 |
22 | eed5c5df | Michael Hanselmann | |
23 | eed5c5df | Michael Hanselmann | for script; do |
24 | 9648f1b4 | Michael Hanselmann | if grep -n -H -F $'\t' "$script"; then |
25 | eed5c5df | Michael Hanselmann | let ++problems |
26 | eed5c5df | Michael Hanselmann | echo "Found tabs in $script" >&2 |
27 | eed5c5df | Michael Hanselmann | fi |
28 | b757f830 | Michael Hanselmann | |
29 | 9648f1b4 | Michael Hanselmann | if grep -n -H -E '[[:space:]]$' "$script"; then |
30 | b757f830 | Michael Hanselmann | let ++problems |
31 | b757f830 | Michael Hanselmann | echo "Found end-of-line-whitespace in $script" >&2 |
32 | b757f830 | Michael Hanselmann | fi |
33 | b757f830 | Michael Hanselmann | |
34 | 11c684bf | Michael Hanselmann | # FIXME: This will also match "foo.xrange(...)" |
35 | 11c684bf | Michael Hanselmann | if grep -n -H -E '^[^#]*\<xrange\>' "$script"; then |
36 | 11c684bf | Michael Hanselmann | let ++problems |
37 | 11c684bf | Michael Hanselmann | echo "Forbidden function 'xrange' used in $script" >&2 |
38 | 11c684bf | Michael Hanselmann | fi |
39 | 11c684bf | Michael Hanselmann | |
40 | eed5c5df | Michael Hanselmann | if [[ "$(wc --max-line-length < "$script")" -gt 80 ]]; then |
41 | eed5c5df | Michael Hanselmann | let ++problems |
42 | eed5c5df | Michael Hanselmann | echo "Longest line in $script is longer than 80 characters" >&2 |
43 | eed5c5df | Michael Hanselmann | fi |
44 | eed5c5df | Michael Hanselmann | done |
45 | eed5c5df | Michael Hanselmann | |
46 | eed5c5df | Michael Hanselmann | if [[ "$problems" -gt 0 ]]; then |
47 | b757f830 | Michael Hanselmann | echo "Found $problems problem(s) while checking code." >&2 |
48 | eed5c5df | Michael Hanselmann | exit 1 |
49 | eed5c5df | Michael Hanselmann | fi |