Skip to content

Commit df9278e

Browse files
authored
resolve custom linters' path relative to config file directory (#1572)
Resolves #1085
1 parent 222076f commit df9278e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/lint/lintersdb/manager.go

+12
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package lintersdb
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67
"plugin"
78

9+
"github.com/spf13/viper"
810
"golang.org/x/tools/go/analysis"
911

1012
"github.com/golangci/golangci-lint/pkg/config"
@@ -425,6 +427,16 @@ type AnalyzerPlugin interface {
425427
}
426428

427429
func (m Manager) getAnalyzerPlugin(path string) (AnalyzerPlugin, error) {
430+
if !filepath.IsAbs(path) {
431+
// resolve non-absolute paths relative to config file's directory
432+
configFilePath := viper.ConfigFileUsed()
433+
absConfigFilePath, err := filepath.Abs(configFilePath)
434+
if err != nil {
435+
return nil, fmt.Errorf("could not get absolute representation of config file path %q: %v", configFilePath, err)
436+
}
437+
path = filepath.Join(filepath.Dir(absConfigFilePath), path)
438+
}
439+
428440
plug, err := plugin.Open(path)
429441
if err != nil {
430442
return nil, err

0 commit comments

Comments
 (0)