-
Notifications
You must be signed in to change notification settings - Fork 113
/
hotload.go
30 lines (27 loc) · 879 Bytes
/
hotload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package hotload
import (
"fmt"
"plugin"
"github.com/go-critic/go-critic/framework/linter"
)
// CheckersFromDylib loads checkers provided by a dynamic library found under path.
//
// The returned info slice must be re-assigned to the original info slice,
// since there will be new entries there.
func CheckersFromDylib(infoList []*linter.CheckerInfo, path string) ([]*linter.CheckerInfo, error) {
if path == "" {
return infoList, nil // Nothing to do
}
checkersBefore := len(infoList)
// Open plugin only for side-effects (init functions).
_, err := plugin.Open(path)
if err != nil {
return infoList, err
}
maybeUpdatedList := linter.GetCheckersInfo()
checkersAfter := len(maybeUpdatedList)
if checkersBefore == checkersAfter {
return infoList, fmt.Errorf("loaded plugin doesn't provide any gocritic-compatible checkers")
}
return maybeUpdatedList, nil
}