From 73f0cd221a825554df191fe8292f85524010f5fb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 2 Sep 2022 23:49:14 +0200 Subject: [PATCH] templates: linting: fix "error return value is not checked (errchkjson) The linter is correct; given that these functions do not allow for an error to be returned, we panic. Alternatively, we could return the error string as output, or add a `//nolint:errchkjson` comment. templates/templates.go:17:3: Error return value of `(*encoding/json.Encoder).Encode` is not checked: unsafe type `interface{}` found (errchkjson) enc.Encode(v) ^ Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 1 + templates/templates.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 01891e752b4b..78d58d6ff620 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,7 @@ linters: - depguard - dogsled - durationcheck + - errchkjson - exportloopref # Checks for pointers to enclosing loop variables - gocyclo - gofmt diff --git a/templates/templates.go b/templates/templates.go index deb043299dbe..3a7ec59e5f6d 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -14,7 +14,11 @@ var basicFunctions = template.FuncMap{ buf := &bytes.Buffer{} enc := json.NewEncoder(buf) enc.SetEscapeHTML(false) - enc.Encode(v) + err := enc.Encode(v) + if err != nil { + panic(err) + } + // Remove the trailing new line added by the encoder return strings.TrimSpace(buf.String()) },