-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
- Loading branch information
Showing
4 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package key_forbidden | ||
|
||
import "log/slog" | ||
|
||
const ( | ||
snakeKey = "foo_bar" | ||
) | ||
|
||
func tests() { | ||
slog.Info("msg") | ||
slog.Info("msg", "foo-bar", 1) | ||
slog.Info("msg", "foo_bar", 1) // want `keys include forbidden values` | ||
slog.Info("msg", snakeKey, 1) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Int("foo_bar", 1)) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Int(snakeKey, 1)) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{}) | ||
slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{snakeKey, slog.IntValue(1)}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Key: "foo_bar"}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Key: snakeKey}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Key: snakeKey, Value: slog.IntValue(1)}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: snakeKey}) // want `keys include forbidden values` | ||
slog.With(slog.Attr{"foo_bar", slog.IntValue(1)}).Info("msg") // want `keys include forbidden values` | ||
slog.With(slog.Attr{snakeKey, slog.IntValue(1)}) // want `keys include forbidden values` | ||
slog.With(snakeKey, slog.IntValue(1)) // want `keys include forbidden values` | ||
slog.With("foo_bar", slog.IntValue(1)) // want `keys include forbidden values` | ||
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: `foo_bar`}) // want `keys include forbidden values` | ||
} |