go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

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

Open Foxboron opened this issue 1 year ago • 4 comments

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 avatar Aug 12 '24 21:08 Foxboron

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

arp242 avatar Aug 12 '24 22:08 arp242

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

Foxboron avatar Aug 12 '24 22:08 Foxboron

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).

arp242 avatar Aug 12 '24 23:08 arp242

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.

Foxboron avatar Aug 13 '24 06:08 Foxboron