1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-27 22:18:41 +02:00

refactor: replace mutex with sync.Once for rule configuration (#1118)

This commit is contained in:
Oleksandr Redko
2024-11-15 13:03:59 +02:00
committed by GitHub
parent 7ee4500e12
commit 3378f7033b
32 changed files with 118 additions and 297 deletions

View File

@@ -14,17 +14,11 @@ import (
// UnhandledErrorRule lints given else constructs.
type UnhandledErrorRule struct {
ignoreList []*regexp.Regexp
sync.Mutex
configureOnce sync.Once
}
func (r *UnhandledErrorRule) configure(arguments lint.Arguments) {
r.Lock()
defer r.Unlock()
if r.ignoreList != nil {
return // already configured
}
for _, arg := range arguments {
argStr, ok := arg.(string)
if !ok {
@@ -47,7 +41,7 @@ func (r *UnhandledErrorRule) configure(arguments lint.Arguments) {
// Apply applies the rule to given file.
func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
r.configure(args)
r.configureOnce.Do(func() { r.configure(args) })
var failures []lint.Failure