mirror of https://github.com/docker/cli.git
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>
This commit is contained in:
parent
4e2477f85f
commit
30d36e977e
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue