mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-02 14:46:31 +00:00
c28f7cb29f
Initial part of #435
39 lines
770 B
Go
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
|
|
}
|