Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go/internal/imports: ScanDir ignores .go files that start with _ but not . #42047

Closed
dmitshur opened this issue Oct 18, 2020 · 1 comment
Closed
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Oct 18, 2020

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.

@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go modules labels Oct 18, 2020
@dmitshur dmitshur added this to the Backlog milestone Oct 18, 2020
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 19, 2020
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 19, 2020
@gopherbot
Copy link

Change https://golang.org/cl/264078 mentions this issue: imports: make ScanDir ignore go files start with dot

@dmitshur dmitshur modified the milestones: Backlog, Go1.16 Nov 27, 2020
@golang golang locked and limited conversation to collaborators Nov 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants