From 30d36e977ea7d3a8ec6fdc54037d92a1fc1e2e41 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 c1ca4b920e..b7be9e413a 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 f0b62260ee..c1366be1cd 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()) },