Skip to content

Commit 55c07a0

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 b28554a commit 55c07a0

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
@@ -5,6 +5,7 @@ linters:
55
- dogsled
66
- dupword # Detects duplicate words.
77
- durationcheck
8+
- errchkjson
89
- exportloopref # Detects pointers to enclosing loop variables.
910
- gocritic # Metalinter; detects bugs, performance, and styling issues.
1011
- gocyclo

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)