From df9278efd2977240666b19ba3e8a78881491dec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dud=C3=A1s=20=C3=81d=C3=A1m?= Date: Sun, 27 Dec 2020 00:02:25 +0100 Subject: [PATCH] resolve custom linters' path relative to config file directory (#1572) Resolves golangci/golangci-lint#1085 --- pkg/lint/lintersdb/manager.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index c9bbdb9a866b..5bec998854d5 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -3,8 +3,10 @@ package lintersdb import ( "fmt" "os" + "path/filepath" "plugin" + "github.com/spf13/viper" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/pkg/config" @@ -425,6 +427,16 @@ type AnalyzerPlugin interface { } func (m Manager) getAnalyzerPlugin(path string) (AnalyzerPlugin, error) { + if !filepath.IsAbs(path) { + // resolve non-absolute paths relative to config file's directory + configFilePath := viper.ConfigFileUsed() + absConfigFilePath, err := filepath.Abs(configFilePath) + if err != nil { + return nil, fmt.Errorf("could not get absolute representation of config file path %q: %v", configFilePath, err) + } + path = filepath.Join(filepath.Dir(absConfigFilePath), path) + } + plug, err := plugin.Open(path) if err != nil { return nil, err