1
0
mirror of https://github.com/mgechev/revive.git synced 2025-07-15 01:04:40 +02:00
This commit is contained in:
chavacava
2022-04-10 09:06:59 +02:00
committed by GitHub
parent b9814276b6
commit 31fbdb1833
23 changed files with 275 additions and 119 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"go/ast"
"go/types"
"sync"
"github.com/mgechev/revive/lint"
)
@ -11,16 +12,17 @@ import (
// UnhandledErrorRule lints given else constructs.
type UnhandledErrorRule struct {
ignoreList ignoreListType
sync.Mutex
}
type ignoreListType map[string]struct{}
// Apply applies the rule to given file.
func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
func (r *UnhandledErrorRule) configure(arguments lint.Arguments) {
r.Lock()
if r.ignoreList == nil {
r.ignoreList = make(ignoreListType, len(args))
r.ignoreList = make(ignoreListType, len(arguments))
for _, arg := range args {
for _, arg := range arguments {
argStr, ok := arg.(string)
if !ok {
panic(fmt.Sprintf("Invalid argument to the unhandled-error rule. Expecting a string, got %T", arg))
@ -29,6 +31,12 @@ func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.
r.ignoreList[argStr] = struct{}{}
}
}
r.Unlock()
}
// Apply applies the rule to given file.
func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
r.configure(args)
var failures []lint.Failure