fixes
This commit is contained in:
parent
c9d006d77a
commit
6f384926cf
@ -37,6 +37,7 @@ func (e *Executor) initRun() {
|
|||||||
config.OutFormatColoredLineNumber,
|
config.OutFormatColoredLineNumber,
|
||||||
fmt.Sprintf("Format of output: %s", strings.Join(config.OutFormats, "|")))
|
fmt.Sprintf("Format of output: %s", strings.Join(config.OutFormats, "|")))
|
||||||
runCmd.Flags().BoolVar(&rc.PrintIssuedLine, "print-issued-lines", true, "Print lines of code with issue")
|
runCmd.Flags().BoolVar(&rc.PrintIssuedLine, "print-issued-lines", true, "Print lines of code with issue")
|
||||||
|
runCmd.Flags().BoolVar(&rc.PrintLinterName, "print-linter-name", true, "Print linter name in issue line")
|
||||||
|
|
||||||
runCmd.Flags().IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code",
|
runCmd.Flags().IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code",
|
||||||
1, "Exit code when issues were found")
|
1, "Exit code when issues were found")
|
||||||
@ -53,7 +54,7 @@ func (e *Executor) initRun() {
|
|||||||
runCmd.Flags().BoolVar(&rc.Gofmt.Simplify, "gofmt.simplify", true, "Gofmt: simplify code")
|
runCmd.Flags().BoolVar(&rc.Gofmt.Simplify, "gofmt.simplify", true, "Gofmt: simplify code")
|
||||||
|
|
||||||
runCmd.Flags().IntVar(&rc.Gocyclo.MinComplexity, "gocyclo.min-complexity",
|
runCmd.Flags().IntVar(&rc.Gocyclo.MinComplexity, "gocyclo.min-complexity",
|
||||||
50, "Minimal complexity of function to report it")
|
30, "Minimal complexity of function to report it")
|
||||||
|
|
||||||
runCmd.Flags().BoolVar(&rc.Structcheck.CheckExportedFields, "structcheck.exported-fields", false, "Structcheck: report about unused exported struct fields")
|
runCmd.Flags().BoolVar(&rc.Structcheck.CheckExportedFields, "structcheck.exported-fields", false, "Structcheck: report about unused exported struct fields")
|
||||||
runCmd.Flags().BoolVar(&rc.Varcheck.CheckExportedFields, "varcheck.exported-fields", false, "Varcheck: report about unused exported variables")
|
runCmd.Flags().BoolVar(&rc.Varcheck.CheckExportedFields, "varcheck.exported-fields", false, "Varcheck: report about unused exported variables")
|
||||||
@ -240,7 +241,8 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
|
|||||||
if e.cfg.Run.OutFormat == config.OutFormatJSON {
|
if e.cfg.Run.OutFormat == config.OutFormatJSON {
|
||||||
p = printers.NewJSON()
|
p = printers.NewJSON()
|
||||||
} else {
|
} else {
|
||||||
p = printers.NewText(e.cfg.Run.PrintIssuedLine, e.cfg.Run.OutFormat == config.OutFormatColoredLineNumber)
|
p = printers.NewText(e.cfg.Run.PrintIssuedLine,
|
||||||
|
e.cfg.Run.OutFormat == config.OutFormatColoredLineNumber, e.cfg.Run.PrintLinterName)
|
||||||
}
|
}
|
||||||
gotAnyIssues, err := p.Print(issues)
|
gotAnyIssues, err := p.Print(issues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,6 +35,7 @@ type Run struct { // nolint:maligned
|
|||||||
|
|
||||||
OutFormat string
|
OutFormat string
|
||||||
PrintIssuedLine bool
|
PrintIssuedLine bool
|
||||||
|
PrintLinterName bool
|
||||||
|
|
||||||
ExitCodeIfIssuesFound int
|
ExitCodeIfIssuesFound int
|
||||||
|
|
||||||
|
@ -49,7 +49,14 @@ func installBinary(t *testing.T) {
|
|||||||
|
|
||||||
func testOneSource(t *testing.T, sourcePath string) {
|
func testOneSource(t *testing.T, sourcePath string) {
|
||||||
goErrchkBin := filepath.Join(runtime.GOROOT(), "test", "errchk")
|
goErrchkBin := filepath.Join(runtime.GOROOT(), "test", "errchk")
|
||||||
cmd := exec.Command(goErrchkBin, binName, "run", "--enable-all", "--gocyclo.min-complexity", "20", sourcePath)
|
cmd := exec.Command(goErrchkBin, binName, "run",
|
||||||
|
"--enable-all",
|
||||||
|
"--dupl.threshold=20",
|
||||||
|
"--gocyclo.min-complexity=20",
|
||||||
|
"--print-issued-lines=false",
|
||||||
|
"--print-linter-name=false",
|
||||||
|
"--out-format=line-number",
|
||||||
|
sourcePath)
|
||||||
runGoErrchk(cmd, t)
|
runGoErrchk(cmd, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ func (p ProjectPaths) MixedPaths() []string {
|
|||||||
func (p ProjectPaths) FilesGrouppedByDirs() [][]string {
|
func (p ProjectPaths) FilesGrouppedByDirs() [][]string {
|
||||||
dirToFiles := map[string][]string{}
|
dirToFiles := map[string][]string{}
|
||||||
for _, f := range p.Files {
|
for _, f := range p.Files {
|
||||||
dirToFiles[filepath.Dir(f)] = append(dirToFiles[f], f)
|
dir := filepath.Dir(f)
|
||||||
|
dirToFiles[dir] = append(dirToFiles[dir], f)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := [][]string{}
|
ret := [][]string{}
|
||||||
|
@ -18,7 +18,7 @@ func (Golint) Name() string {
|
|||||||
func (g Golint) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
|
func (g Golint) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
|
||||||
var issues []result.Issue
|
var issues []result.Issue
|
||||||
for _, pkgFiles := range lintCtx.Paths.FilesGrouppedByDirs() {
|
for _, pkgFiles := range lintCtx.Paths.FilesGrouppedByDirs() {
|
||||||
i, err := lintFiles(lintCtx.RunCfg().Golint.MinConfidence, pkgFiles...)
|
i, err := g.lintFiles(lintCtx.RunCfg().Golint.MinConfidence, pkgFiles...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: skip and warn
|
// TODO: skip and warn
|
||||||
return nil, fmt.Errorf("can't lint files %s: %s", lintCtx.Paths.Files, err)
|
return nil, fmt.Errorf("can't lint files %s: %s", lintCtx.Paths.Files, err)
|
||||||
@ -29,7 +29,7 @@ func (g Golint) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, erro
|
|||||||
return issues, nil
|
return issues, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func lintFiles(minConfidence float64, filenames ...string) ([]result.Issue, error) {
|
func (g Golint) lintFiles(minConfidence float64, filenames ...string) ([]result.Issue, error) {
|
||||||
files := make(map[string][]byte)
|
files := make(map[string][]byte)
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
src, err := ioutil.ReadFile(filename)
|
src, err := ioutil.ReadFile(filename)
|
||||||
@ -49,8 +49,9 @@ func lintFiles(minConfidence float64, filenames ...string) ([]result.Issue, erro
|
|||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
if p.Confidence >= minConfidence {
|
if p.Confidence >= minConfidence {
|
||||||
issues = append(issues, result.Issue{
|
issues = append(issues, result.Issue{
|
||||||
Pos: p.Position,
|
Pos: p.Position,
|
||||||
Text: p.Text,
|
Text: p.Text,
|
||||||
|
FromLinter: g.Name(),
|
||||||
})
|
})
|
||||||
// TODO: use p.Link and p.Category
|
// TODO: use p.Link and p.Category
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@ import (
|
|||||||
type Text struct {
|
type Text struct {
|
||||||
printIssuedLine bool
|
printIssuedLine bool
|
||||||
useColors bool
|
useColors bool
|
||||||
|
printLinterName bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewText(printIssuedLine bool, useColors bool) *Text {
|
func NewText(printIssuedLine, useColors, printLinterName bool) *Text {
|
||||||
return &Text{
|
return &Text{
|
||||||
printIssuedLine: printIssuedLine,
|
printIssuedLine: printIssuedLine,
|
||||||
useColors: useColors,
|
useColors: useColors,
|
||||||
|
printLinterName: printLinterName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +49,9 @@ func (p Text) Print(issues chan result.Issue) (bool, error) {
|
|||||||
for i := range issues {
|
for i := range issues {
|
||||||
gotAnyIssue = true
|
gotAnyIssue = true
|
||||||
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
||||||
|
if p.printLinterName {
|
||||||
|
text += fmt.Sprintf(" (%s)", i.FromLinter)
|
||||||
|
}
|
||||||
pos := p.SprintfColored(color.Bold, "%s:%d", i.FilePath(), i.Line())
|
pos := p.SprintfColored(color.Bold, "%s:%d", i.FilePath(), i.Line())
|
||||||
fmt.Fprintf(out, "%s: %s\n", pos, text)
|
fmt.Fprintf(out, "%s: %s\n", pos, text)
|
||||||
|
|
||||||
|
6
pkg/testdata/with_issues/golint.go
vendored
6
pkg/testdata/with_issues/golint.go
vendored
@ -13,3 +13,9 @@ type ExportedInterfaceWithNoComment interface{}
|
|||||||
|
|
||||||
// Bad comment // ERROR "comment on exported function ExportedFuncWithBadComment should be of the form .ExportedFuncWithBadComment \.\.\.."
|
// Bad comment // ERROR "comment on exported function ExportedFuncWithBadComment should be of the form .ExportedFuncWithBadComment \.\.\.."
|
||||||
func ExportedFuncWithBadComment() {}
|
func ExportedFuncWithBadComment() {}
|
||||||
|
|
||||||
|
type GolintTest struct{}
|
||||||
|
|
||||||
|
func (receiver1 GolintTest) A() {}
|
||||||
|
|
||||||
|
func (receiver2 GolintTest) B() {} // ERROR "receiver name receiver2 should be consistent with previous receiver name receiver1 for GolintTest"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user