Skip to content

Feature/golangci com support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(),
},
}

Expand Down
68 changes: 50 additions & 18 deletions pkg/enabled_linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"fmt"
"os"
"strings"
"sync"

Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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),
Expand All @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion pkg/result/processors/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"

"github.com/golangci/golangci-lint/pkg/result"
"github.com/golangci/revgrep"
Expand All @@ -14,6 +16,7 @@ type Diff struct {
onlyNew bool
fromRev string
patchFilePath string
patch string
}

var _ Processor = Diff{}
Expand All @@ -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"),
}
}

Expand All @@ -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
}

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down