Skip to content

golint: strange behaviour when processing code involving go.mod replace statements #57658

@flyn-org

Description

@flyn-org

What version of Go are you using (go version)?

$ go version
go version go1.19.3 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Fedora 37.

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mike/.cache/go-build"
GOENV="/home/mike/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mike/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mike/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mike/Scratch/mwe/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build66445986=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The utility golint behaves strangely in the presence of replace statements in go.mod. Given the following directory tree:

go.mod
|
pkg--test--+--go.mod
|          |--test.go
|
prog--main.go

The following prog/main.go:

package main

import (
	"fmt"
	"local/test"
)

func main() {
	// Give golint something to complain about.
	if false {
		return
	} else {
		fmt.Printf("Hello, %d!\n", test.I)
	}
}

The following top-level go.mod:

module main

go 1.16

replace local/test => ./pkg/test

require local/test v0.0.0-00010101000000-000000000000 // indirect

I ran the command golint pkg/test/ local/test/.

What did you expect to see?

I expected to see:

$ golint pkg/test/ local/test/
prog/main.go:12:9: if block ends with a return statement, so drop this else and outdent its block
pkg/test/test.go:3:1: comment on exported var I should be of the form "I ..."

What did you see instead?

Usage of golint:
	golint [flags] # runs on package in current directory
	golint [flags] [packages]
	golint [flags] [directories] # where a '/...' suffix includes all sub-directories
	golint [flags] [files] # all must belong to a single package
Flags:
  -min_confidence float
    	minimum confidence of a problem to print it (default 0.8)
  -set_exit_status
    	set exit status to 1 if any issues are found

Things worked better if I run golint twice:

$ golint pkg/test/
pkg/test/test.go:3:1: comment on exported var I should be of the form "I ..."
$ golint local/test/
/home/mike/Scratch/mwe/pkg/test/test.go:3:1: comment on exported var I should be of the form "I ..."

Here is a file containing a minimum (not?) working example: mwe.tar.gz.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions