Skip to content

x/tools/gopls/internal/settings: enable more staticcheck passes #73058

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

Closed
adonovan opened this issue Mar 26, 2025 · 5 comments
Closed

x/tools/gopls/internal/settings: enable more staticcheck passes #73058

adonovan opened this issue Mar 26, 2025 · 5 comments
Assignees
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

This program triggers no diagnostic from staticcheck's SA4003 analyzer:

func f(x uint8) {
	if x < 0 {
		println(0)
	}
	if x >= 0 {
		println(0)
	}
}

I would have expected it to be on by default and to report that both comparisons are redundant. Why does this not happen?

@adonovan adonovan self-assigned this Mar 26, 2025
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Mar 26, 2025
@adonovan adonovan added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 26, 2025
@adonovan
Copy link
Member Author

Ok, well the answer to that question is easy: the default value of the staticcheck configuration is false.

Next question: why is it false? Let's enable the subset of its analyzers that produce reliable signals that your code has a problem (or, if the code is not necessarily wrong, as with modernizers, let's report the diagnostic at "hint" severity). What is that subset?

@gabyhelp gabyhelp added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Mar 26, 2025
@dmitshur
Copy link
Member

dmitshur commented Mar 26, 2025

What is that subset?

As noted at https://staticcheck.dev/docs/configuration/, "Staticcheck tries to provide a good out-of-the-box experience, [...]", that is, this question is already being considered upstream. So it might work well to reuse the decisions made (and maintained) there, or at least use that as a starting point.

Edit: It looks like one of the places the default check list is visible is https://staticcheck.dev/docs/configuration/options/, under the default value for "checks".

CC @dominikh.

@adonovan
Copy link
Member Author

So it might work well to reuse the decisions made (and maintained) there, or at least use that as a starting point.

I feel sure that we have discussed this question before but I can't find the thread. I remember now that at least one reason, perhaps the major one, not to enable staticcheck by default was that the buildir (SSA) pass uses facts, meaning that it is applied to all transitive dependencies, making it computationally quite expensive. We did some work in the x/tools/go/ssa to eliminate most of the costs involved, but last I heard they were not yet ported to buildir.

So I think the buildir-free subset of staticcheck may be a reasonable starting point.

@seankhliao seankhliao changed the title gopls/internal/settings: enable more staticcheck passes x/tools/gopls/internal/settings: enable more staticcheck passes Mar 26, 2025
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 26, 2025
@gopherbot gopherbot added this to the Unreleased milestone Mar 26, 2025
@findleyr
Copy link
Member

findleyr commented Apr 7, 2025

My recollection is that we would enable the buildir-free subset of staticcheck by default. I'm not sure if this is recorded anywhere; thanks for filing this issue.

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Apr 7, 2025
@adonovan
Copy link
Member Author

This is fixed, as #71038, which is really a dup of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants