From 2cc30e91d67d28ed7dd1cd620426ffb70bb825ea Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Fri, 8 May 2015 17:12:02 -0400 Subject: [PATCH] Fix boilerplate check crash if .go file has no comments Clayton pointed out that if he created a file with no /* in it anywhere the boilerplate logic would crash like: $ hack/verify-boilerplate.sh Traceback (most recent call last): File "hack/../hooks/boilerplate.py", line 87, in sys.exit(main()) File "hack/../hooks/boilerplate.py", line 83, in main if not file_passes(filename, extention, ref, p): File "hack/../hooks/boilerplate.py", line 38, in file_passes while data[0] != "/*\n": IndexError: list index out of range That is because we were just stripping everything before the first line that contained exacly "/*". If no such line existed it got to the end and just kept going. This does something smarter. We use a regex to look for one or more lines which start // +build followed by a single newline and remove only those. This obviously found one place where the package name was above the license and was being missed by both the old and the new checker. It also fixed the python spew and just tells you your file fails. --- k8petstore/web-server/PetStoreBook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/k8petstore/web-server/PetStoreBook.go b/k8petstore/web-server/PetStoreBook.go index b6d148ba..1c81cef9 100644 --- a/k8petstore/web-server/PetStoreBook.go +++ b/k8petstore/web-server/PetStoreBook.go @@ -1,5 +1,3 @@ -package main - /* Copyright 2014 The Kubernetes Authors All rights reserved. @@ -16,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +package main + import ( "encoding/json" "fmt"