alingse / sundrylint

three thousand real world bug linter
MIT License
5 stars 0 forks source link

New Idea: wasted assign in range slice. #15

Open alingse opened 3 months ago

alingse commented 3 months ago

found a case by review the fix bug PR. by human now :)

see https://github.com/operator-framework/operator-controller/pull/1899/files#diff-4e1161250663230583e5c1839b774ef8ee35d18cc9fc5801b68516a12bd3dc5eL332

type Permission struct {
    Roles []string
}

func AddRole(ps []Permission) []Permission {
    newPs := make([]Permission, 0)
    for _, p := range ps {
        p.Roles = append(p.Roles, "Hello")
    }
    newPs = append(newPs, ps...)
    return newPs
}