From 3e29592dba4a7aee36a50e98f6493e097bf2ecc3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 20 Aug 2013 15:39:49 -0700 Subject: [PATCH] cmd/vet: move whitelist to its own package App Engine needs the whitelist file and it's cleaner if it's in its own package where it can be imported directly, without pushing composite.go through a pile of sed. R=dsymonds, r CC=golang-dev https://golang.org/cl/12746045 --- cmd/vet/composite.go | 50 ++------------------------------ cmd/vet/whitelist/whitelist.go | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 cmd/vet/whitelist/whitelist.go diff --git a/cmd/vet/composite.go b/cmd/vet/composite.go index c41e1a1c..1168d26b 100644 --- a/cmd/vet/composite.go +++ b/cmd/vet/composite.go @@ -10,6 +10,8 @@ import ( "flag" "go/ast" "strings" + + "code.google.com/p/go.tools/cmd/vet/whitelist" ) var compositeWhiteList = flag.Bool("compositewhitelist", true, "use composite white list; for testing only") @@ -88,7 +90,7 @@ func (f *File) checkUnkeyedLiteral(c *ast.CompositeLit) { return } typeName := path + "." + s.Sel.Name - if *compositeWhiteList && unkeyedLiteralWhitelist[typeName] { + if *compositeWhiteList && whitelist.UnkeyedLiteral[typeName] { return } @@ -117,49 +119,3 @@ func pkgPath(f *File, pkgName string) (path string) { } return "" } - -var unkeyedLiteralWhitelist = map[string]bool{ - /* - These types are actually slices. Syntactically, we cannot tell - whether the Typ in pkg.Typ{1, 2, 3} is a slice or a struct, so we - whitelist all the standard package library's exported slice types. - - find $GOROOT/src/pkg -type f | grep -v _test.go | xargs grep '^type.*\[\]' | \ - grep -v ' map\[' | sed 's,/[^/]*go.type,,' | sed 's,.*src/pkg/,,' | \ - sed 's, ,.,' | sed 's, .*,,' | grep -v '\.[a-z]' | \ - sort | awk '{ print "\"" $0 "\": true," }' - */ - "crypto/x509/pkix.RDNSequence": true, - "crypto/x509/pkix.RelativeDistinguishedNameSET": true, - "database/sql.RawBytes": true, - "debug/macho.LoadBytes": true, - "encoding/asn1.ObjectIdentifier": true, - "encoding/asn1.RawContent": true, - "encoding/json.RawMessage": true, - "encoding/xml.CharData": true, - "encoding/xml.Comment": true, - "encoding/xml.Directive": true, - "go/scanner.ErrorList": true, - "image/color.Palette": true, - "net.HardwareAddr": true, - "net.IP": true, - "net.IPMask": true, - "sort.Float64Slice": true, - "sort.IntSlice": true, - "sort.StringSlice": true, - "unicode.SpecialCase": true, - - // These image and image/color struct types are frozen. We will never add fields to them. - "image/color.Alpha16": true, - "image/color.Alpha": true, - "image/color.Gray16": true, - "image/color.Gray": true, - "image/color.NRGBA64": true, - "image/color.NRGBA": true, - "image/color.RGBA64": true, - "image/color.RGBA": true, - "image/color.YCbCr": true, - "image.Point": true, - "image.Rectangle": true, - "image.Uniform": true, -} diff --git a/cmd/vet/whitelist/whitelist.go b/cmd/vet/whitelist/whitelist.go new file mode 100644 index 00000000..7aa0d30d --- /dev/null +++ b/cmd/vet/whitelist/whitelist.go @@ -0,0 +1,52 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package whitelist defines exceptions for the vet tool. +package whitelist + +// UnkeyedLiteral are types that are actually slices, but +// syntactically, we cannot tell whether the Typ in pkg.Typ{1, 2, 3} +// is a slice or a struct, so we whitelist all the standard package +// library's exported slice types. +var UnkeyedLiteral = map[string]bool{ + /* + find $GOROOT/src/pkg -type f | grep -v _test.go | xargs grep '^type.*\[\]' | \ + grep -v ' map\[' | sed 's,/[^/]*go.type,,' | sed 's,.*src/pkg/,,' | \ + sed 's, ,.,' | sed 's, .*,,' | grep -v '\.[a-z]' | \ + sort | awk '{ print "\"" $0 "\": true," }' + */ + "crypto/x509/pkix.RDNSequence": true, + "crypto/x509/pkix.RelativeDistinguishedNameSET": true, + "database/sql.RawBytes": true, + "debug/macho.LoadBytes": true, + "encoding/asn1.ObjectIdentifier": true, + "encoding/asn1.RawContent": true, + "encoding/json.RawMessage": true, + "encoding/xml.CharData": true, + "encoding/xml.Comment": true, + "encoding/xml.Directive": true, + "go/scanner.ErrorList": true, + "image/color.Palette": true, + "net.HardwareAddr": true, + "net.IP": true, + "net.IPMask": true, + "sort.Float64Slice": true, + "sort.IntSlice": true, + "sort.StringSlice": true, + "unicode.SpecialCase": true, + + // These image and image/color struct types are frozen. We will never add fields to them. + "image/color.Alpha16": true, + "image/color.Alpha": true, + "image/color.Gray16": true, + "image/color.Gray": true, + "image/color.NRGBA64": true, + "image/color.NRGBA": true, + "image/color.RGBA64": true, + "image/color.RGBA": true, + "image/color.YCbCr": true, + "image.Point": true, + "image.Rectangle": true, + "image.Uniform": true, +}