Merge pull request #2 from golangci/feature/golangci_com_support
Feature/golangci com support
This commit is contained in:
commit
0e107e1d78
@ -228,6 +228,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
|
||||
}
|
||||
runner := pkg.SimpleRunner{
|
||||
Processors: []processors.Processor{
|
||||
processors.NewPathPrettifier(), // must be before diff processor at least
|
||||
processors.NewExclude(excludeTotalPattern),
|
||||
processors.NewCgo(),
|
||||
processors.NewNolint(fset),
|
||||
@ -236,7 +237,6 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
|
||||
processors.NewMaxPerFileFromLinter(),
|
||||
processors.NewMaxSameIssues(e.cfg.Issues.MaxSameIssues),
|
||||
processors.NewMaxFromLinter(e.cfg.Issues.MaxIssuesPerLinter),
|
||||
processors.NewPathPrettifier(),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package pkg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -55,15 +56,9 @@ func (lc LinterConfig) WithPresets(presets ...string) LinterConfig {
|
||||
return lc
|
||||
}
|
||||
|
||||
func (lc LinterConfig) WithDisabledByDefault() LinterConfig {
|
||||
lc.EnabledByDefault = false
|
||||
return lc
|
||||
}
|
||||
|
||||
func newLinterConfig(linter Linter) LinterConfig {
|
||||
return LinterConfig{
|
||||
Linter: linter,
|
||||
EnabledByDefault: true,
|
||||
Linter: linter,
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,11 +81,21 @@ func GetLinterConfig(name string) *LinterConfig {
|
||||
return &lc
|
||||
}
|
||||
|
||||
func enableLinterConfigs(lcs []LinterConfig, isEnabled func(lc *LinterConfig) bool) []LinterConfig {
|
||||
var ret []LinterConfig
|
||||
for _, lc := range lcs {
|
||||
lc.EnabledByDefault = isEnabled(&lc)
|
||||
ret = append(ret, lc)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func GetAllSupportedLinterConfigs() []LinterConfig {
|
||||
return []LinterConfig{
|
||||
lcs := []LinterConfig{
|
||||
newLinterConfig(golinters.Govet{}).WithPresets(PresetBugs),
|
||||
newLinterConfig(golinters.Errcheck{}).WithFullImport().WithPresets(PresetBugs),
|
||||
newLinterConfig(golinters.Golint{}).WithDisabledByDefault().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Golint{}).WithPresets(PresetStyle),
|
||||
|
||||
newLinterConfig(golinters.Megacheck{StaticcheckEnabled: true}).WithSSA().WithPresets(PresetBugs),
|
||||
newLinterConfig(golinters.Megacheck{UnusedEnabled: true}).WithSSA().WithPresets(PresetUnused),
|
||||
@ -99,20 +104,47 @@ func GetAllSupportedLinterConfigs() []LinterConfig {
|
||||
newLinterConfig(golinters.Gas{}).WithFullImport().WithPresets(PresetBugs),
|
||||
newLinterConfig(golinters.Structcheck{}).WithFullImport().WithPresets(PresetUnused),
|
||||
newLinterConfig(golinters.Varcheck{}).WithFullImport().WithPresets(PresetUnused),
|
||||
newLinterConfig(golinters.Interfacer{}).WithDisabledByDefault().WithSSA().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Unconvert{}).WithDisabledByDefault().WithFullImport().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Interfacer{}).WithSSA().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Unconvert{}).WithFullImport().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Ineffassign{}).WithPresets(PresetUnused),
|
||||
newLinterConfig(golinters.Dupl{}).WithDisabledByDefault().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Goconst{}).WithDisabledByDefault().WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Dupl{}).WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Goconst{}).WithPresets(PresetStyle),
|
||||
newLinterConfig(golinters.Deadcode{}).WithFullImport().WithPresets(PresetUnused),
|
||||
newLinterConfig(golinters.Gocyclo{}).WithDisabledByDefault().WithPresets(PresetComplexity),
|
||||
newLinterConfig(golinters.Gocyclo{}).WithPresets(PresetComplexity),
|
||||
|
||||
newLinterConfig(golinters.Gofmt{}).WithDisabledByDefault().WithPresets(PresetFormatting),
|
||||
newLinterConfig(golinters.Gofmt{UseGoimports: true}).WithDisabledByDefault().WithPresets(PresetFormatting),
|
||||
newLinterConfig(golinters.Maligned{}).WithFullImport().WithDisabledByDefault().WithPresets(PresetPerformance),
|
||||
newLinterConfig(golinters.Gofmt{}).WithPresets(PresetFormatting),
|
||||
newLinterConfig(golinters.Gofmt{UseGoimports: true}).WithPresets(PresetFormatting),
|
||||
newLinterConfig(golinters.Maligned{}).WithFullImport().WithPresets(PresetPerformance),
|
||||
newLinterConfig(golinters.Megacheck{GosimpleEnabled: true, UnusedEnabled: true, StaticcheckEnabled: true}).
|
||||
WithSSA().WithPresets(PresetStyle, PresetBugs, PresetUnused).WithDisabledByDefault(),
|
||||
WithSSA().WithPresets(PresetStyle, PresetBugs, PresetUnused),
|
||||
}
|
||||
|
||||
if os.Getenv("GOLANGCI_COM_RUN") == "1" {
|
||||
disabled := map[string]bool{
|
||||
"gocyclo": true,
|
||||
"dupl": true,
|
||||
"maligned": true,
|
||||
}
|
||||
return enableLinterConfigs(lcs, func(lc *LinterConfig) bool {
|
||||
return !disabled[lc.Linter.Name()]
|
||||
})
|
||||
}
|
||||
|
||||
enabled := map[string]bool{
|
||||
"govet": true,
|
||||
"errcheck": true,
|
||||
"staticcheck": true,
|
||||
"unused": true,
|
||||
"gosimple": true,
|
||||
"gas": true,
|
||||
"structcheck": true,
|
||||
"varcheck": true,
|
||||
"ineffassign": true,
|
||||
"deadcode": true,
|
||||
}
|
||||
return enableLinterConfigs(lcs, func(lc *LinterConfig) bool {
|
||||
return enabled[lc.Linter.Name()]
|
||||
})
|
||||
}
|
||||
|
||||
func getAllSupportedLinters() []Linter {
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
"github.com/golangci/revgrep"
|
||||
@ -14,6 +16,7 @@ type Diff struct {
|
||||
onlyNew bool
|
||||
fromRev string
|
||||
patchFilePath string
|
||||
patch string
|
||||
}
|
||||
|
||||
var _ Processor = Diff{}
|
||||
@ -23,6 +26,7 @@ func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff {
|
||||
onlyNew: onlyNew,
|
||||
fromRev: fromRev,
|
||||
patchFilePath: patchFilePath,
|
||||
patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +35,7 @@ func (p Diff) Name() string {
|
||||
}
|
||||
|
||||
func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" { // no need to work
|
||||
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" { // no need to work
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
@ -42,7 +46,10 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return nil, fmt.Errorf("can't read from pathc file %s: %s", p.patchFilePath, err)
|
||||
}
|
||||
patchReader = bytes.NewReader(patch)
|
||||
} else if p.patch != "" {
|
||||
patchReader = strings.NewReader(p.patch)
|
||||
}
|
||||
|
||||
c := revgrep.Checker{
|
||||
Patch: patchReader,
|
||||
RevisionFrom: p.fromRev,
|
||||
|
@ -145,7 +145,8 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue)
|
||||
newIssues, err := p.Process(issues)
|
||||
elapsed := time.Since(startedAt)
|
||||
if elapsed > 50*time.Millisecond {
|
||||
logrus.Infof("Result processor %s took %s", p.Name(), elapsed)
|
||||
logrus.Infof("Result processor %s took %s and transformed %d -> %d issues",
|
||||
p.Name(), elapsed, len(issues), len(newIssues))
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Warnf("Can't process result by %s processor: %s", p.Name(), err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user