mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* inline mattermost-govet * fix style issues * simplify the openApiSync spec test * README.md tweaks * fix missing licenses * simplify README.md * trigger server-ci on tools/mattermost-govet/** * Apply https://github.com/mattermost/mattermost-govet/commit/470cf78253f0aa85a4f4b5b50002682bf823e729 --------- Co-authored-by: Mattermost Build <[email protected]>
75 lines
908 B
Go
75 lines
908 B
Go
//go:build ignore
|
|
|
|
package pkg
|
|
|
|
//immut:type T
|
|
|
|
type T struct {
|
|
a int
|
|
b map[string]int
|
|
c *T
|
|
d []int
|
|
e int
|
|
f int
|
|
g int
|
|
h *T3
|
|
i map[string]*T
|
|
}
|
|
|
|
func (t *T) Mut() {
|
|
t.a++
|
|
}
|
|
|
|
type t2 struct {
|
|
x *int
|
|
}
|
|
|
|
type T3 struct {
|
|
x int
|
|
}
|
|
|
|
func gen() *T { return nil }
|
|
|
|
func (t *T) Mut2(t3 *T3) {
|
|
// all of these should flag, they're fairly direct mutations of T
|
|
t.a++
|
|
t.b[""] = 1
|
|
t.b[""]++
|
|
t.c.a++
|
|
t.d[2] = 1
|
|
x := &t.e
|
|
*x++
|
|
y := &t.f
|
|
if false {
|
|
y = nil
|
|
}
|
|
*y++
|
|
|
|
// should flag, because &t.g is immutable
|
|
z := t2{&t.g}
|
|
*z.x++
|
|
|
|
// should flag, because it's addressed through the immutable T
|
|
t.h.x++
|
|
|
|
// should not flag, because T3 is not immutable
|
|
t3.x++
|
|
|
|
// should flag
|
|
t.i[""].a++ // FLAGGED
|
|
|
|
// should flag, inc is known to mutate its param
|
|
inc(&t.a)
|
|
|
|
// should flag, add is known to mutate its param
|
|
add(t.b)
|
|
}
|
|
|
|
func inc(x *int) {
|
|
*x++
|
|
}
|
|
|
|
func add(m map[string]int) {
|
|
m[""] = 0
|
|
}
|