From b615f5e0ae0a4a57b82cca5b286fc4b087b3db07 Mon Sep 17 00:00:00 2001 From: Vladimir Palevich Date: Wed, 20 Mar 2024 14:19:00 +0100 Subject: [PATCH] [nogo] match regexp againts relative paths --- go/tools/builders/nogo_main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/tools/builders/nogo_main.go b/go/tools/builders/nogo_main.go index 23acdef0eb..d282177477 100644 --- a/go/tools/builders/nogo_main.go +++ b/go/tools/builders/nogo_main.go @@ -32,6 +32,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "reflect" "regexp" "sort" @@ -442,6 +443,10 @@ func checkAnalysisResults(actions []*action, pkg *goPackage) string { } var diagnostics []entry var errs []error + cwd, err := os.Getwd() + if cwd == "" || err != nil { + errs = append(errs, fmt.Errorf("nogo failed to get CWD: %w", err)) + } for _, act := range actions { if act.err != nil { // Analyzer failed. @@ -485,6 +490,11 @@ func checkAnalysisResults(actions []*action, pkg *goPackage) string { if p.IsValid() { filename = p.Filename } + if cwd != "" { + if relname, err := filepath.Rel(cwd, filename); err == nil { + filename = relname + } + } include := true if len(currentConfig.onlyFiles) > 0 { // This analyzer emits diagnostics for only a set of files.