fix small bugs
This commit is contained in:
parent
100efea259
commit
c9bb265140
Gopkg.lock
internal/commands
pkg
vendor/github.com/golangci/go-tools/lint
2
Gopkg.lock
generated
2
Gopkg.lock
generated
@ -82,7 +82,7 @@
|
|||||||
"unused",
|
"unused",
|
||||||
"version"
|
"version"
|
||||||
]
|
]
|
||||||
revision = "f557f368b7f3d00a54ed44eb57b9eca59e85cee1"
|
revision = "b5abc2a37fd3a93a3716b0bc4da42d47b90ecaab"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -153,7 +153,7 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config)
|
|||||||
args = []string{"./..."}
|
args = []string{"./..."}
|
||||||
}
|
}
|
||||||
|
|
||||||
paths, err := fsutils.GetPathsForAnalysis(args)
|
paths, err := fsutils.GetPathsForAnalysis(ctx, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package golinters
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -19,11 +19,15 @@ func runGoErrchk(c *exec.Cmd, t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const testdataDir = "testdata"
|
const testdataDir = "testdata"
|
||||||
|
|
||||||
|
var testdataWithIssuesDir = filepath.Join(testdataDir, "with_issues")
|
||||||
|
var testdataNotCompilingDir = filepath.Join(testdataDir, "not_compiles")
|
||||||
|
|
||||||
const binName = "golangci-lint"
|
const binName = "golangci-lint"
|
||||||
|
|
||||||
func TestSourcesFromTestdataDir(t *testing.T) {
|
func TestSourcesFromTestdataWithIssuesDir(t *testing.T) {
|
||||||
t.Log(filepath.Join(testdataDir, "*.go"))
|
t.Log(filepath.Join(testdataWithIssuesDir, "*.go"))
|
||||||
sources, err := filepath.Glob(filepath.Join(testdataDir, "*.go"))
|
sources, err := filepath.Glob(filepath.Join(testdataWithIssuesDir, "*.go"))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, sources)
|
assert.NotEmpty(t, sources)
|
||||||
|
|
||||||
@ -39,7 +43,7 @@ func TestSourcesFromTestdataDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func installBinary(t *testing.T) {
|
func installBinary(t *testing.T) {
|
||||||
cmd := exec.Command("go", "install", filepath.Join("..", "..", "cmd", binName))
|
cmd := exec.Command("go", "install", filepath.Join("..", "cmd", binName))
|
||||||
assert.NoError(t, cmd.Run(), "Can't go install %s", binName)
|
assert.NoError(t, cmd.Run(), "Can't go install %s", binName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,3 +52,9 @@ func testOneSource(t *testing.T, sourcePath string) {
|
|||||||
cmd := exec.Command(goErrchkBin, binName, "run", "--enable-all", "--gocyclo.min-complexity", "20", sourcePath)
|
cmd := exec.Command(goErrchkBin, binName, "run", "--enable-all", "--gocyclo.min-complexity", "20", sourcePath)
|
||||||
runGoErrchk(cmd, t)
|
runGoErrchk(cmd, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNotCompilingProgram(t *testing.T) {
|
||||||
|
installBinary(t)
|
||||||
|
err := exec.Command(binName, "run", "--enable-all", testdataNotCompilingDir).Run()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golangci/golangci-shared/pkg/analytics"
|
"github.com/golangci/golangci-shared/pkg/analytics"
|
||||||
)
|
)
|
||||||
@ -54,14 +55,20 @@ func processPaths(root string, paths []string, maxPaths int) ([]string, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPathsForAnalysis(inputPaths []string) (*ProjectPaths, error) {
|
func GetPathsForAnalysis(ctx context.Context, inputPaths []string) (ret *ProjectPaths, err error) {
|
||||||
|
defer func(startedAt time.Time) {
|
||||||
|
if ret != nil {
|
||||||
|
analytics.Log(ctx).Infof("Found paths for analysis for %s: %s", time.Since(startedAt), ret.MixedPaths())
|
||||||
|
}
|
||||||
|
}(time.Now())
|
||||||
|
|
||||||
for _, path := range inputPaths {
|
for _, path := range inputPaths {
|
||||||
if strings.HasSuffix(path, ".go") && len(inputPaths) != 1 {
|
if strings.HasSuffix(path, ".go") && len(inputPaths) != 1 {
|
||||||
return nil, fmt.Errorf("Specific files for analysis are allowed only if one file is set")
|
return nil, fmt.Errorf("Specific files for analysis are allowed only if one file is set")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
excludeDirs := []string{"vendor", "testdata", "examples", "Godeps"}
|
excludeDirs := []string{"vendor", "testdata", "examples", "Godeps", "builtin"}
|
||||||
pr := NewPathResolver(excludeDirs, []string{".go"})
|
pr := NewPathResolver(excludeDirs, []string{".go"})
|
||||||
paths, err := pr.Resolve(inputPaths...)
|
paths, err := pr.Resolve(inputPaths...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,8 +37,8 @@ func runLinter(ctx context.Context, linter Linter, lintCtx *golinters.Context, i
|
|||||||
}()
|
}()
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
res, err = linter.Run(ctx, lintCtx)
|
res, err = linter.Run(ctx, lintCtx)
|
||||||
analytics.Log(ctx).Infof("worker #%d: linter %s took %s for paths %s", i, linter.Name(),
|
analytics.Log(ctx).Infof("worker #%d: linter %s took %s", i, linter.Name(),
|
||||||
time.Since(startedAt), lintCtx.Paths.MixedPaths())
|
time.Since(startedAt))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
pkg/testdata/not_compiles/main.go
vendored
Normal file
3
pkg/testdata/not_compiles/main.go
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package p
|
||||||
|
|
||||||
|
func F {
|
@ -9,7 +9,7 @@ func (DuplLogger) level() int {
|
|||||||
func (DuplLogger) Debug(args ...interface{}) {}
|
func (DuplLogger) Debug(args ...interface{}) {}
|
||||||
func (DuplLogger) Info(args ...interface{}) {}
|
func (DuplLogger) Info(args ...interface{}) {}
|
||||||
|
|
||||||
func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are duplicate of `testdata/dupl.go:23-32`"
|
func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are duplicate of `testdata/with_issues/dupl.go:23-32`"
|
||||||
if logger.level() >= 0 {
|
if logger.level() >= 0 {
|
||||||
logger.Debug(args...)
|
logger.Debug(args...)
|
||||||
logger.Debug(args...)
|
logger.Debug(args...)
|
||||||
@ -20,7 +20,7 @@ func (logger *DuplLogger) First(args ...interface{}) { // ERROR "12-21 lines are
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *DuplLogger) Second(args ...interface{}) { // ERROR "23-32 lines are duplicate of `testdata/dupl.go:12-21`"
|
func (logger *DuplLogger) Second(args ...interface{}) { // ERROR "23-32 lines are duplicate of `testdata/with_issues/dupl.go:12-21`"
|
||||||
if logger.level() >= 1 {
|
if logger.level() >= 1 {
|
||||||
logger.Info(args...)
|
logger.Info(args...)
|
||||||
logger.Info(args...)
|
logger.Info(args...)
|
@ -11,7 +11,7 @@ func Govet() error {
|
|||||||
|
|
||||||
func GovetShadow(f io.Reader, buf []byte) (err error) {
|
func GovetShadow(f io.Reader, buf []byte) (err error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
_, err := f.Read(buf) // ERROR "declaration of .err. shadows declaration at testdata/govet.go:\d+"
|
_, err := f.Read(buf) // ERROR "declaration of .err. shadows declaration at testdata/with_issues/govet.go:\d+"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
17
vendor/github.com/golangci/go-tools/lint/lint.go
generated
vendored
17
vendor/github.com/golangci/go-tools/lint/lint.go
generated
vendored
@ -23,10 +23,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/tools/go/ast/astutil"
|
|
||||||
"golang.org/x/tools/go/loader"
|
|
||||||
"github.com/golangci/go-tools/ssa"
|
"github.com/golangci/go-tools/ssa"
|
||||||
"github.com/golangci/go-tools/ssa/ssautil"
|
"github.com/golangci/go-tools/ssa/ssautil"
|
||||||
|
"golang.org/x/tools/go/ast/astutil"
|
||||||
|
"golang.org/x/tools/go/loader"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
@ -482,6 +482,14 @@ type Pkg struct {
|
|||||||
BuildPkg *build.Package
|
BuildPkg *build.Package
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Pkg) GetPackage() *types.Package {
|
||||||
|
if p.Package == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.Pkg
|
||||||
|
}
|
||||||
|
|
||||||
type packager interface {
|
type packager interface {
|
||||||
Package() *ssa.Package
|
Package() *ssa.Package
|
||||||
}
|
}
|
||||||
@ -556,7 +564,7 @@ func (prog *Program) DisplayPosition(p token.Pos) token.Position {
|
|||||||
func (j *Job) Errorf(n Positioner, format string, args ...interface{}) *Problem {
|
func (j *Job) Errorf(n Positioner, format string, args ...interface{}) *Problem {
|
||||||
tf := j.Program.SSA.Fset.File(n.Pos())
|
tf := j.Program.SSA.Fset.File(n.Pos())
|
||||||
f := j.Program.tokenFileMap[tf]
|
f := j.Program.tokenFileMap[tf]
|
||||||
pkg := j.Program.astFileMap[f].Pkg
|
pkg := j.Program.astFileMap[f].GetPackage()
|
||||||
|
|
||||||
pos := j.Program.DisplayPosition(n.Pos())
|
pos := j.Program.DisplayPosition(n.Pos())
|
||||||
problem := Problem{
|
problem := Problem{
|
||||||
@ -779,6 +787,9 @@ func NodeFns(pkgs []*Pkg) map[ast.Node]*ssa.Function {
|
|||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
chNodeFns := make(chan map[ast.Node]*ssa.Function, runtime.NumCPU()*2)
|
chNodeFns := make(chan map[ast.Node]*ssa.Function, runtime.NumCPU()*2)
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
|
if pkg.Package == nil { // package wasn't loaded, probably it doesn't compile
|
||||||
|
continue
|
||||||
|
}
|
||||||
pkg := pkg
|
pkg := pkg
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user