github.com/Johnny2210/revive@v1.0.8-0.20210625134200-febf37ccd0f5/testdata/golint/indent-error-flow.go (about)

     1  // Test of return+else warning.
     2  
     3  // Package pkg ...
     4  package pkg
     5  
     6  import "log"
     7  
     8  func f(x int) bool {
     9  	if x > 0 {
    10  		return true
    11  	} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block/
    12  		log.Printf("non-positive x: %d", x)
    13  	}
    14  	return false
    15  }
    16  
    17  func g(f func() bool) string {
    18  	if ok := f(); ok {
    19  		return "it's okay"
    20  	} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)/
    21  		return "it's NOT okay!"
    22  	}
    23  }
    24  
    25  func h(f func() bool, x int) string {
    26  	if err == author.ErrCourseNotFound {
    27  		return
    28  	} else if err == author.ErrCourseAccess {
    29  		// side effect
    30  	} else if err == author.AnotherError {
    31  		return "okay"
    32  	} else {
    33  		if ok := f(); ok {
    34  			return "it's okay"
    35  		} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)/
    36  			return "it's NOT okay!"
    37  		}
    38  	}
    39  }
    40