1 Star 0 Fork 0

goproxies/github.com-alecthomas-gometalinter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
_linters
src
4d63.com
github.com
alecthomas/gocyclo
alexkohler/nakedret
client9/misspell
cmd/misspell
ignore
glob.go
parse.go
vendor/github.com/gobwas/glob
LICENSE
ascii.go
case.go
legal.go
mime.go
notwords.go
replace.go
stringreplacer.go
url.go
words.go
golang/lint
gordonklaus/ineffassign
jgautheron/goconst
kisielk
mdempsky
mibk/dupl
mozilla/tls-observatory/constants
nbutton23/zxcvbn-go
opennota/check
ryanuber/go-glob
securego/gosec
stretchr/objx
stripe/safesql
tsenart/deadcode
walle/lll
golang.org/x
gopkg.in/yaml.v2
honnef.co/go/tools
mvdan.cc
manifest
4d63.com
README.md
github.com
golang.org
honnef.co
mvdan.cc
vendor
regressiontests
scripts
vendor
.gitignore
.goreleaser.yml
.travis.yml
CONTRIBUTING.md
COPYING
README.md
aggregate.go
checkstyle.go
config.go
config_test.go
directives.go
directives_test.go
execute.go
execute_test.go
issue.go
issue_template.md
issue_test.go
linters.go
linters_test.go
main.go
main_test.go
partition.go
partition_test.go
stringset.go
克隆/下载
glob.go 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
package ignore
import (
"bytes"
"fmt"
"github.com/gobwas/glob"
)
// Matcher defines an interface for filematchers
//
type Matcher interface {
Match(string) bool
True() bool
MarshalText() ([]byte, error)
}
// MultiMatch has matching on a list of matchers
type MultiMatch struct {
matchers []Matcher
}
// NewMultiMatch creates a new MultiMatch instance
func NewMultiMatch(matchers []Matcher) *MultiMatch {
return &MultiMatch{matchers: matchers}
}
// Match satifies the Matcher iterface
func (mm *MultiMatch) Match(arg string) bool {
// Normal: OR
// false, false -> false
// false, true -> true
// true, false -> true
// true, true -> true
// Invert:
// false, false -> false
// false, true -> false
// true, false -> true
// true, true -> false
use := false
for _, m := range mm.matchers {
if m.Match(arg) {
use = m.True()
}
}
return use
}
// True returns true
func (mm *MultiMatch) True() bool { return true }
// MarshalText satifies the ?? interface
func (mm *MultiMatch) MarshalText() ([]byte, error) {
return []byte("multi"), nil
}
// GlobMatch handle glob matching
type GlobMatch struct {
orig string
matcher glob.Glob
normal bool
}
// NewGlobMatch creates a new GlobMatch instance or error
func NewGlobMatch(arg []byte) (*GlobMatch, error) {
truth := true
if len(arg) > 0 && arg[0] == '!' {
truth = false
arg = arg[1:]
}
if bytes.IndexByte(arg, '/') == -1 {
return NewBaseGlobMatch(string(arg), truth)
}
return NewPathGlobMatch(string(arg), truth)
}
// NewBaseGlobMatch compiles a new matcher.
// Arg true should be set to false if the output is inverted.
func NewBaseGlobMatch(arg string, truth bool) (*GlobMatch, error) {
g, err := glob.Compile(arg)
if err != nil {
return nil, err
}
return &GlobMatch{orig: arg, matcher: g, normal: truth}, nil
}
// NewPathGlobMatch compiles a new matcher.
// Arg true should be set to false if the output is inverted.
func NewPathGlobMatch(arg string, truth bool) (*GlobMatch, error) {
// if starts with "/" then glob only applies to top level
if len(arg) > 0 && arg[0] == '/' {
arg = arg[1:]
}
// create path-aware glob
g, err := glob.Compile(arg, '/')
if err != nil {
return nil, err
}
return &GlobMatch{orig: arg, matcher: g, normal: truth}, nil
}
// True returns true if this should be evaluated normally ("true is true")
// and false if the result should be inverted ("false is true")
//
func (g *GlobMatch) True() bool { return g.normal }
// MarshalText is really a debug function
func (g *GlobMatch) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s: %v %s\"", "GlobMatch", g.normal, g.orig)), nil
}
// Match satisfies the Matcher interface
func (g *GlobMatch) Match(file string) bool {
return g.matcher.Match(file)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/goproxies/github.com-alecthomas-gometalinter.git
git@gitee.com:goproxies/github.com-alecthomas-gometalinter.git
goproxies
github.com-alecthomas-gometalinter
github.com-alecthomas-gometalinter
v2.0.7

搜索帮助