From 9a036658b7b1eab8f226171e72319ec2e9e84176 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 22 May 2024 10:08:42 +0200 Subject: [PATCH] Add an environment varialbe which disables the parsing of Go version from module file Signed-off-by: Cosmin Cojocar --- helpers.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/helpers.go b/helpers.go index 2e28b31..098d311 100644 --- a/helpers.go +++ b/helpers.go @@ -32,6 +32,9 @@ import ( "strings" ) +// noGoModVersion disables the parsing of go version from go module file present in the project +const noGoModVersion = "GOSECNOMODVERSION" + // MatchCallByPackage ensures that the specified package is imported, // adjusts the name for any aliases and ignores cases that are // initialization only imports. @@ -498,12 +501,13 @@ func RootPath(root string) (string, error) { // GoVersion returns parsed version of Go mod version and fallback to runtime version if not found. func GoVersion() (int, int, int) { - goVersion, err := goModVersion() - if err != nil { - return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go")) + _, ok := os.LookupEnv(noGoModVersion) + if ok { + if goModVersion, err := goModVersion(); err == nil { + return parseGoVersion(goModVersion) + } } - - return parseGoVersion(goVersion) + return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go")) } type goListOutput struct {