aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gostaticanalysis/comment
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-09-15 18:05:35 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-09-15 19:34:30 +0200
commit712de1c63d9db97c81af68cd0dc4372c53d2e57a (patch)
treeae1761fec52c3ae4ddd003a4130ddbda8d0a2d69 /vendor/github.com/gostaticanalysis/comment
parent298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff)
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/gostaticanalysis/comment')
-rw-r--r--vendor/github.com/gostaticanalysis/comment/LICENSE21
-rw-r--r--vendor/github.com/gostaticanalysis/comment/README.md10
-rw-r--r--vendor/github.com/gostaticanalysis/comment/comment.go147
-rw-r--r--vendor/github.com/gostaticanalysis/comment/go.mod8
-rw-r--r--vendor/github.com/gostaticanalysis/comment/go.sum24
-rw-r--r--vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go20
6 files changed, 230 insertions, 0 deletions
diff --git a/vendor/github.com/gostaticanalysis/comment/LICENSE b/vendor/github.com/gostaticanalysis/comment/LICENSE
new file mode 100644
index 000000000..4f7eeff5b
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Takuya Ueda
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/gostaticanalysis/comment/README.md b/vendor/github.com/gostaticanalysis/comment/README.md
new file mode 100644
index 000000000..533555313
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/README.md
@@ -0,0 +1,10 @@
+# gostaticanalysis/comment
+
+[![godoc.org][godoc-badge]][godoc]
+
+`comment` provides utilities for [ast.CommentMap](https://golang.org/pkg/go/ast/#CommentMap).
+
+<!-- links -->
+[godoc]: https://godoc.org/github.com/gostaticanalysis/comment
+[godoc-badge]: https://img.shields.io/badge/godoc-reference-4F73B3.svg?style=flat-square&label=%20godoc.org
+
diff --git a/vendor/github.com/gostaticanalysis/comment/comment.go b/vendor/github.com/gostaticanalysis/comment/comment.go
new file mode 100644
index 000000000..2fe67fa96
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/comment.go
@@ -0,0 +1,147 @@
+package comment
+
+import (
+ "go/ast"
+ "go/token"
+ "strings"
+)
+
+// Maps is slice of ast.CommentMap.
+type Maps []ast.CommentMap
+
+// New creates new a CommentMap slice from specified files.
+func New(fset *token.FileSet, files []*ast.File) Maps {
+ maps := make(Maps, len(files))
+ for i := range files {
+ maps[i] = ast.NewCommentMap(fset, files[i], files[i].Comments)
+ }
+ return maps
+}
+
+// Comments returns correspond a CommentGroup slice to specified AST node.
+func (maps Maps) Comments(n ast.Node) []*ast.CommentGroup {
+ for i := range maps {
+ if maps[i][n] != nil {
+ return maps[i][n]
+ }
+ }
+ return nil
+}
+
+// CommentsByPos returns correspond a CommentGroup slice to specified pos.
+func (maps Maps) CommentsByPos(pos token.Pos) []*ast.CommentGroup {
+ for i := range maps {
+ for n, cgs := range maps[i] {
+ if n.Pos() == pos {
+ return cgs
+ }
+ }
+ }
+ return nil
+}
+
+// Annotated checks either specified AST node is annotated or not.
+func (maps Maps) Annotated(n ast.Node, annotation string) bool {
+ for _, cg := range maps.Comments(n) {
+ if strings.HasPrefix(strings.TrimSpace(cg.Text()), annotation) {
+ return true
+ }
+ }
+ return false
+}
+
+// Ignore checks either specified AST node is ignored by the check.
+// It follows staticcheck style as the below.
+// //lint:ignore Check1[,Check2,...,CheckN] reason
+func (maps Maps) Ignore(n ast.Node, check string) bool {
+ for _, cg := range maps.Comments(n) {
+ if hasIgnoreCheck(cg, check) {
+ return true
+ }
+ }
+ return false
+}
+
+// IgnorePos checks either specified postion of AST node is ignored by the check.
+// It follows staticcheck style as the below.
+// //lint:ignore Check1[,Check2,...,CheckN] reason
+func (maps Maps) IgnorePos(pos token.Pos, check string) bool {
+ for _, cg := range maps.CommentsByPos(pos) {
+ if hasIgnoreCheck(cg, check) {
+ return true
+ }
+ }
+ return false
+}
+
+// Deprecated: This function does not work with multiple files.
+// CommentsByPosLine can be used instead of CommentsByLine.
+//
+// CommentsByLine returns correspond a CommentGroup slice to specified line.
+func (maps Maps) CommentsByLine(fset *token.FileSet, line int) []*ast.CommentGroup {
+ for i := range maps {
+ for n, cgs := range maps[i] {
+ l := fset.File(n.Pos()).Line(n.Pos())
+ if l == line {
+ return cgs
+ }
+ }
+ }
+ return nil
+}
+
+// CommentsByPosLine returns correspond a CommentGroup slice to specified line.
+func (maps Maps) CommentsByPosLine(fset *token.FileSet, pos token.Pos) []*ast.CommentGroup {
+ f1 := fset.File(pos)
+ for i := range maps {
+ for n, cgs := range maps[i] {
+ f2 := fset.File(n.Pos())
+ if f1 != f2 {
+ // different file
+ continue
+ }
+
+ if f1.Line(pos) == f2.Line(n.Pos()) {
+ return cgs
+ }
+ }
+ }
+ return nil
+}
+
+// IgnoreLine checks either specified lineof AST node is ignored by the check.
+// It follows staticcheck style as the below.
+// //lint:ignore Check1[,Check2,...,CheckN] reason
+func (maps Maps) IgnoreLine(fset *token.FileSet, line int, check string) bool {
+ for _, cg := range maps.CommentsByLine(fset, line) {
+ if hasIgnoreCheck(cg, check) {
+ return true
+ }
+ }
+ return false
+}
+
+// hasIgnoreCheck returns true if the provided CommentGroup starts with a comment
+// of the form "//lint:ignore Check1[,Check2,...,CheckN] reason" and one of the
+// checks matches the provided check. The *ast.CommentGroup is checked directly
+// rather than using "cg.Text()" because, starting in Go 1.15, the "cg.Text()" call
+// no longer returns directive-style comments (see https://github.com/golang/go/issues/37974).
+func hasIgnoreCheck(cg *ast.CommentGroup, check string) bool {
+ if !strings.HasPrefix(cg.List[0].Text, "//") {
+ return false
+ }
+
+ s := strings.TrimSpace(cg.List[0].Text[2:])
+ txt := strings.Split(s, " ")
+ if len(txt) < 3 || txt[0] != "lint:ignore" {
+ return false
+ }
+
+ checks := strings.Split(txt[1], ",")
+ for i := range checks {
+ if check == checks[i] {
+ return true
+ }
+ }
+ return false
+}
diff --git a/vendor/github.com/gostaticanalysis/comment/go.mod b/vendor/github.com/gostaticanalysis/comment/go.mod
new file mode 100644
index 000000000..275568113
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/go.mod
@@ -0,0 +1,8 @@
+module github.com/gostaticanalysis/comment
+
+go 1.12
+
+require (
+ github.com/google/go-cmp v0.5.1
+ golang.org/x/tools v0.0.0-20200820010801-b793a1359eac
+)
diff --git a/vendor/github.com/gostaticanalysis/comment/go.sum b/vendor/github.com/gostaticanalysis/comment/go.sum
new file mode 100644
index 000000000..425807ce1
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/go.sum
@@ -0,0 +1,24 @@
+github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200820010801-b793a1359eac h1:DugppSxw0LSF8lcjaODPJZoDzq0ElTGskTst3ZaBkHI=
+golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go b/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go
new file mode 100644
index 000000000..9266d9895
--- /dev/null
+++ b/vendor/github.com/gostaticanalysis/comment/passes/commentmap/commentmap.go
@@ -0,0 +1,20 @@
+package commentmap
+
+import (
+ "reflect"
+
+ "github.com/gostaticanalysis/comment"
+ "golang.org/x/tools/go/analysis"
+)
+
+var Analyzer = &analysis.Analyzer{
+ Name: "commentmap",
+ Doc: "create comment map",
+ Run: run,
+ RunDespiteErrors: true,
+ ResultType: reflect.TypeOf(comment.Maps{}),
+}
+
+func run(pass *analysis.Pass) (interface{}, error) {
+ return comment.New(pass.Fset, pass.Files), nil
+}