mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Merge pull request #12450 from owen-mc/unexpected-directory-layout
Diagnostic for imports with relative package paths
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/github/codeql-go/extractor"
|
||||
"github.com/github/codeql-go/extractor/diagnostics"
|
||||
)
|
||||
|
||||
var cpuprofile, memprofile string
|
||||
@@ -115,7 +116,12 @@ func main() {
|
||||
log.Printf("Build flags: '%s'; patterns: '%s'\n", strings.Join(buildFlags, " "), strings.Join(patterns, " "))
|
||||
err := extractor.ExtractWithFlags(buildFlags, patterns)
|
||||
if err != nil {
|
||||
log.Fatalf("Error running go tooling: %s\n", err.Error())
|
||||
errString := err.Error()
|
||||
if strings.Contains(errString, "unexpected directory layout:") {
|
||||
diagnostics.EmitRelativeImportPaths()
|
||||
}
|
||||
|
||||
log.Fatalf("Error running go tooling: %s\n", errString)
|
||||
}
|
||||
|
||||
if memprofile != "" {
|
||||
|
||||
@@ -181,3 +181,14 @@ func EmitGoFilesFoundButNotProcessed() {
|
||||
noLocation,
|
||||
)
|
||||
}
|
||||
|
||||
func EmitRelativeImportPaths() {
|
||||
emitDiagnostic(
|
||||
"go/autobuilder/relative-import-paths",
|
||||
"Some imports use unsupported relative package paths",
|
||||
"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).",
|
||||
severityError,
|
||||
fullVisibility,
|
||||
noLocation,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"markdownMessage": "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).",
|
||||
"severity": "error",
|
||||
"source": {
|
||||
"extractorName": "go",
|
||||
"id": "go/autobuilder/relative-import-paths",
|
||||
"name": "Some imports use unsupported relative package paths"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": true,
|
||||
"statusPage": true,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import sys
|
||||
|
||||
from create_database_utils import *
|
||||
from diagnostics_test_utils import *
|
||||
|
||||
os.environ['GITHUB_REPOSITORY'] = "a/b"
|
||||
run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully)
|
||||
|
||||
check_diagnostics()
|
||||
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"./subpkg"
|
||||
)
|
||||
|
||||
func main() {
|
||||
subpkg.F()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package subpkg
|
||||
|
||||
import "fmt"
|
||||
|
||||
func F() {
|
||||
// It is required that there is an import in this package, which is import by another package using a local path
|
||||
fmt.Println("subpkg.F")
|
||||
}
|
||||
Reference in New Issue
Block a user