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

New check: warn when packages gets moved from golang.org/exp to the stdlib #1584

Open
Foxboron opened this issue Aug 12, 2024 · 4 comments
Open

Comments

@Foxboron
Copy link

I just debugged an issue where one part of the codebase was importing log/slog and an older part of the codebase was importing golang.org/x/exp/slog causing me to get very confused why setting the default logger didn't work.

Neither go vet ./... nor staticcheck ./... gave me a warning so I thought this would be a cool thing to check for.

@Foxboron Foxboron added the needs-triage Newly filed issue that needs triage label Aug 12, 2024
@dominikh dominikh added new-check and removed needs-triage Newly filed issue that needs triage labels Aug 12, 2024
@arp242
Copy link
Contributor

arp242 commented Aug 12, 2024

I wonder if it would make sense to mark x/exp/slog as deprecated?

@Foxboron
Copy link
Author

I suspect that would be annoying for everyone that doesn't have a new enough stdlib? Could you avoid false positives?

@arp242
Copy link
Contributor

arp242 commented Aug 12, 2024

Yeah, that's a potential issue.

stdlib's log/slog is more or less a drop-in replacement for x/exp/slog, but for example x/exp/maps has some stuff that didn't make it in stdlib, so "replace this package with stdlib" isn't always so straight-forward.

Something, somewhere needs to keep a list of things, whether that's in stasticcheck or "// Deprecated: ..." comments, or somewhere else.

Somewhat related issue: #499 (stylecheck: configurable import blacklist).

@Foxboron
Copy link
Author

I suspect this depends on how you want to solve the check.

You could just check if slog is occupied by multiple packages in your code base, or you could check if you are using slog.Debug from two different packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants