github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/simple/s1036/testdata/src/example.com/CheckUnnecessaryGuard/LintUnnecessaryGuard.go.golden (about)

     1  package pkg
     2  
     3  func fn() {
     4  	var m = map[string][]string{}
     5  
     6  	m["k1"] = append(m["k1"], "v1", "v2")
     7  
     8  	if _, ok := m["k1"]; ok {
     9  		m["k1"] = append(m["k1"], "v1", "v2")
    10  	} else {
    11  		m["k1"] = []string{"v1"}
    12  	}
    13  
    14  	if _, ok := m["k1"]; ok {
    15  		m["k2"] = append(m["k2"], "v1")
    16  	} else {
    17  		m["k1"] = []string{"v1"}
    18  	}
    19  
    20  	k1 := "key"
    21  	m[k1] = append(m[k1], "v1", "v2")
    22  
    23  	// ellipsis is not currently supported
    24  	v := []string{"v1", "v2"}
    25  	if _, ok := m["k1"]; ok {
    26  		m["k1"] = append(m["k1"], v...)
    27  	} else {
    28  		m["k1"] = v
    29  	}
    30  
    31  	var m2 map[string]int
    32  	m2["k"] += 4
    33  
    34  	if _, ok := m2["k"]; ok {
    35  		m2["k"] += 4
    36  	} else {
    37  		m2["k"] = 3
    38  	}
    39  
    40  	m2["k"]++
    41  
    42  	if _, ok := m2["k"]; ok {
    43  		m2["k"] -= 1
    44  	} else {
    45  		m2["k"] = 1
    46  	}
    47  }
    48  
    49  // this used to cause a panic in the pattern package
    50  func fn2() {
    51  	var obj interface{}
    52  
    53  	if _, ok := obj.(map[string]interface{})["items"]; ok {
    54  		obj.(map[string]interface{})["version"] = 1
    55  	}
    56  }