
1. Log all warnings, don't hide none of them 2. Write fatal messages (stop analysis) with error log level 3. Remove ugly timestamp counter from logrus output 4. Print nested module prefix in log 5. Make logger abstraction: no global logging anymore 6. Refactor config reading to config.FileReader struct to avoid passing logger into every function 7. Replace exit codes hardcoding with constants in exitcodes package 8. Fail test if any warning was logged 9. Fix calculation of relative path if we analyze parent dir ../ 10. Move Runner initialization from Executor to NewRunner func 11. Log every AST parsing error 12. Properly print used config file path in verbose mode 13. Print package files if only 1 package is analyzedin verbose mode, print not compiling packages in verbose mode 14. Forbid usage of github.com/sirupsen/logrus by DepGuard linter 15. Add default ignore pattern to folint: "comment on exported const"
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package golinters
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
megacheckAPI "github.com/golangci/go-tools/cmd/megacheck"
|
|
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
)
|
|
|
|
type Megacheck struct {
|
|
UnusedEnabled bool
|
|
GosimpleEnabled bool
|
|
StaticcheckEnabled bool
|
|
}
|
|
|
|
func (m Megacheck) Name() string {
|
|
names := []string{}
|
|
if m.UnusedEnabled {
|
|
names = append(names, "unused")
|
|
}
|
|
if m.GosimpleEnabled {
|
|
names = append(names, "gosimple")
|
|
}
|
|
if m.StaticcheckEnabled {
|
|
names = append(names, "staticcheck")
|
|
}
|
|
|
|
if len(names) == 1 {
|
|
return names[0] // only one sublinter is enabled
|
|
}
|
|
|
|
if len(names) == 3 {
|
|
return "megacheck" // all enabled
|
|
}
|
|
|
|
return fmt.Sprintf("megacheck.{%s}", strings.Join(names, ","))
|
|
}
|
|
|
|
func (m Megacheck) Desc() string {
|
|
descs := map[string]string{
|
|
"unused": "Checks Go code for unused constants, variables, functions and types",
|
|
"gosimple": "Linter for Go source code that specializes in simplifying a code",
|
|
"staticcheck": "Staticcheck is a go vet on steroids, applying a ton of static analysis checks",
|
|
"megacheck": "3 sub-linters in one: unused, gosimple and staticcheck",
|
|
}
|
|
|
|
return descs[m.Name()]
|
|
}
|
|
|
|
func (m Megacheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
|
if len(lintCtx.NotCompilingPackages) != 0 {
|
|
var packages []string
|
|
for _, p := range lintCtx.NotCompilingPackages {
|
|
packages = append(packages, p.String())
|
|
}
|
|
lintCtx.Log.Warnf("Can't run megacheck because of compilation errors in packages "+
|
|
"%s: run `typecheck` linter to see errors", packages)
|
|
// megacheck crashes if there are not compiling packages
|
|
return nil, nil
|
|
}
|
|
|
|
issues := megacheckAPI.Run(lintCtx.Program, lintCtx.LoaderConfig, lintCtx.SSAProgram,
|
|
m.StaticcheckEnabled, m.GosimpleEnabled, m.UnusedEnabled)
|
|
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.Position,
|
|
Text: i.Text,
|
|
FromLinter: m.Name(),
|
|
})
|
|
}
|
|
return res, nil
|
|
}
|