Skip to content

Commit 0c1ac0d

Browse files
committed
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 <github@gone.nl>
1 parent d515077 commit 0c1ac0d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ linters:
44
- depguard
55
- dogsled
66
- durationcheck
7+
- errchkjson
78
- exportloopref # Checks for pointers to enclosing loop variables
89
- gocyclo
910
- gofumpt

templates/templates.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ var basicFunctions = template.FuncMap{
1414
buf := &bytes.Buffer{}
1515
enc := json.NewEncoder(buf)
1616
enc.SetEscapeHTML(false)
17-
enc.Encode(v)
17+
err := enc.Encode(v)
18+
if err != nil {
19+
panic(err)
20+
}
21+
1822
// Remove the trailing new line added by the encoder
1923
return strings.TrimSpace(buf.String())
2024
},

0 commit comments

Comments
 (0)