
Use go/packages instead of x/tools/loader: it allows to work with go modules and speedups loading of packages with the help of build cache. A lot of linters became "fast": they are enabled by --fast now and work in 1-2 seconds. Only unparam, interfacer and megacheck are "slow" linters now. Average project is analyzed 20-40% faster than before if all linters are enabled! If we enable all linters except unparam, interfacer and megacheck analysis is 10-20x faster!
38 lines
879 B
Go
38 lines
879 B
Go
package golinters
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
ineffassignAPI "github.com/golangci/ineffassign"
|
|
)
|
|
|
|
type Ineffassign struct{}
|
|
|
|
func (Ineffassign) Name() string {
|
|
return "ineffassign"
|
|
}
|
|
|
|
func (Ineffassign) Desc() string {
|
|
return "Detects when assignments to existing variables are not used"
|
|
}
|
|
|
|
func (lint Ineffassign) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
|
issues := ineffassignAPI.Run(getAllFileNames(lintCtx))
|
|
if len(issues) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
res := make([]result.Issue, 0, len(issues))
|
|
for _, i := range issues {
|
|
res = append(res, result.Issue{
|
|
Pos: i.Pos,
|
|
Text: fmt.Sprintf("ineffectual assignment to %s", formatCode(i.IdentName, lintCtx.Cfg)),
|
|
FromLinter: lint.Name(),
|
|
})
|
|
}
|
|
return res, nil
|
|
}
|