Skip to content

Commit c9bb265

Browse files
committed
fix small bugs
1 parent 100efea commit c9bb265

File tree

24 files changed

+48
-17
lines changed

24 files changed

+48
-17
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/commands/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config)
153153
args = []string{"./..."}
154154
}
155155

156-
paths, err := fsutils.GetPathsForAnalysis(args)
156+
paths, err := fsutils.GetPathsForAnalysis(ctx, args)
157157
if err != nil {
158158
return nil, err
159159
}

pkg/golinters/linters_test.go renamed to pkg/enabled_linters_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package golinters
1+
package pkg
22

33
import (
44
"bytes"
@@ -19,11 +19,15 @@ func runGoErrchk(c *exec.Cmd, t *testing.T) {
1919
}
2020

2121
const testdataDir = "testdata"
22+
23+
var testdataWithIssuesDir = filepath.Join(testdataDir, "with_issues")
24+
var testdataNotCompilingDir = filepath.Join(testdataDir, "not_compiles")
25+
2226
const binName = "golangci-lint"
2327

24-
func TestSourcesFromTestdataDir(t *testing.T) {
25-
t.Log(filepath.Join(testdataDir, "*.go"))
26-
sources, err := filepath.Glob(filepath.Join(testdataDir, "*.go"))
28+
func TestSourcesFromTestdataWithIssuesDir(t *testing.T) {
29+
t.Log(filepath.Join(testdataWithIssuesDir, "*.go"))
30+
sources, err := filepath.Glob(filepath.Join(testdataWithIssuesDir, "*.go"))
2731
assert.NoError(t, err)
2832
assert.NotEmpty(t, sources)
2933

@@ -39,7 +43,7 @@ func TestSourcesFromTestdataDir(t *testing.T) {
3943
}
4044

4145
func installBinary(t *testing.T) {
42-
cmd := exec.Command("go", "install", filepath.Join("..", "..", "cmd", binName))
46+
cmd := exec.Command("go", "install", filepath.Join("..", "cmd", binName))
4347
assert.NoError(t, cmd.Run(), "Can't go install %s", binName)
4448
}
4549

@@ -48,3 +52,9 @@ func testOneSource(t *testing.T, sourcePath string) {
4852
cmd := exec.Command(goErrchkBin, binName, "run", "--enable-all", "--gocyclo.min-complexity", "20", sourcePath)
4953
runGoErrchk(cmd, t)
5054
}
55+
56+
func TestNotCompilingProgram(t *testing.T) {
57+
installBinary(t)
58+
err := exec.Command(binName, "run", "--enable-all", testdataNotCompilingDir).Run()
59+
assert.NoError(t, err)
60+
}

pkg/fsutils/fsutils.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"path/filepath"
1010
"strings"
11+
"time"
1112

1213
"github.com/golangci/golangci-shared/pkg/analytics"
1314
)
@@ -54,14 +55,20 @@ func processPaths(root string, paths []string, maxPaths int) ([]string, error) {
5455
return ret, nil
5556
}
5657

57-
func GetPathsForAnalysis(inputPaths []string) (*ProjectPaths, error) {
58+
func GetPathsForAnalysis(ctx context.Context, inputPaths []string) (ret *ProjectPaths, err error) {
59+
defer func(startedAt time.Time) {
60+
if ret != nil {
61+
analytics.Log(ctx).Infof("Found paths for analysis for %s: %s", time.Since(startedAt), ret.MixedPaths())
62+
}
63+
}(time.Now())
64+
5865
for _, path := range inputPaths {
5966
if strings.HasSuffix(path, ".go") && len(inputPaths) != 1 {
6067
return nil, fmt.Errorf("Specific files for analysis are allowed only if one file is set")
6168
}
6269
}
6370

64-
excludeDirs := []string{"vendor", "testdata", "examples", "Godeps"}
71+
excludeDirs := []string{"vendor", "testdata", "examples", "Godeps", "builtin"}
6572
pr := NewPathResolver(excludeDirs, []string{".go"})
6673
paths, err := pr.Resolve(inputPaths...)
6774
if err != nil {

pkg/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func runLinter(ctx context.Context, linter Linter, lintCtx *golinters.Context, i
3737
}()
3838
startedAt := time.Now()
3939
res, err = linter.Run(ctx, lintCtx)
40-
analytics.Log(ctx).Infof("worker #%d: linter %s took %s for paths %s", i, linter.Name(),
41-
time.Since(startedAt), lintCtx.Paths.MixedPaths())
40+
analytics.Log(ctx).Infof("worker #%d: linter %s took %s", i, linter.Name(),
41+
time.Since(startedAt))
4242
return
4343
}
4444

pkg/testdata/not_compiles/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package p
2+
3+
func F {

pkg/golinters/testdata/dupl.go renamed to pkg/testdata/with_issues/dupl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (DuplLogger) level() int {
99
func (DuplLogger) Debug(args ...interface{}) {}
1010
func (DuplLogger) Info(args ...interface{}) {}
1111

12-
func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are duplicate of `testdata/dupl.go:23-32`"
12+
func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are duplicate of `testdata/with_issues/dupl.go:23-32`"
1313
if logger.level() >= 0 {
1414
logger.Debug(args...)
1515
logger.Debug(args...)
@@ -20,7 +20,7 @@ func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are
2020
}
2121
}
2222

23-
func (logger *DuplLogger) Second(args ...interface{}) { // ERROR "23-32 lines are duplicate of `testdata/dupl.go:12-21`"
23+
func (logger *DuplLogger) Second(args ...interface{}) { // ERROR "23-32 lines are duplicate of `testdata/with_issues/dupl.go:12-21`"
2424
if logger.level() >= 1 {
2525
logger.Info(args...)
2626
logger.Info(args...)
File renamed without changes.

0 commit comments

Comments
 (0)