Skip to content

Commit

Permalink
Remove use of strings.Title()
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Sep 1, 2024
1 parent 248e041 commit e1a23c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 4 additions & 1 deletion v2/internal/controllers/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"testing"

. "github.com/onsi/gomega"
"golang.org/x/text/cases"
"golang.org/x/text/language"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -193,8 +195,9 @@ func getTestName(group string, version string) string {
result.WriteString("Test_")

// Titlecase for each part of the group
title := cases.Title(language.English)
for _, part := range strings.Split(group, ".") {
result.WriteString(strings.Title(part))
result.WriteString(title.String(part))
}
result.WriteString("_")

Expand Down
11 changes: 4 additions & 7 deletions v2/tools/generator/internal/astmodel/identifier_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"unicode"

"github.com/Azure/azure-service-operator/v2/internal/set"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// \W is all non-word characters (https://golang.org/pkg/regexp/syntax/)
Expand Down Expand Up @@ -176,18 +178,13 @@ func (factory *identifierFactory) cleanPart(part string, visibility Visibility)
clean := filterRegex.ReplaceAllLiteralString(part, " ")
cleanWords := sliceIntoWords(clean)
caseCorrectedWords := make([]string, 0, len(cleanWords))
title := cases.Title(language.English, cases.NoLower)
for ix, word := range cleanWords {
var w string
if ix == 0 && visibility == NotExported {
w = strings.ToLower(word)
} else {
// Disable lint: the suggested "replacement" for this in /x/cases has fundamental
// differences in how it works (e.g. 'JSON' becomes 'Json'; we don’t want that).
// Furthermore, the cases (ha) that it "fixes" are not relevant to us
// (something about better handling of various punctuation characters;
// our words are punctuation-free).
//nolint:staticcheck
w = strings.Title(word)
w = title.String(word)
}

caseCorrectedWords = append(caseCorrectedWords, w)
Expand Down

0 comments on commit e1a23c8

Please sign in to comment.