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
This commit is contained in:
parent
99ac9493e1
commit
3e29592dba
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
Loading…
Reference in New Issue