Skip to content

Commit

Permalink
dep: update wastedassign v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Mar 4, 2021
1 parent 507703b commit 3c5ee1e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -57,7 +57,7 @@ require (
github.com/polyfloyd/go-errorlint v0.0.0-20201127212506-19bd8db6546f
github.com/ryancurrah/gomodguard v1.2.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/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
github.com/shirou/gopsutil/v3 v3.21.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 68 additions & 21 deletions test/testdata/wastedassign.go
@@ -1,64 +1,64 @@
//args: -Ewastedassign
package testdata

import (
"strings"
)
import "strings"

func p(x int) int {
func pa(x int) int {
return x + 1
}

func typeSwitchNoError(val interface{}, times uint) interface{} {
switch hoge := val.(type) {
func multiple(val interface{}, times uint) interface{} {

switch hogehoge := val.(type) {
case int:
return 12
case string:
return strings.Repeat(hoge, int(times))
return strings.Repeat(hogehoge, int(times))
default:
return nil
}
}

func noUseParamsNoError(params string) int {
func noUseParams(params string) int {
a := 12
println(a)
return a
}

func manyif(param int) int {
func f(param int) int {
println(param)
useOutOfIf := 1212121 // ERROR "wasted assignment"
useOutOfIf := 1212121 // ERROR "reassigned, but reassigned without using the value"
ret := 0
if false {
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
return 0
} else if param == 100 {
useOutOfIf = 100 // ERROR "wasted assignment"
useOutOfIf = 100 // ERROR "reassigned, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = p(useOutOfIf)
useOutOfIf += 200 // ERROR "wasted assignment"
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // ERROR "reassigned, but reassigned without using the value"
} else {
useOutOfIf = 100
useOutOfIf += 100
useOutOfIf = p(useOutOfIf)
useOutOfIf += 200 // ERROR "wasted assignment"
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // ERROR "reassigned, but reassigned without using the value"
}

if false {
useOutOfIf = 200 // ERROR "reassigned, but never used afterwards"
return 0
} else if param == 200 {
useOutOfIf = 100 // ERROR "wasted assignment"
useOutOfIf = 100 // ERROR "reassigned, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = p(useOutOfIf)
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200
} else {
useOutOfIf = 100
useOutOfIf += 100
useOutOfIf = p(useOutOfIf)
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200
}
// useOutOfIf = 12
println(useOutOfIf)
useOutOfIf = 192
useOutOfIf += 100
Expand All @@ -81,19 +81,43 @@ func checkLoopTest() int {
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 hoge int
for {
hoge = 5 // ERROR "reassigned, but never used afterwards"
hoge = 5 // ERROR "reassigned, but reassigned without using the value"
// break
}

println(i)
println(hoge)
return
}

func infinity2() {
func noMugen() {
var i int
var hoge int
for {
Expand All @@ -105,3 +129,26 @@ func infinity2() {
println(hoge)
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)
}

0 comments on commit 3c5ee1e

Please sign in to comment.