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

Delta Between Two Patch Sets: cmd/vet/structtag.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/shadow.go ('k') | cmd/vet/unsafeptr.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 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 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 canonical struct tags. 5 // This file contains the test for canonical struct tags.
6 6
7 package main 7 package main
8 8
9 import ( 9 import (
10 "go/ast" 10 "go/ast"
11 "reflect" 11 "reflect"
12 "strconv" 12 "strconv"
13 ) 13 )
14 14
15 func init() { 15 func init() {
16 register("structtags", 16 register("structtags",
17 "check that struct field tags have canonical format and apply to exported fields as needed", 17 "check that struct field tags have canonical format and apply to exported fields as needed",
18 filterCanonicalFieldTag,
18 checkCanonicalFieldTag, 19 checkCanonicalFieldTag,
19 field) 20 field)
20 } 21 }
22
23 func filterCanonicalFieldTag(f *File) bool { return true }
21 24
22 // checkCanonicalFieldTag checks a struct field tag. 25 // checkCanonicalFieldTag checks a struct field tag.
23 func checkCanonicalFieldTag(f *File, node ast.Node) { 26 func checkCanonicalFieldTag(f *File, node ast.Node) {
24 field := node.(*ast.Field) 27 field := node.(*ast.Field)
25 if field.Tag == nil { 28 if field.Tag == nil {
26 return 29 return
27 } 30 }
28 31
29 tag, err := strconv.Unquote(field.Tag.Value) 32 tag, err := strconv.Unquote(field.Tag.Value)
30 if err != nil { 33 if err != nil {
(...skipping 22 matching lines...) Expand all
53 return 56 return
54 } 57 }
55 58
56 for _, enc := range [...]string{"json", "xml"} { 59 for _, enc := range [...]string{"json", "xml"} {
57 if st.Get(enc) != "" { 60 if st.Get(enc) != "" {
58 f.Badf(field.Pos(), "struct field %s has %s tag but is n ot exported", field.Names[0].Name, enc) 61 f.Badf(field.Pos(), "struct field %s has %s tag but is n ot exported", field.Names[0].Name, enc)
59 return 62 return
60 } 63 }
61 } 64 }
62 } 65 }
LEFTRIGHT

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