logginghandler/vendor/github.com/kulti/thelper/pkg/analyzer/report.go
Marvin Preuss d095180eb4
All checks were successful
continuous-integration/drone/push Build is passing
build: uses go modules for tool handling
2022-01-14 13:51:56 +01:00

57 lines
1020 B
Go

package analyzer
import (
"go/token"
"golang.org/x/tools/go/analysis"
)
type reports struct {
reports []report
filter map[token.Pos]struct{}
nofilter map[token.Pos]struct{}
}
type report struct {
pos token.Pos
format string
args []interface{}
}
func (rr *reports) Reportf(pos token.Pos, format string, args ...interface{}) {
rr.reports = append(rr.reports, report{
pos: pos,
format: format,
args: args,
})
}
func (rr *reports) Filter(pos token.Pos) {
if pos.IsValid() {
if rr.filter == nil {
rr.filter = make(map[token.Pos]struct{})
}
rr.filter[pos] = struct{}{}
}
}
func (rr *reports) NoFilter(pos token.Pos) {
if pos.IsValid() {
if rr.nofilter == nil {
rr.nofilter = make(map[token.Pos]struct{})
}
rr.nofilter[pos] = struct{}{}
}
}
func (rr reports) Flush(pass *analysis.Pass) {
for _, r := range rr.reports {
if _, ok := rr.filter[r.pos]; ok {
if _, ok := rr.nofilter[r.pos]; !ok {
continue
}
}
pass.Reportf(r.pos, r.format, r.args...)
}
}