github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/simple/s1033/testdata/src/example.com/CheckGuardedDelete/LintGuardedDelete.go.golden (about)

     1  // Package pkg ...
     2  package pkg
     3  
     4  func fn(m map[int]int) {
     5  	delete(m, 0)
     6  	if _, ok := m[0]; !ok {
     7  		delete(m, 0)
     8  	}
     9  	if _, ok := m[0]; ok {
    10  		println("deleting")
    11  		delete(m, 0)
    12  	}
    13  	if v, ok := m[0]; ok && v > 0 {
    14  		delete(m, 0)
    15  	}
    16  
    17  	var key int
    18  	delete(m, key)
    19  	if _, ok := m[key]; ok {
    20  		delete(m, 0)
    21  	}
    22  	if _, ok := m[key]; ok {
    23  		delete(m, key)
    24  	} else {
    25  		println("not deleted")
    26  	}
    27  
    28  	var ok bool
    29  	if _, ok = m[key]; ok {
    30  		delete(m, 0)
    31  	}
    32  	if ok {
    33  		println("deleted")
    34  	}
    35  
    36  	delete := func(a, b interface{}) {}
    37  	if _, ok := m[0]; ok {
    38  		delete(m, 0)
    39  	}
    40  }