new custom linters didn't show in "Issue" or "Report" and "fmt.Println" didn't printed #2769
-
Welcome
Description of the problemI add a custom linter to check go projects. And after run that, the output shows that the linter.so was loaded and run in xx us, but the "fmt.Println() " written by the linter did not printed. Also, the custom linter wasn't print in neither "Issue" nor "Report" field of ouput. Why is that? Version of golangci-lint$ golangci-lint --version
go version go1.16.5 linux/amd64 Configuration filerun:
timeout: 5m
output:
format: json
linters:
disable-all: true
enable:
- my_checker
issues:
exclude-use-default: false
exclude-rules:
- path: ./
linters:
- my_checker
#linters-settings:
linters-settings:
custom:
my_checker:
path: /home/xx/my_checker.so
description: my_checker Go environment$ go version && go env
# paste output here Verbose output of running$ golangci-lint cache clean
$ export GL_DEBUG=loader,gocritic,env,autogen_exclude,nolint && golangci-lint -v run -c my_debug.yml .
INFO [lintersdb] Active 1 linters: [my_checker]
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 165.727µs
INFO [linters context/goanalysis] analyzers took 18.189µs with top 10 stages: my_checker: 18.189µs
INFO [runner] linters took 1.224164ms with stages: my_checker: 893.899µs
{"Issues":[{"FromLinter":"typecheck","Text":"could not import fmt (Config.Importer.Import(fmt) returned nil but no error)","Severity":"","SourceLines":["\t\"fmt\""],"Replacement":null,"Pos":{"Filename":"main.go","Offset":0,"Line":4,"Column":2},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":{"Linters":[{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode","EnabledByDefault":true},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl"},{"Name":"durationcheck"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exportloopref"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"funlen"},{"Name":"gci"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gocognit"},{"Name":"goconst"},{"Name":"gocritic"},{"Name":"gocyclo"},{"Name":"godot"},{"Name":"godox"},{"Name":"goerr113"},{"Name":"gofmt"},{"Name":"gofumpt"},{"Name":"goheader"},{"Name":"goimports"},{"Name":"golint"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","EnabledByDefault":true},{"Name":"govet","EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"importas"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"interfacer"},{"Name":"ireturn"},{"Name":"lll"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"misspell"},{"Name":"nakedret"},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"paralleltest"},{"Name":"prealloc"},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"structcheck","EnabledByDefault":true},{"Name":"stylecheck"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","EnabledByDefault":true},{"Name":"unconvert"},{"Name":"unparam"},{"Name":"unused","EnabledByDefault":true},{"Name":"varcheck","EnabledByDefault":true},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"nolintlint"}]}} Code example or link to a public repositorypackage main
import (
"fmt"
"go/ast"
"os"
"golang.org/x/tools/go/analysis"
)
type analyzerPlugin struct{}
func (*analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
return []*analysis.Analyzer{
My_CHECKERAnalyzer,
}
}
var AnalyzerPlugin analyzerPlugin
var MY_CHECKERAnalyzer = &analysis.Analyzer{
Name: "my_checker",
Doc: "limit_for_the_use_of_context",
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
fmt.Println(" test args:")
for _, file := range pass.Files {
ast.Inspect(file, func(n ast.Node) bool {
fmt.Fprintf(os.Stderr, "test1: \n")
msg := "test123"
pass.Report(analysis.Diagnostic{
Pos: n.Pos(),
End: n.End(),
Category: "my_checker",
Message: msg,
})
return true
})
}
return nil, nil
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Please provide using |
Beta Was this translation helpful? Give feedback.
-
This behavior is expected: every data sent to If you want to cancel this discard (which I don't recommend), you should use the following debug key $ GL_DEBUG=linters_output ./golangci-lint run |
Beta Was this translation helpful? Give feedback.
This behavior is expected: every data sent to
os.Stdout
/Stderr
(i.e. all the output of functions likefmt.Printxx
) by a linter is discarded.A linter should create reports not display things by itself.
If you want to cancel this discard (which I don't recommend), you should use the following debug key
linters_output
.https://golangci-lint.run/contributing/debug/