go-simpler / sloglint

🪵 Ensure consistent code style when using log/slog
https://go-simpler.org/sloglint
Mozilla Public License 2.0
75 stars 5 forks source link

feat: implement `--forbidden-keys` #40

Closed tigrato closed 2 months ago

tigrato commented 2 months ago

This PR implements a linter rule to deny usages of certain keys as attributes to enforce that developers don't override reserved keys managed by custom handlers.

tmzane commented 2 months ago

Hello, thank you for the PR, I like the idea!

I noticed that you first named it --forbidden-key, which I actually like better, because there might be other reasons why a log key is forbidden (e.g., a styleguide). In general, I think sloglint does not need to know the semantics behind the keys, it just needs to forbid them.

tigrato commented 2 months ago

@tmzane thanks.

I reverted the feature to its original name forbbiden-key.

tmzane commented 2 months ago

I just remembered that strconv.Unquote exists. And it is used in the standard library exactly for this case!

tmzane commented 2 months ago

@tigrato thanks, this is a great feature to have!

@mattdowdell as always, thanks for the review!

tmzane commented 2 months ago

Oh, and we should bump Go version in go.mod, because the slices package only exists since 1.21.