Skip to content

Commit

Permalink
templates: linting: fix "error return value is not checked (errchkjson)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thaJeztah committed Sep 3, 2022
1 parent 5a602c7 commit 96d2a6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters:
- depguard
- dogsled
- durationcheck
- errchkjson
- exportloopref # Checks for pointers to enclosing loop variables
- gocyclo
- gofmt
Expand Down
6 changes: 5 additions & 1 deletion templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
Expand Down

0 comments on commit 96d2a6d

Please sign in to comment.