Skip to content

Commit

Permalink
resolve custom linters' path relative to config file directory (#1572)
Browse files Browse the repository at this point in the history
Resolves #1085
  • Loading branch information
siliconbrain committed Dec 26, 2020
1 parent 222076f commit df9278e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit df9278e

Please sign in to comment.