Skip to content

Commit 674799a

Browse files
committed
Implement diagnostic for relative package paths
1 parent d6712b2 commit 674799a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

go/extractor/cli/go-extractor/go-extractor.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/github/codeql-go/extractor"
12+
"github.com/github/codeql-go/extractor/diagnostics"
1213
)
1314

1415
var cpuprofile, memprofile string
@@ -115,7 +116,12 @@ func main() {
115116
log.Printf("Build flags: '%s'; patterns: '%s'\n", strings.Join(buildFlags, " "), strings.Join(patterns, " "))
116117
err := extractor.ExtractWithFlags(buildFlags, patterns)
117118
if err != nil {
118-
log.Fatalf("Error running go tooling: %s\n", err.Error())
119+
errString := err.Error()
120+
if strings.Contains(errString, "unexpected directory layout:") {
121+
diagnostics.EmitRelativeImportPaths()
122+
}
123+
124+
log.Fatalf("Error running go tooling: %s\n", errString)
119125
}
120126

121127
if memprofile != "" {

go/extractor/diagnostics/diagnostics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,14 @@ func EmitGoFilesFoundButNotProcessed() {
181181
noLocation,
182182
)
183183
}
184+
185+
func EmitRelativeImportPaths() {
186+
emitDiagnostic(
187+
"go/autobuilder/relative-import-paths",
188+
"Some imports use unsupported relative package paths",
189+
"You should replace relative package paths (that contain `.` or `..`) with absolute paths. Alternatively you can [use a Go module](https://go.dev/blog/using-go-modules).",
190+
severityError,
191+
fullVisibility,
192+
noLocation,
193+
)
194+
}

0 commit comments

Comments
 (0)