github.com/googleapis/api-linter@v1.65.2/lint/rule_groups.go (about)

     1  package lint
     2  
     3  import "fmt"
     4  
     5  // A list of functions, each of which returns the group name for the given AIP
     6  // number and if no group is found, returns an empty string.
     7  // NOTE: the list will be evaluated in the FILO order.
     8  //
     9  // At Google, we inject additional group naming functions into this list.
    10  // Example: google_aip_groups.go
    11  // package lint
    12  //
    13  //	func init() {
    14  //	  aipGroups = append(aipGroups, aipInternalGroup)
    15  //	}
    16  //
    17  //	func aipInternalGroup(aip int) string {
    18  //	  if aip > 9000 {
    19  //		   return "internal"
    20  //	  }
    21  //	  return ""
    22  //	}
    23  var aipGroups = []func(int) string{
    24  	aipCoreGroup,
    25  	aipClientLibrariesGroup,
    26  	aipCloudGroup,
    27  }
    28  
    29  func aipCoreGroup(aip int) string {
    30  	if aip > 0 && aip < 1000 {
    31  		return "core"
    32  	}
    33  	return ""
    34  }
    35  
    36  func aipClientLibrariesGroup(aip int) string {
    37  	if aip >= 4200 && aip <= 4299 {
    38  		return "client-libraries"
    39  	}
    40  	return ""
    41  }
    42  
    43  func aipCloudGroup(aip int) string {
    44  	if (aip >= 2500 && aip <= 2599) || (aip >= 25000 && aip <= 25999) {
    45  		return "cloud"
    46  	}
    47  	return ""
    48  }
    49  
    50  // getRuleGroup takes an AIP number and returns the appropriate group.
    51  // It panics if no group is found.
    52  func getRuleGroup(aip int, groups []func(int) string) string {
    53  	for i := len(groups) - 1; i >= 0; i-- {
    54  		if group := groups[i](aip); group != "" {
    55  			return group
    56  		}
    57  	}
    58  	panic(fmt.Sprintf("Invalid AIP number %d: no available group.", aip))
    59  }