Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3816)

Delta Between Two Patch Sets: cmd/vet/composite.go

Issue 106510044: go.tools/cmd/vet: enable file level checker short-circuiting (Closed)
Left Patch Set: Created 9 years, 8 months ago
Right Patch Set: diff -r 0f0740bbe48a https://code.google.com/p/go.tools Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/vet/bool.go ('k') | cmd/vet/copylock.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This file contains the test for unkeyed struct literals. 5 // This file contains the test for unkeyed struct literals.
6 6
7 package main 7 package main
8 8
9 import ( 9 import (
10 "flag" 10 "flag"
11 "go/ast" 11 "go/ast"
12 "strings" 12 "strings"
13 13
14 "code.google.com/p/go.tools/cmd/vet/whitelist" 14 "code.google.com/p/go.tools/cmd/vet/whitelist"
15 ) 15 )
16 16
17 var compositeWhiteList = flag.Bool("compositewhitelist", true, "use composite wh ite list; for testing only") 17 var compositeWhiteList = flag.Bool("compositewhitelist", true, "use composite wh ite list; for testing only")
18 18
19 func init() { 19 func init() {
20 register("composites", 20 register("composites",
21 "check that composite literals used field-keyed elements", 21 "check that composite literals used field-keyed elements",
22 filterUnkeyedLiteral,
22 checkUnkeyedLiteral, 23 checkUnkeyedLiteral,
23 compositeLit) 24 compositeLit)
24 } 25 }
26
27 func filterUnkeyedLiteral(f *File) bool { return true }
25 28
26 // checkUnkeyedLiteral checks if a composite literal is a struct literal with 29 // checkUnkeyedLiteral checks if a composite literal is a struct literal with
27 // unkeyed fields. 30 // unkeyed fields.
28 func checkUnkeyedLiteral(f *File, node ast.Node) { 31 func checkUnkeyedLiteral(f *File, node ast.Node) {
29 c := node.(*ast.CompositeLit) 32 c := node.(*ast.CompositeLit)
30 typ := c.Type 33 typ := c.Type
31 for { 34 for {
32 if typ1, ok := c.Type.(*ast.ParenExpr); ok { 35 if typ1, ok := c.Type.(*ast.ParenExpr); ok {
33 typ = typ1 36 typ = typ1
34 continue 37 continue
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 119 }
117 } else { 120 } else {
118 // Catch `import "pkgName"` or `import "foo/bar/pkgName" `. 121 // Catch `import "pkgName"` or `import "foo/bar/pkgName" `.
119 if s == pkgName || strings.HasSuffix(s, "/"+pkgName) { 122 if s == pkgName || strings.HasSuffix(s, "/"+pkgName) {
120 return s 123 return s
121 } 124 }
122 } 125 }
123 } 126 }
124 return "" 127 return ""
125 } 128 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b