suspicious assignment to a by-value method receiver
313 refreshTime = p.RefreshInterval[0]
314 }
315
316 p.Content += `<script>317window.setTimeout(function(){
318 $.pjax.reload('#pjax-container');
319}, ` + template.HTML(strconv.Itoa(refreshTime*1000)) + `);
suspicious assignment to a by-value method receiver
305
306 p.Content = `<div` + animation + style + ">" + p.Content + "</div>" + remove
307 if p.MiniSidebar {
308 p.Content += `<script>$("body").addClass("sidebar-collapse")</script>`309 }
310 if p.AutoRefresh {
311 refreshTime := 60
suspicious assignment to a by-value method receiver
303 </script>`)
304 }
305
306 p.Content = `<div` + animation + style + ">" + p.Content + "</div>" + remove307 if p.MiniSidebar {
308 p.Content += `<script>$("body").addClass("sidebar-collapse")</script>`
309 }
suspicious assignment to a by-value method receiver
261func (p Panel) AddComponent(comp Component) Panel {
262 p.JS += comp.GetJS()
263 p.CSS += comp.GetCSS()
264 p.Content += comp.GetContent()265 p.Callbacks = append(p.Callbacks, comp.GetCallbacks()...)
266 return p
267}
suspicious assignment to a by-value method receiver
260
261func (p Panel) AddComponent(comp Component) Panel {
262 p.JS += comp.GetJS()
263 p.CSS += comp.GetCSS()264 p.Content += comp.GetContent()
265 p.Callbacks = append(p.Callbacks, comp.GetCallbacks()...)
266 return p
suspicious assignment to a by-value method receiver
259}
260
261func (p Panel) AddComponent(comp Component) Panel {
262 p.JS += comp.GetJS()263 p.CSS += comp.GetCSS()
264 p.Content += comp.GetContent()
265 p.Callbacks = append(p.Callbacks, comp.GetCallbacks()...)
suspicious assignment to a by-value method receiver
262 p.JS += comp.GetJS()
263 p.CSS += comp.GetCSS()
264 p.Content += comp.GetContent()
265 p.Callbacks = append(p.Callbacks, comp.GetCallbacks()...)266 return p
267}
268
suspicious assignment to a by-value method receiver
267}
268
269func (p Panel) AddJS(js template.JS) Panel {
270 p.JS += js271 return p
272}
273
Description
A method that modifies its receiver value can have undesired behavior. The modification can also be the root of a bug because the actual value receiver could be a copy of that used at the calling site. This rule warns when a method modifies its receiver.
Bad practice
type data struct {
num int
key *string
items map[string]bool
}
func (d data) vmethod() {
d.num = 8
}
Recommended
type data struct {
num int
key *string
items map[string]bool
}
func (d *data) vmethod() {
d.num = 8
}