check-python-code: Give location(s) of lines longer than 80 chars
authorMichael Hanselmann <hansmi@google.com>
Tue, 23 Aug 2011 13:12:44 +0000 (15:12 +0200)
committerMichael Hanselmann <hansmi@google.com>
Thu, 25 Aug 2011 13:37:57 +0000 (15:37 +0200)
Until now it would only say that there was a line longer than 80
characters, but not where.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

autotools/check-python-code

index ec1d96b..166e12d 100755 (executable)
 
 set -e
 
+readonly maxlinelen=$(for ((i=0; i<81; ++i)); do echo -n .; done)
+
+if [[ "${#maxlinelen}" != 81 ]]; then
+  echo "Internal error: Check for line length is incorrect" >&2
+  exit 1
+fi
+
 # "[...] If the last ARG evaluates to 0, let returns 1; 0 is returned
 # otherwise.", hence ignoring the return value.
 let problems=0 || :
@@ -47,7 +54,7 @@ for script; do
     echo "Found editor-specific settings in $script" >&2
   fi
 
-  if [[ "$(wc --max-line-length < "$script")" -gt 80 ]]; then
+  if grep -n -H "^$maxlinelen" "$script"; then
     let ++problems
     echo "Longest line in $script is longer than 80 characters" >&2
   fi