Repository: google/go-github
File: tools/jsonfieldname/jsonfieldname.go (Go)

Code before:
		if part == "" {
			continue
		}
		upper := strings.ToUpper(part)
		if initialisms[upper] {
			parts[i] = upper
			alt[i] = upper
		} else if specialCase, ok := specialCases[upper]; ok {
			parts[i] = specialCase
			alt[i] = specialCase
		} else if possibleAlternate, ok := possibleAlternates[upper]; ok {
			parts[i] = possibleAlternate
			alt[i] = strings.ToUpper(part[:1]) + part[1:]
		} else {
			parts[i] = strings.ToUpper(part[:1]) + part[1:]
			alt[i] = parts[i]
		}
	}
	return strings.Join(parts, ""), strings.Join(alt, "")
}

var allowedExceptions = map[string]bool{
	"ActionsCacheUsageList.RepoCacheUsage": true, // TODO: RepoCacheUsages ?
	"AuditEntry.ExternalIdentityNameID":    true,
	"AuditEntry.Timestamp":                 true,
	"CheckSuite.AfterSHA":                  true,
	"CheckSuite.BeforeSHA":                 true,
	"CodeSearchResult.CodeResults":         true,
	"CodeSearchResult.Total":               true,
	"CommitAuthor.Login":                   true,
	"CommitsSearchResult.Commits":          true,
	"CommitsSearchResult.Total":            true,
	"CreateOrgInvitationOptions.TeamID":    true, // TODO: TeamIDs
	"DependencyGraphSnapshot.Sha":          true, // TODO: SHA
	"Discussion.DiscussionCategory":        true, // TODO: Category ?
	"EditOwner.OwnerInfo":                  true,
	"Event.RawPayload":                     true,
	"HookRequest.RawPayload":               true,
	"HookResponse.RawPayload":              true,
	"Issue.PullRequestLinks":               true, // TODO: PullRequest
	"IssueImportRequest.IssueImport":       true, // TODO: Issue
	"IssuesSearchResult.Issues":            true, // TODO: Items
	"IssuesSearchResult.Total":             true,
	"LabelsSearchResult.Labels":            true, // TODO: Items
	"LabelsSearchResult.Total":             true,
	"ListCheckRunsResults.Total":           true,
	"ListCheckSuiteResults.Total":          true,
	"ListCustomDeploymentRuleIntegrationsResponse.AvailableIntegrations":      true,
	"ListDeploymentProtectionRuleResponse.ProtectionRules":                    true,
	"OrganizationCustomRepoRoles.CustomRepoRoles":                             true, // TODO: CustomRoles
	"OrganizationCustomRoles.CustomRepoRoles":                                 true, // TODO: Roles

Review comment (refactor):
A linter has its configuration in .golangci.yml. Maybe it's better to move this list into a configuration parameter for the jsonfieldname linter? That way, we don't need to rebuild the linter if we want to enable or disable items in the list.

Code after:
	}

	if strings.Contains(jsonTagName, "-") {
		return strings.Split(jsonTagName, "-")
	}

	if strings.ToLower(jsonTagName) == jsonTagName { // single word
		return []string{jsonTagName}
	}

	s := camelCaseRE.ReplaceAllString(jsonTagName, "$1 $2")
	parts := strings.Fields(s)
	for i, part := range parts {
		parts[i] = strings.ToLower(part)
	}

	return parts
}

var camelCaseRE = regexp.MustCompile(`([a-z0-9])([A-Z])`)

func jsonTagToPascal(jsonTagName string) (want, alternate string) {
	parts := splitJSONTag(jsonTagName)
	alt := make([]string, len(parts))
	for i, part := range parts {
		alt[i] = part
		if part == "" {
			continue
		}
		upper := strings.ToUpper(part)
		if initialisms[upper] {
			parts[i] = upper
			alt[i] = upper
		} else if specialCase, ok := specialCases[upper]; ok {
			parts[i] = specialCase
			alt[i] = specialCase
		} else if possibleAlternate, ok := possibleAlternates[upper]; ok {
			parts[i] = possibleAlternate
			alt[i] = strings.ToUpper(part[:1]) + part[1:]
		} else {
			parts[i] = strings.ToUpper(part[:1]) + part[1:]
			alt[i] = parts[i]
		}
	}
	return strings.Join(parts, ""), strings.Join(alt, "")
}

// Common Go initialisms that should be all caps.
var initialisms = map[string]bool{
	"API": true, "ASCII": true,
	"CAA": true, "CAS": true, "CNAME": true, "CPU": true,