1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +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

@@ -11,7 +11,8 @@ import (
// FileHeaderRule lints given else constructs.
type FileHeaderRule struct {
header string
sync.Mutex
configureOnce sync.Once
}
var (
@@ -20,12 +21,6 @@ var (
)
func (r *FileHeaderRule) configure(arguments lint.Arguments) {
r.Lock()
defer r.Unlock()
if r.header != "" {
return // already configured
}
if len(arguments) < 1 {
return
}
@@ -39,7 +34,7 @@ func (r *FileHeaderRule) configure(arguments lint.Arguments) {
// Apply applies the rule to given file.
func (r *FileHeaderRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
r.configure(arguments)
r.configureOnce.Do(func() { r.configure(arguments) })
if r.header == "" {
return nil