github.com/azazeal/revive@v1.0.9/testdata/golint/error-return.go (about)

     1  // Test for returning errors.
     2  
     3  // Package foo ...
     4  package foo
     5  
     6  // Returns nothing
     7  func f() { // ok
     8  }
     9  
    10  // Check for a single error return
    11  func g() error { // ok
    12  	return nil
    13  }
    14  
    15  // Check for a single other return type
    16  func h() int { // ok
    17  	return 0
    18  }
    19  
    20  // Check for multiple return but error at end.
    21  func i() (int, error) { // ok
    22  	return 0, nil
    23  }
    24  
    25  // Check for multiple return but error at end with named variables.
    26  func j() (x int, err error) { // ok
    27  	return 0, nil
    28  }
    29  
    30  // Check for error in the wrong location on 2 types
    31  func k() (error, int) { // MATCH /error should be the last type when returning multiple items/
    32  	return nil, 0
    33  }
    34  
    35  // Check for error in the wrong location for > 2 types
    36  func l() (int, error, int) { // MATCH /error should be the last type when returning multiple items/
    37  	return 0, nil, 0
    38  }
    39  
    40  // Check for error in the wrong location with named variables.
    41  func m() (x int, err error, y int) { // MATCH /error should be the last type when returning multiple items/
    42  	return 0, nil, 0
    43  }
    44  
    45  // Check for multiple error returns but with errors at the end.
    46  func n() (int, error, error) { // ok
    47  	return 0, nil, nil
    48  }
    49  
    50  // Check for multiple error returns mixed in order, but keeping one error at last position.
    51  func o() (int, error, int, error) { // ok
    52  	return 0, nil, 0, nil
    53  }