Skip to content

Commit 0e107e1

Browse files
author
golangci
authored
Merge pull request #2 from golangci/feature/golangci_com_support
Feature/golangci com support
2 parents ac1a976 + e73a876 commit 0e107e1

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

internal/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
228228
}
229229
runner := pkg.SimpleRunner{
230230
Processors: []processors.Processor{
231+
processors.NewPathPrettifier(), // must be before diff processor at least
231232
processors.NewExclude(excludeTotalPattern),
232233
processors.NewCgo(),
233234
processors.NewNolint(fset),
@@ -236,7 +237,6 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
236237
processors.NewMaxPerFileFromLinter(),
237238
processors.NewMaxSameIssues(e.cfg.Issues.MaxSameIssues),
238239
processors.NewMaxFromLinter(e.cfg.Issues.MaxIssuesPerLinter),
239-
processors.NewPathPrettifier(),
240240
},
241241
}
242242

pkg/enabled_linters.go

+50-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pkg
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67
"sync"
78

@@ -55,15 +56,9 @@ func (lc LinterConfig) WithPresets(presets ...string) LinterConfig {
5556
return lc
5657
}
5758

58-
func (lc LinterConfig) WithDisabledByDefault() LinterConfig {
59-
lc.EnabledByDefault = false
60-
return lc
61-
}
62-
6359
func newLinterConfig(linter Linter) LinterConfig {
6460
return LinterConfig{
65-
Linter: linter,
66-
EnabledByDefault: true,
61+
Linter: linter,
6762
}
6863
}
6964

@@ -86,11 +81,21 @@ func GetLinterConfig(name string) *LinterConfig {
8681
return &lc
8782
}
8883

