github.com/azazeal/revive@v1.0.9/testdata/unconditional-recursion.go (about) 1 package fixtures 2 3 import ( 4 "log" 5 "os" 6 "time" 7 ) 8 9 func ur1() { 10 ur1() // MATCH /unconditional recursive call/ 11 } 12 13 func ur1bis() { 14 if true { 15 print() 16 } else { 17 switch { 18 case true: 19 println() 20 default: 21 for i := 0; i < 10; i++ { 22 print() 23 } 24 } 25 26 } 27 28 ur1bis() // MATCH /unconditional recursive call/ 29 } 30 31 func ur2tris() { 32 for { 33 println() 34 ur2tris() // MATCH /unconditional recursive call/ 35 } 36 } 37 38 func ur2() { 39 if true { 40 return 41 } 42 43 ur2() 44 } 45 46 func ur3() { 47 ur1() 48 } 49 50 func urn4() { 51 if true { 52 print() 53 } else if false { 54 return 55 } 56 57 ur4() 58 } 59 60 func urn5() { 61 if true { 62 return 63 } 64 65 if true { 66 println() 67 } 68 69 ur5() 70 } 71 72 func ur2tris() { 73 for true == false { 74 println() 75 ur2tris() 76 } 77 } 78 79 type myType struct { 80 foo int 81 bar int 82 } 83 84 func (mt *myType) Foo() int { 85 return mt.Foo() // MATCH /unconditional recursive call/ 86 } 87 88 func (mt *myType) Bar() int { 89 return mt.bar 90 } 91 92 func ur6() { 93 switch { 94 case true: 95 return 96 default: 97 println() 98 } 99 100 ur6() 101 } 102 103 func ur7(a interface{}) { 104 switch a.(type) { 105 case int: 106 return 107 default: 108 println() 109 } 110 111 ur7() 112 } 113 114 func ur8(a []int) { 115 for _, i := range a { 116 return 117 } 118 119 ur8() 120 } 121 122 func ur9(a []int) { 123 for _, i := range a { 124 ur9() 125 } 126 } 127 128 func ur10() { 129 select { 130 case <-aChannel: 131 case <-time.After(2 * time.Second): 132 return 133 } 134 ur10() 135 } 136 137 func ur11() { 138 go ur11() 139 } 140 141 func ur12() { 142 go foo(ur12()) // MATCH /unconditional recursive call/ 143 go bar(1, "string", ur12(), 1.0) // MATCH /unconditional recursive call/ 144 go foo(bar()) 145 } 146 147 func urn13() { 148 if true { 149 panic("") 150 } 151 urn13() 152 } 153 154 func urn14() { 155 if true { 156 os.Exit(1) 157 } 158 urn14() 159 } 160 161 func urn15() { 162 if true { 163 log.Panic("") 164 } 165 urn15() 166 } 167 168 func urn16(ch chan int) { 169 for range ch { 170 log.Panic("") 171 } 172 urn16(ch) 173 } 174 175 func urn17(ch chan int) { 176 for range ch { 177 print("") 178 } 179 urn17(ch) // MATCH /unconditional recursive call/ 180 }