From 600ed6fe56feabd911680ed43eaa76280078a4ec 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 c1ca4b920e41..b7be9e413a2d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,6 +5,7 @@ linters: - dogsled - dupword # Detects duplicate words. - durationcheck + - errchkjson - exportloopref # Detects pointers to enclosing loop variables. - gocritic # Metalinter; detects bugs, performance, and styling issues. - gocyclo diff --git a/templates/templates.go b/templates/templates.go index f0b62260eee1..c1366be1cde9 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()) },