github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/cmd/tast-lint/internal/check/package_comment.go (about) 1 // Copyright 2019 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package check 6 7 import ( 8 "fmt" 9 "go/ast" 10 "go/token" 11 ) 12 13 // PackageComment checks if there is a document for given package. 14 func PackageComment(fs *token.FileSet, pkg *ast.Package) []*Issue { 15 hasDoc := false 16 var packagePos token.Pos 17 var packageName string 18 for _, f := range pkg.Files { 19 if f.Doc != nil { 20 hasDoc = true 21 break 22 } 23 if f.Package > packagePos { // to make sure the issue stores information of the last file 24 packagePos = f.Package 25 packageName = f.Name.Name 26 } 27 } 28 var issues []*Issue 29 if !hasDoc { 30 issues = append(issues, &Issue{ 31 Pos: fs.Position(packagePos), 32 Msg: fmt.Sprintf("document of newly created package '%s' is required in one of the files in this directory", packageName), 33 Link: "https://chromium.googlesource.com/chromiumos/platform/tast/+/HEAD/docs/writing_tests.md#Documentation", 34 }) 35 } 36 return issues 37 }