github.com/nozzle/golangci-lint@v1.49.0-nz3/test/testdata/gocognit.go (about) 1 //golangcitest:args -Egocognit 2 //golangcitest:config_path testdata/configs/gocognit.yml 3 package testdata 4 5 func GoCognit_CC4_GetWords(number int) string { // want "cognitive complexity 4 of func .* is high .*" 6 if number == 1 { // +1 7 return "one" 8 } else if number == 2 { // +1 9 return "a couple" 10 } else if number == 3 { // +1 11 return "a few" 12 } else { // +1 13 return "lots" 14 } 15 } // total complexity = 4 16 17 func GoCognit_CC1_GetWords(number int) string { 18 switch number { // +1 19 case 1: 20 return "one" 21 case 2: 22 return "a couple" 23 case 3: 24 return "a few" 25 default: 26 return "lots" 27 } 28 } // Cognitive complexity = 1 29 30 func GoCognit_CC3_Fact(n int) int { // want "cognitive complexity 3 of func .* is high .*" 31 if n <= 1 { // +1 32 return 1 33 } else { // +1 34 return n + GoCognit_CC3_Fact(n-1) // +1 35 } 36 } // total complexity = 3 37 38 func GoCognit_CC7_SumOfPrimes(max int) int { // want "cognitive complexity 7 of func .* is high .*" 39 var total int 40 41 OUT: 42 for i := 1; i < max; i++ { // +1 43 for j := 2; j < i; j++ { // +2 (nesting = 1) 44 if i%j == 0 { // +3 (nesting = 2) 45 continue OUT // +1 46 } 47 } 48 total += i 49 } 50 51 return total 52 } // Cognitive complexity = 7