bump wastedassign to v0.2.0 (#1815)
This commit is contained in:
parent
921a1484fb
commit
351f57b174
2
go.mod
2
go.mod
@ -57,7 +57,7 @@ require (
|
|||||||
github.com/polyfloyd/go-errorlint v0.0.0-20201127212506-19bd8db6546f
|
github.com/polyfloyd/go-errorlint v0.0.0-20201127212506-19bd8db6546f
|
||||||
github.com/ryancurrah/gomodguard v1.2.0
|
github.com/ryancurrah/gomodguard v1.2.0
|
||||||
github.com/ryanrolds/sqlclosecheck v0.3.0
|
github.com/ryanrolds/sqlclosecheck v0.3.0
|
||||||
github.com/sanposhiho/wastedassign v0.1.3
|
github.com/sanposhiho/wastedassign v0.2.0
|
||||||
github.com/securego/gosec/v2 v2.6.1
|
github.com/securego/gosec/v2 v2.6.1
|
||||||
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
|
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
|
||||||
github.com/shirou/gopsutil/v3 v3.21.1
|
github.com/shirou/gopsutil/v3 v3.21.1
|
||||||
|
4
go.sum
generated
4
go.sum
generated
@ -360,8 +360,8 @@ github.com/ryancurrah/gomodguard v1.2.0/go.mod h1:rNqbC4TOIdUDcVMSIpNNAzTbzXAZa6
|
|||||||
github.com/ryanrolds/sqlclosecheck v0.3.0 h1:AZx+Bixh8zdUBxUA1NxbxVAS78vTPq4rCb8OUZI9xFw=
|
github.com/ryanrolds/sqlclosecheck v0.3.0 h1:AZx+Bixh8zdUBxUA1NxbxVAS78vTPq4rCb8OUZI9xFw=
|
||||||
github.com/ryanrolds/sqlclosecheck v0.3.0/go.mod h1:1gREqxyTGR3lVtpngyFo3hZAgk0KCtEdgEkHwDbigdA=
|
github.com/ryanrolds/sqlclosecheck v0.3.0/go.mod h1:1gREqxyTGR3lVtpngyFo3hZAgk0KCtEdgEkHwDbigdA=
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/sanposhiho/wastedassign v0.1.3 h1:qIMpTh4NGZYRbFJ+DSpLoVn8F4SLciX2afRvXPefC7w=
|
github.com/sanposhiho/wastedassign v0.2.0 h1:0vycy8D/Ky55U5ub8oJFqyDv9M4ICM/wte9sAp2/7Mc=
|
||||||
github.com/sanposhiho/wastedassign v0.1.3/go.mod h1:LGpq5Hsv74QaqM47WtIsRSF/ik9kqk07kchgv66tLVE=
|
github.com/sanposhiho/wastedassign v0.2.0/go.mod h1:LGpq5Hsv74QaqM47WtIsRSF/ik9kqk07kchgv66tLVE=
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||||
github.com/securego/gosec/v2 v2.6.1 h1:+KCw+uz16FYfFyJ/A5aU6uP7mnrL+j1TbDnk1yN+8R0=
|
github.com/securego/gosec/v2 v2.6.1 h1:+KCw+uz16FYfFyJ/A5aU6uP7mnrL+j1TbDnk1yN+8R0=
|
||||||
github.com/securego/gosec/v2 v2.6.1/go.mod h1:I76p3NTHBXsGhybUW+cEQ692q2Vp+A0Z6ZLzDIZy+Ao=
|
github.com/securego/gosec/v2 v2.6.1/go.mod h1:I76p3NTHBXsGhybUW+cEQ692q2Vp+A0Z6ZLzDIZy+Ao=
|
||||||
|
89
test/testdata/wastedassign.go
vendored
89
test/testdata/wastedassign.go
vendored
@ -1,64 +1,64 @@
|
|||||||
//args: -Ewastedassign
|
//args: -Ewastedassign
|
||||||
package testdata
|
package testdata
|
||||||
|
|
||||||
import (
|
import "strings"
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func p(x int) int {
|
func pa(x int) int {
|
||||||
return x + 1
|
return x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func typeSwitchNoError(val interface{}, times uint) interface{} {
|
func multiple(val interface{}, times uint) interface{} {
|
||||||
switch hoge := val.(type) {
|
|
||||||
|
switch hogehoge := val.(type) {
|
||||||
case int:
|
case int:
|
||||||
return 12
|
return 12
|
||||||
case string:
|
case string:
|
||||||
return strings.Repeat(hoge, int(times))
|
return strings.Repeat(hogehoge, int(times))
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func noUseParamsNoError(params string) int {
|
func noUseParams(params string) int {
|
||||||
a := 12
|
a := 12
|
||||||
println(a)
|
println(a)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func manyif(param int) int {
|
func f(param int) int {
|
||||||
println(param)
|
println(param)
|
||||||
useOutOfIf := 1212121 // ERROR "wasted assignment"
|
useOutOfIf := 1212121 // ERROR "reassigned, but reassigned without using the value"
|
||||||
ret := 0
|
ret := 0
|
||||||
if false {
|
if false {
|
||||||
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
|
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
|
||||||
return 0
|
return 0
|
||||||
} else if param == 100 {
|
} else if param == 100 {
|
||||||
useOutOfIf = 100 // ERROR "wasted assignment"
|
useOutOfIf = 100 // ERROR "reassigned, but reassigned without using the value"
|
||||||
useOutOfIf = 201
|
useOutOfIf = 201
|
||||||
useOutOfIf = p(useOutOfIf)
|
useOutOfIf = pa(useOutOfIf)
|
||||||
useOutOfIf += 200 // ERROR "wasted assignment"
|
useOutOfIf += 200 // ERROR "reassigned, but reassigned without using the value"
|
||||||
} else {
|
} else {
|
||||||
useOutOfIf = 100
|
useOutOfIf = 100
|
||||||
useOutOfIf += 100
|
useOutOfIf += 100
|
||||||
useOutOfIf = p(useOutOfIf)
|
useOutOfIf = pa(useOutOfIf)
|
||||||
useOutOfIf += 200 // ERROR "wasted assignment"
|
useOutOfIf += 200 // ERROR "reassigned, but reassigned without using the value"
|
||||||
}
|
}
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
|
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
|
||||||
return 0
|
return 0
|
||||||
} else if param == 200 {
|
} else if param == 200 {
|
||||||
useOutOfIf = 100 // ERROR "wasted assignment"
|
useOutOfIf = 100 // ERROR "reassigned, but reassigned without using the value"
|
||||||
useOutOfIf = 201
|
useOutOfIf = 201
|
||||||
useOutOfIf = p(useOutOfIf)
|
useOutOfIf = pa(useOutOfIf)
|
||||||
useOutOfIf += 200
|
useOutOfIf += 200
|
||||||
} else {
|
} else {
|
||||||
useOutOfIf = 100
|
useOutOfIf = 100
|
||||||
useOutOfIf += 100
|
useOutOfIf += 100
|
||||||
useOutOfIf = p(useOutOfIf)
|
useOutOfIf = pa(useOutOfIf)
|
||||||
useOutOfIf += 200
|
useOutOfIf += 200
|
||||||
}
|
}
|
||||||
|
// useOutOfIf = 12
|
||||||
println(useOutOfIf)
|
println(useOutOfIf)
|
||||||
useOutOfIf = 192
|
useOutOfIf = 192
|
||||||
useOutOfIf += 100
|
useOutOfIf += 100
|
||||||
@ -81,11 +81,35 @@ func checkLoopTest() int {
|
|||||||
return hoge
|
return hoge
|
||||||
}
|
}
|
||||||
|
|
||||||
func infinity() {
|
func r(param int) int {
|
||||||
|
println(param)
|
||||||
|
useOutOfIf := 1212121
|
||||||
|
ret := 0
|
||||||
|
if false {
|
||||||
|
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
|
||||||
|
return 0
|
||||||
|
} else if param == 100 {
|
||||||
|
ret = useOutOfIf
|
||||||
|
} else if param == 200 {
|
||||||
|
useOutOfIf = 100 // ERROR "reassigned, but reassigned without using the value"
|
||||||
|
useOutOfIf = 100
|
||||||
|
useOutOfIf = pa(useOutOfIf)
|
||||||
|
useOutOfIf += 200 // ERROR "reassigned, but reassigned without using the value"
|
||||||
|
}
|
||||||
|
useOutOfIf = 12
|
||||||
|
println(useOutOfIf)
|
||||||
|
useOutOfIf = 192
|
||||||
|
useOutOfIf += 100
|
||||||
|
useOutOfIf += 200 // ERROR "reassigned, but never used afterwards"
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func mugen() {
|
||||||
var i int
|
var i int
|
||||||
var hoge int
|
var hoge int
|
||||||
for {
|
for {
|
||||||
hoge = 5 // ERROR "reassigned, but never used afterwards"
|
hoge = 5 // ERROR "reassigned, but reassigned without using the value"
|
||||||
|
// break
|
||||||
}
|
}
|
||||||
|
|
||||||
println(i)
|
println(i)
|
||||||
@ -93,7 +117,7 @@ func infinity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func infinity2() {
|
func noMugen() {
|
||||||
var i int
|
var i int
|
||||||
var hoge int
|
var hoge int
|
||||||
for {
|
for {
|
||||||
@ -105,3 +129,26 @@ func infinity2() {
|
|||||||
println(hoge)
|
println(hoge)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reassignInsideLoop() {
|
||||||
|
bar := func(b []byte) ([]byte, error) { return b, nil }
|
||||||
|
var err error
|
||||||
|
var rest []byte
|
||||||
|
for {
|
||||||
|
rest, err = bar(rest)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func reassignInsideLoop2() {
|
||||||
|
var x int = 0
|
||||||
|
var y int = 1
|
||||||
|
for i := 1; i < 3; i++ {
|
||||||
|
x += y
|
||||||
|
y *= 2 * i
|
||||||
|
}
|
||||||
|
println(x)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user