Rule | Description | Example | KPI | |
---|---|---|---|---|
S1001-Replace for loop with call to copy | Use copy() for copying elements from one slice to another. | //non-compliant code for i, x := range src { dst[i] = x } //compliant code copy(dst, src) | Functionality, Efficiency | low |
S1002-Omit comparison with boolean constant | Omit comparison with boolean constant | //non-compliant code if x == true {} //compliant code if x {} | Functionality | low |
S1005-Drop unnecessary use of the blank identifier | In many cases, assigning to the blank identifier is unnecessary. | //non-compliant code for _ = range s {} x, _ = someMap[key] _ = <-ch //compliant code for range s{} x = someMap[key] <-ch | Functionality | low |
S1006-Use for { ... } for infinite loops | For infinite loops, using for { ... } is the most idiomatic choice. | Functionality | low | |
S1012-Replace time.Now().Sub(x) with time.Since(x) | Replace time.Now().Sub(x) with time.Since(x) | //non-compliant code time.Now().Sub(x) //compliant code time.Since(x) | Functionality | low |
S1020-Omit redundant nil check in type assertion | Omit redundant nil check in type assertion | //non-compliant code if _, ok := i.(T); ok && i != nil {} //compliant code if _, ok := i.(T); ok {} | Functionality | low |
S1021-Merge variable declaration and assignment | Merge variable declaration and assignment | //non-compliant code var x uint x = 1 //compliant code var x uint = 1 | Functionality | low |
S1031-Omit redundant nil check around loop | Omit redundant nil check around loop | Functionality | low | |
S1032-Use sort.Ints(x), sort.Float64s(x), and sort.Strings(x) | The sort.Ints, sort.Float64s and sort.Strings functions are easier to read than sort.Sort(sort.IntSlice(x)), sort.Sort(sort.Float64Slice(x)) and sort.Sort(sort.StringSlice(x)). | //non-compliant code sort.Sort(sort.StringSlice(x)) //compliant code sort.Strings(x) | Functionality | low |
S1033-Unnecessary guard around call to delete | Calling delete on a nil map is a no-op. | Functionality | low |
Showing 1 to 10 of 46 entries