From https://golang.org/cmd/go/:
Files whose names begin with "_" (including "_test.go") or "." are ignored.
ScanDir has a !strings.HasPrefix(name, "_") condition but does not have a !strings.HasPrefix(name, ".") one.
As a result, imports in a _ignore.go file don't contribute to the module graph:
$ cd $(mktemp -d)
$ go mod init m.test
go: creating new go.mod: module m.test
$ echo 'package p' > p.go
$ cat <<EOF >_ignore.go
package p
import _ "golang.org/x/mod/modfile"
EOF
$ go mod tidy
$ cat go.mod
module m.test
go 1.16
But imports in a .ignore.go file do:
# ... same as above
$ cat <<EOF >.ignore.go
package p
import _ "golang.org/x/mod/modfile"
EOF
$ go mod tidy
go: finding module for package golang.org/x/mod/modfile
go: found golang.org/x/mod/modfile in golang.org/x/mod v0.3.0
$ cat go.mod
module m.test
go 1.16
require golang.org/x/mod v0.3.0
CC @jayconrod, @matloob, @bcmills.
From https://golang.org/cmd/go/:
ScanDirhas a!strings.HasPrefix(name, "_")condition but does not have a!strings.HasPrefix(name, ".")one.As a result, imports in a
_ignore.gofile don't contribute to the module graph:But imports in a
.ignore.gofile do:CC @jayconrod, @matloob, @bcmills.