@@ -59,9 +59,9 @@ func (e *errchkjson) run(pass *analysis.Pass) (interface{}, error) {
59
59
60
60
switch fn .FullName () {
61
61
case "encoding/json.Marshal" , "encoding/json.MarshalIndent" :
62
- e .handleJSONMarshal (pass , ce , fn .FullName (), blankIdentifier )
62
+ e .handleJSONMarshal (pass , ce , fn .FullName (), blankIdentifier , e . omitSafe )
63
63
case "(*encoding/json.Encoder).Encode" :
64
- e .handleJSONMarshal (pass , ce , fn .FullName (), blankIdentifier )
64
+ e .handleJSONMarshal (pass , ce , fn .FullName (), blankIdentifier , true )
65
65
default :
66
66
e .inspectArgs (pass , ce .Args )
67
67
}
@@ -85,9 +85,9 @@ func (e *errchkjson) run(pass *analysis.Pass) (interface{}, error) {
85
85
86
86
switch fn .FullName () {
87
87
case "encoding/json.Marshal" , "encoding/json.MarshalIndent" :
88
- e .handleJSONMarshal (pass , ce , fn .FullName (), evaluateMarshalErrorTarget (as .Lhs [1 ]))
88
+ e .handleJSONMarshal (pass , ce , fn .FullName (), evaluateMarshalErrorTarget (as .Lhs [1 ]), e . omitSafe )
89
89
case "(*encoding/json.Encoder).Encode" :
90
- e .handleJSONMarshal (pass , ce , fn .FullName (), evaluateMarshalErrorTarget (as .Lhs [0 ]))
90
+ e .handleJSONMarshal (pass , ce , fn .FullName (), evaluateMarshalErrorTarget (as .Lhs [0 ]), true )
91
91
default :
92
92
return true
93
93
}
@@ -115,7 +115,7 @@ const (
115
115
functionArgument // the returned error from the JSON marshal function is passed to an other function as argument.
116
116
)
117
117
118
- func (e * errchkjson ) handleJSONMarshal (pass * analysis.Pass , ce * ast.CallExpr , fnName string , errorTarget marshalErrorTarget ) {
118
+ func (e * errchkjson ) handleJSONMarshal (pass * analysis.Pass , ce * ast.CallExpr , fnName string , errorTarget marshalErrorTarget , omitSafe bool ) {
119
119
t := pass .TypesInfo .TypeOf (ce .Args [0 ])
120
120
if t == nil {
121
121
// Not sure, if this is at all possible
@@ -143,11 +143,11 @@ func (e *errchkjson) handleJSONMarshal(pass *analysis.Pass, ce *ast.CallExpr, fn
143
143
pass .Reportf (ce .Pos (), "Error return value of `%s` is not checked: %v" , fnName , err )
144
144
}
145
145
}
146
- if err == nil && errorTarget == variableAssignment && ! e . omitSafe {
146
+ if err == nil && errorTarget == variableAssignment && ! omitSafe {
147
147
pass .Reportf (ce .Pos (), "Error return value of `%s` is checked but passed argument is safe" , fnName )
148
148
}
149
149
// Report an error, if err for json.Marshal is not checked and safe types are omitted
150
- if err == nil && errorTarget == blankIdentifier && e . omitSafe {
150
+ if err == nil && errorTarget == blankIdentifier && omitSafe {
151
151
pass .Reportf (ce .Pos (), "Error return value of `%s` is not checked" , fnName )
152
152
}
153
153
}
@@ -296,9 +296,9 @@ func (e *errchkjson) inspectArgs(pass *analysis.Pass, args []ast.Expr) {
296
296
297
297
switch fn .FullName () {
298
298
case "encoding/json.Marshal" , "encoding/json.MarshalIndent" :
299
- e .handleJSONMarshal (pass , ce , fn .FullName (), functionArgument )
299
+ e .handleJSONMarshal (pass , ce , fn .FullName (), functionArgument , e . omitSafe )
300
300
case "(*encoding/json.Encoder).Encode" :
301
- e .handleJSONMarshal (pass , ce , fn .FullName (), functionArgument )
301
+ e .handleJSONMarshal (pass , ce , fn .FullName (), functionArgument , true )
302
302
default :
303
303
e .inspectArgs (pass , ce .Args )
304
304
}
0 commit comments