forked from golangci/golangci-lint
/
config.go
70 lines (54 loc) · 1.48 KB
/
config.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package config
import (
"os"
"strings"
hcversion "github.com/hashicorp/go-version"
"github.com/ldez/gomoddirectives"
)
// Config encapsulates the config data specified in the golangci yaml config file.
type Config struct {
cfgDir string // The directory containing the golangci config file.
Run Run
Output Output
LintersSettings LintersSettings `mapstructure:"linters-settings"`
Linters Linters
Issues Issues
Severity Severity
Version Version
InternalCmdTest bool `mapstructure:"internal-cmd-test"` // Option is used only for testing golangci-lint command, don't use it
InternalTest bool // Option is used only for testing golangci-lint code, don't use it
}
// GetConfigDir returns the directory that contains golangci config file.
func (c *Config) GetConfigDir() string {
return c.cfgDir
}
func NewDefault() *Config {
return &Config{
LintersSettings: defaultLintersSettings,
}
}
type Version struct {
Format string `mapstructure:"format"`
}
func IsGreaterThanOrEqualGo118(v string) bool {
v1, err := hcversion.NewVersion(strings.TrimPrefix(v, "go"))
if err != nil {
return false
}
limit, err := hcversion.NewVersion("1.18")
if err != nil {
return false
}
return v1.GreaterThanOrEqual(limit)
}
func DetectGoVersion() string {
file, _ := gomoddirectives.GetModuleFile()
if file != nil && file.Go != nil && file.Go.Version != "" {
return file.Go.Version
}
v := os.Getenv("GOVERSION")
if v != "" {
return v
}
return "1.17"
}