84+
func enableLinterConfigs(lcs []LinterConfig, isEnabled func(lc *LinterConfig) bool) []LinterConfig {
85+
var ret []LinterConfig
86+
for _, lc := range lcs {
87+
lc.EnabledByDefault = isEnabled(&lc)
88+
ret = append(ret, lc)
89+
}
90+
91+
return ret
92+
}
93+
8994
func GetAllSupportedLinterConfigs() []LinterConfig {
90-
return []LinterConfig{
95+
lcs := []LinterConfig{
9196
newLinterConfig(golinters.Govet{}).WithPresets(PresetBugs),
9297
newLinterConfig(golinters.Errcheck{}).WithFullImport().WithPresets(PresetBugs),
93-
newLinterConfig(golinters.Golint{}).WithDisabledByDefault().WithPresets(PresetStyle),
98+
newLinterConfig(golinters.Golint{}).WithPresets(PresetStyle),
9499

95100
newLinterConfig(golinters.Megacheck{StaticcheckEnabled: true}).WithSSA().WithPresets(PresetBugs),
96101
newLinterConfig(golinters.Megacheck{UnusedEnabled: true}).WithSSA().WithPresets(PresetUnused),
@@ -99,20 +104,47 @@ func GetAllSupportedLinterConfigs() []LinterConfig {
99104
newLinterConfig(golinters.Gas{}).WithFullImport().WithPresets(PresetBugs),
100105
newLinterConfig(golinters.Structcheck{}).WithFullImport().WithPresets(PresetUnused),
101106
newLinterConfig(golinters.Varcheck{}).WithFullImport().WithPresets(PresetUnused),
102-
newLinterConfig(golinters.Interfacer{}).WithDisabledByDefault().WithSSA().WithPresets(PresetStyle),
103-
newLinterConfig(golinters.Unconvert{}).WithDisabledByDefault().WithFullImport().WithPresets(PresetStyle),
107+
newLinterConfig(golinters.Interfacer{}).WithSSA().WithPresets(PresetStyle),
108+
newLinterConfig(golinters.Unconvert{}).WithFullImport().WithPresets(PresetStyle),
104109
newLinterConfig(golinters.Ineffassign{}).WithPresets(PresetUnused),
105-
newLinterConfig(golinters.Dupl{}).WithDisabledByDefault().WithPresets(PresetStyle),
106-
newLinterConfig(golinters.Goconst{}).WithDisabledByDefault().WithPresets(PresetStyle),
110+
newLinterConfig(golinters.Dupl{}).WithPresets(PresetStyle),
111+
newLinterConfig(golinters.Goconst{}).WithPresets(PresetStyle),
107112
newLinterConfig(golinters.Deadcode{}).WithFullImport().WithPresets(PresetUnused),
108-
newLinterConfig(golinters.Gocyclo{}).WithDisabledByDefault().WithPresets(PresetComplexity),
113+
newLinterConfig(golinters.Gocyclo{}).WithPresets(PresetComplexity),
109114

110-
newLinterConfig(golinters.Gofmt{}).WithDisabledByDefault().WithPresets(PresetFormatting),
111-
newLinterConfig(golinters.Gofmt{UseGoimports: true}).WithDisabledByDefault().WithPresets(PresetFormatting),
112-
newLinterConfig(golinters.Maligned{}).WithFullImport().WithDisabledByDefault().WithPresets(PresetPerformance),
115+
newLinterConfig(golinters.Gofmt{}).WithPresets(PresetFormatting),
116+
newLinterConfig(golinters.Gofmt{UseGoimports: true}).WithPresets(PresetFormatting),
117+
newLinterConfig(golinters.Maligned{}).WithFullImport().WithPresets(PresetPerformance),
113118
newLinterConfig(golinters.Megacheck{GosimpleEnabled: true, UnusedEnabled: true, StaticcheckEnabled: true}).
114-
WithSSA().WithPresets(PresetStyle, PresetBugs, PresetUnused).WithDisabledByDefault(),
119+
WithSSA().WithPresets(PresetStyle, PresetBugs, PresetUnused),
120+
}
121+
122+
if os.Getenv("GOLANGCI_COM_RUN") == "1" {
123+
disabled := map[string]bool{
124+
"gocyclo": true,
125+
"dupl": true,
126+
"maligned": true,
127+
}
128+
return enableLinterConfigs(lcs, func(lc *LinterConfig) bool {
129+
return !disabled[lc.Linter.Name()]
130+
})
115131
}
132+
133+
enabled := map[string]bool{
134+
"govet": true,
135+
"errcheck": true,
136+
"staticcheck": true,
137+
"unused": true,
138+
"gosimple": true,
139+
"gas": true,
140+
"structcheck": true,
141+
"varcheck": true,
142+
"ineffassign": true,
143+
"deadcode": true,
144+
}
145+
return enableLinterConfigs(lcs, func(lc *LinterConfig) bool {
146+
return enabled[lc.Linter.Name()]
147+
})
116148
}
117149

118150
func getAllSupportedLinters() []Linter {

pkg/result/processors/diff.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"io"
77
"io/ioutil"
8+
"os"
9+
"strings"
810

911
"github.com/golangci/golangci-lint/pkg/result"
1012
"github.com/golangci/revgrep"
@@ -14,6 +16,7 @@ type Diff struct {
1416
onlyNew bool
1517
fromRev string
1618
patchFilePath string
19+
patch string
1720
}
1821

1922
var _ Processor = Diff{}
@@ -23,6 +26,7 @@ func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff {
2326
onlyNew: onlyNew,
2427
fromRev: fromRev,
2528
patchFilePath: patchFilePath,
29+
patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"),
2630
}
2731
}
2832

@@ -31,7 +35,7 @@ func (p Diff) Name() string {
3135
}
3236

3337
func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
34-
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" { // no need to work
38+
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" { // no need to work
3539
return issues, nil
3640
}
3741

@@ -42,7 +46,10 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
4246
return nil, fmt.Errorf("can't read from pathc file %s: %s", p.patchFilePath, err)
4347
}
4448
patchReader = bytes.NewReader(patch)
49+
} else if p.patch != "" {
50+
patchReader = strings.NewReader(p.patch)
4551
}
52+
4653
c := revgrep.Checker{
4754
Patch: patchReader,
4855
RevisionFrom: p.fromRev,

pkg/runner.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ func (r *SimpleRunner) processIssues(ctx context.Context, issues []result.Issue)
145145
newIssues, err := p.Process(issues)
146146
elapsed := time.Since(startedAt)
147147
if elapsed > 50*time.Millisecond {
148-
logrus.Infof("Result processor %s took %s", p.Name(), elapsed)
148+
logrus.Infof("Result processor %s took %s and transformed %d -> %d issues",
149+
p.Name(), elapsed, len(issues), len(newIssues))
149150
}
150151
if err != nil {
151152
logrus.Warnf("Can't process result by %s processor: %s", p.Name(), err)

0 commit comments

Comments
 (0)