woodpecker/vendor/github.com/fzipp/gocyclo/directives.go
Lukas c28f7cb29f
Add golangci-lint (#502)
Initial part of #435
2021-11-14 21:01:54 +01:00

39 lines
770 B
Go

// Copyright 2020 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gocyclo
import (
"go/ast"
"strings"
)
type directives []string
func (ds directives) HasIgnore() bool {
return ds.isPresent("ignore")
}
func (ds directives) isPresent(name string) bool {
for _, d := range ds {
if d == name {
return true
}
}
return false
}
func parseDirectives(doc *ast.CommentGroup) directives {
if doc == nil {
return directives{}
}
const prefix = "//gocyclo:"
var ds directives
for _, comment := range doc.List {
if strings.HasPrefix(comment.Text, prefix) {
ds = append(ds, strings.TrimSpace(strings.TrimPrefix(comment.Text, prefix)))
}
}
return ds
}