-
Notifications
You must be signed in to change notification settings - Fork 18.1k
x/tools/cmd/deadcode: Underscore in file path results in no dead code detection #66045
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
Comments
This is consistent with the go command, which ignores paths with leading dots or underscores. |
@seankhliao Thanks for that additional context, I wasn't aware of that. However, the behavior of go.mod
_utils/utils.go
example/main.go
The output of
Removing the call to
|
As another potential example of the challenges with the current behavior, consider the When
When
Instead, the second example should likely report that |
This is still consistent with cmd/go: explicit imports are always part of the build, otherwise ./... has the meaning as documented. |
Appreciate your follow-up clarifications and totally agree with the high-level desire to maintain consistency between go tools whenever possible. Working-backwards from how I expect customers of this tool to use
Does that mental model of expected / typical customer usage match your own? If so, it seems like the current behavior could lead to customer confusion or missed deadcode detection, for a few different reasons:
A good analogy to the challenge here in my mind is Go's original treatment of test coverage for packages that had no tests. Rather than reporting that such packages were untested when calculating overall test coverage, Go originally did not include these packages in coverage reporting, leading to users mistakenly having incorrect coverage measurements due to this implicit filtering. Eventually, this was changed such that packages without tests were still included in coverage reporting when reporting on overall coverage. I see the behavior of Thoughts? |
Closed issues do not get much visibility. If you think there is something to be done about the clarity of package lists and patterns, I would encourage you to open a different bug. This could be requests for docs, a blog post, more code examples, better examples of tool usage, a new reserved name in package lists, etc. Your informal survey seems to indicate that this the root cause of this issue. |
Go version
go version go1.22.0 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
go.mod
_utils/utils.go
_utils/pkg/pkg.go
_utils/pkg2/pkg2.go
Ran
deadcode ./...
:What did you see happen?
deadcode ./...
had no outputWhat did you expect to see?
deadcode ./...
to output:Note that simply changing the directory name from
_utils
toutils
and rerunningdeadcode ./...
results in the expected behavior:The text was updated successfully, but these errors were encountered: