chore(util): Fix modernize linter (#26329)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2026-02-09 11:44:05 +01:00
committed by GitHub
parent f2c69c1628
commit 34eeede822
7 changed files with 7 additions and 10 deletions

View File

@@ -353,7 +353,7 @@ func diffArrayCached(configArray []*unstructured.Unstructured, liveArray []*unst
Diffs: make([]diff.DiffResult, numItems),
}
for i := 0; i < numItems; i++ {
for i := range numItems {
config := configArray[i]
live := liveArray[i]
resourceVersion := ""

View File

@@ -247,7 +247,7 @@ const (
func setComments(input []byte, comments string) []byte {
input = stripComments(input)
var commentLines []string
for _, line := range strings.Split(comments, "\n") {
for line := range strings.SplitSeq(comments, "\n") {
if line != "" {
commentLines = append(commentLines, "# "+line)
}

2
util/env/env.go vendored
View File

@@ -202,7 +202,7 @@ func ParseStringToStringFromEnv(envVar string, defaultValue map[string]string, s
}
parsed := make(map[string]string)
for _, pair := range strings.Split(str, separator) {
for pair := range strings.SplitSeq(str, separator) {
keyvalue := strings.Split(pair, "=")
if len(keyvalue) != 2 {
log.Warnf("Invalid key-value pair when parsing environment '%s' as a string map", str)

View File

@@ -144,7 +144,7 @@ func (vm VM) ExecuteHealthLua(obj *unstructured.Unstructured, script string) (*h
err = json.Unmarshal(jsonBytes, healthStatus)
if err != nil {
// Validate if the error is caused by an empty object
typeError := &json.UnmarshalTypeError{Value: "array", Type: reflect.TypeOf(healthStatus)}
typeError := &json.UnmarshalTypeError{Value: "array", Type: reflect.TypeFor[*health.HealthStatus]()}
if errors.As(err, &typeError) {
return &health.HealthStatus{}, nil
}

View File

@@ -85,10 +85,7 @@ func (h DummyPasswordHasher) VerifyPassword(password, hashedPassword string) boo
// HashPassword creates a one-way digest ("hash") of a password. In the case of Bcrypt, a pseudorandom salt is included automatically by the underlying library. For security reasons, the work factor is always at _least_ bcrypt.DefaultCost.
func (h BcryptPasswordHasher) HashPassword(password string) (string, error) {
cost := h.Cost
if cost < bcrypt.DefaultCost {
cost = bcrypt.DefaultCost
}
cost := max(h.Cost, bcrypt.DefaultCost)
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), cost)
if err != nil {
hashedPassword = []byte("")

View File

@@ -18,7 +18,7 @@ func String(n int) (string, error) {
func StringFromCharset(n int, charset string) (string, error) {
b := make([]byte, n)
maxIdx := big.NewInt(int64(len(charset)))
for i := 0; i < n; i++ {
for i := range n {
randIdx, err := rand.Int(rand.Reader, maxIdx)
if err != nil {
return "", fmt.Errorf("failed to generate random string: %w", err)

View File

@@ -523,7 +523,7 @@ func Test_affectedRevisionInfo_appRevisionHasChanged(t *testing.T) {
// The payload's "push.changes[0].new.name" member seems to only have the branch name (based on the example payload).
// https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#EventPayloads-Push
var pl bitbucket.RepoPushPayload
err := json.Unmarshal([]byte(fmt.Sprintf(`{"push":{"changes":[{"new":{"name":%q}}]}}`, branchName)), &pl)
err := json.Unmarshal(fmt.Appendf(nil, `{"push":{"changes":[{"new":{"name":%q}}]}}`, branchName), &pl)
require.NoError(t, err)
return pl
}