16 msformat136 mscheck 278total 66errors 101warnings 111notes

base62.go19

1:9package-commentspackage should have a documentation comment

base62.go:1:9

1package ksuid
2
17:2no-package-varpackage variables introduce mutable global state

base62.go:17:2

16var (
17 errShortBuffer = errors.New("the output buffer is too small to hold to decoded value")
18)
22:2single-case-switchswitch with one case can be replaced by an if statement

base62.go:22:2

21func base62Value(digit byte) byte {
22 switch {
23 case digit >= '0' && digit <= '9':
60:16redundant-conversionconversion from uint64 to the identical type is redundant

base62.go:60:16

59 quotient := bq[:0]
60 remainder := uint64(0)
61
63:25redundant-conversionconversion from uint64 to the identical type is redundant

base62.go:63:25

62 for _, c := range bp {
63 value := uint64(c) + uint64(remainder)*srcBase
64 digit := value / dstBase
67:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

base62.go:67:7

66
67 if len(quotient) != 0 || digit != 0 {
68 quotient = append(quotient, uint32(digit))
75:3modifies-parameterassignment modifies parameter dst

base62.go:75:3

74 n--
75 dst[n] = base62Characters[remainder]
76 bp = quotient
89:2modifies-parameterassignment modifies parameter dst

base62.go:89:2

88func fastAppendEncodeBase62(dst []byte, src []byte) []byte {
89 dst = reserve(dst, stringEncodedLength)
90 n := len(dst)
102:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

base62.go:102:6

101// Any unused bytes in dst will be set to zero.
102func fastDecodeBase62(dst []byte, src []byte) error {
103 const srcBase = 62
148:16redundant-conversionconversion from uint64 to the identical type is redundant

base62.go:148:16

147 quotient := bq[:0]
148 remainder := uint64(0)
149
151:25redundant-conversionconversion from uint64 to the identical type is redundant

base62.go:151:25

150 for _, c := range bp {
151 value := uint64(c) + uint64(remainder)*srcBase
152 digit := value / dstBase
155:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

base62.go:155:7

154
155 if len(quotient) != 0 || digit != 0 {
156 quotient = append(quotient, byte(digit))
164:3modifies-parameterassignment modifies parameter dst

base62.go:164:3

163
164 dst[n-4] = byte(remainder >> 24)
165 dst[n-3] = byte(remainder >> 16)
165:3modifies-parameterassignment modifies parameter dst

base62.go:165:3

164 dst[n-4] = byte(remainder >> 24)
165 dst[n-3] = byte(remainder >> 16)
166 dst[n-2] = byte(remainder >> 8)
166:3modifies-parameterassignment modifies parameter dst

base62.go:166:3

165 dst[n-3] = byte(remainder >> 16)
166 dst[n-2] = byte(remainder >> 8)
167 dst[n-1] = byte(remainder)
167:3modifies-parameterassignment modifies parameter dst

base62.go:167:3

166 dst[n-2] = byte(remainder >> 8)
167 dst[n-1] = byte(remainder)
168 n -= 4
179:2modifies-parameterassignment modifies parameter dst

base62.go:179:2

178func fastAppendDecodeBase62(dst []byte, src []byte) []byte {
179 dst = reserve(dst, byteLength)
180 n := len(dst)
181:2discarded-error-resulterror result returned by fastDecodeBase62 is discarded

base62.go:181:2

180 n := len(dst)
181 fastDecodeBase62(dst[n:n+byteLength], src)
182 return dst[:n+byteLength]
198:3modifies-parameterassignment modifies parameter dst

base62.go:198:3

197 copy(b, dst)
198 dst = b
199 }

base62_test.go22

1:1formatfile is not formatted

base62_test.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt base62_test.go`
10:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:10:6

9
10func TestBase10ToBase62AndBack(t *testing.T) {
11 number := []byte{1, 2, 3, 4}
20:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:20:6

19
20func TestBase256ToBase62AndBack(t *testing.T) {
21 number := []byte{255, 254, 253, 251}
30:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:30:6

29
30func TestEncodeAndDecodeBase62(t *testing.T) {
31 helloWorld := []byte("hello world")
41:20add-constantstring literal " != " appears more than twice; define a constant

base62_test.go:41:20

40 if bytes.Compare(helloWorld, decoded) != 0 {
41 t.Fatal(decoded, " != ", helloWorld)
42 }
45:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:45:6

44
45func TestLexographicOrdering(t *testing.T) {
46 unsortedStrings := make([]string, 256)
65:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:65:6

64
65func TestBase62Value(t *testing.T) {
66 s := base62Characters
79:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:79:6

78
79func TestFastAppendEncodeBase62(t *testing.T) {
80 for i := 0; i != 1000; i++ {
98:6test-parallelismconsider calling t.Parallel() when this test begins

base62_test.go:98:6

97
98func TestFastAppendDecodeBase62(t *testing.T) {
99 for i := 0; i != 1000; i++ {
108:10add-constantstring literal "<<<" appears more than twice; define a constant

base62_test.go:108:10

107 t.Error("bad binary representation of", string(b0))
108 t.Log("<<<", b1)
109 t.Log(">>>", b2)
109:10add-constantstring literal ">>>" appears more than twice; define a constant

base62_test.go:109:10

108 t.Log("<<<", b1)
109 t.Log(">>>", b2)
110 }
169:9ineffective-bitwise-zeroacc/outBase | 0 always equals acc / outBase

base62_test.go:169:9

168 acc := int(bs[i]) + remainder*inBase
169 d := acc/outBase | 0
170 remainder = acc % outBase
172:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

base62_test.go:172:7

171
172 if len(quotient) > 0 || d > 0 {
173 quotient = append(quotient, byte(d))
179:3modifies-parameterassignment modifies parameter dst

base62_test.go:179:3

178 // returned by the function.
179 dst = append(dst, byte(remainder))
180 bs = quotient
193:2modifies-parameterassignment modifies parameter dst

base62_test.go:193:2

192 off := len(dst)
193 dst = appendBase2Base(dst, src, 256, 62)
194 for i, c := range dst[off:] {
195:3modifies-parameterassignment modifies parameter dst

base62_test.go:195:3

194 for i, c := range dst[off:] {
195 dst[off+i] = base62Characters[c]
196 }
209:3modifies-parameterassignment modifies parameter src

base62_test.go:209:3

208 // O(1)... technically. Has better real-world perf than a map
209 src[i] = byte(strings.IndexByte(base62Characters, b))
210 }
226:3modifies-parameterassignment modifies parameter b

base62_test.go:226:3

225 for i < j {
226 b[i], b[j] = b[j], b[i]
227 i++
226:9modifies-parameterassignment modifies parameter b

base62_test.go:226:9

225 for i < j {
226 b[i], b[j] = b[j], b[i]
227 i++
233:5modifies-parameterassignment modifies parameter n

base62_test.go:233:5

232func leftpad(b []byte, c byte, n int) []byte {
233 if n -= len(b); n > 0 {
234 for i := 0; i != n; i++ {
235:4modifies-parameterassignment modifies parameter b

base62_test.go:235:4

234 for i := 0; i != n; i++ {
235 b = append(b, c)
236 }
241:4modifies-parameterassignment modifies parameter b

base62_test.go:241:4

240 for i := 0; i != n; i++ {
241 b[i] = c
242 }

cmd/ksuid/main.go25

1:1formatfile is not formatted

cmd/ksuid/main.go:1:1

1package main
2
  • Fix (safe): run `strider fmt cmd/ksuid/main.go`
1:9package-commentspackage should have a documentation comment

cmd/ksuid/main.go:1:9

1package main
2
18:2no-package-varpackage variables introduce mutable global state

cmd/ksuid/main.go:18:2

17var (
18 count int
19 format string
19:2no-package-varpackage variables introduce mutable global state

cmd/ksuid/main.go:19:2

18 count int
19 format string
20 tpltxt string
20:2no-package-varpackage variables introduce mutable global state

cmd/ksuid/main.go:20:2

19 format string
20 tpltxt string
21 verbose bool
21:2no-package-varpackage variables introduce mutable global state

cmd/ksuid/main.go:21:2

20 tpltxt string
21 verbose bool
22)
24:6no-initreplace init with explicit initialization

cmd/ksuid/main.go:24:6

23
24func init() {
25 flag.IntVar(&count, "n", 1, "Number of KSUIDs to generate when called with no other arguments.")
31:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

cmd/ksuid/main.go:31:6

30
31func main() {
32 flag.Parse()
31:6cyclomatic-complexityfunction complexity is 14; maximum is 10

cmd/ksuid/main.go:31:6

30
31func main() {
32 flag.Parse()
35:6redefines-builtin-ididentifier print shadows a predeclared identifier

cmd/ksuid/main.go:35:6

34
35 var print func(ksuid.KSUID)
36 switch format {
36:2single-case-switchswitch with one case can be replaced by an if statement

cmd/ksuid/main.go:36:2

35 var print func(ksuid.KSUID)
36 switch format {
37 case "string":
52:3discarded-error-resulterror result returned by fmt.Println is discarded

cmd/ksuid/main.go:52:3

51 default:
52 fmt.Println("Bad formatting function:", format)
53 os.Exit(1)
62:6slice-preallocationpreallocate ids with capacity len(range source) before appending once per iteration

cmd/ksuid/main.go:62:6

61
62 var ids []ksuid.KSUID
63 for _, arg := range args {
66:4discarded-error-resulterror result returned by fmt.Printf is discarded

cmd/ksuid/main.go:66:4

65 if err != nil {
66 fmt.Printf("Error when parsing %q: %s\n\n", arg, err)
67 flag.PrintDefaults()
75:4discarded-error-resulterror result returned by fmt.Printf is discarded

cmd/ksuid/main.go:75:4

74 if verbose {
75 fmt.Printf("%s: ", id)
76 }
77:3use-fmt-printuse fmt.Print or fmt.Println instead of the builtin

cmd/ksuid/main.go:77:3

76 }
77 print(id)
78 }
82:2discarded-error-resulterror result returned by fmt.Println is discarded

cmd/ksuid/main.go:82:2

81func printString(id ksuid.KSUID) {
82 fmt.Println(id.String())
83}
99:2discarded-error-resulterror result returned by fmt.Printf is discarded

cmd/ksuid/main.go:99:2

98`
99 fmt.Printf(inspectFormat,
100 id.String(),
109:2discarded-error-resulterror result returned by fmt.Println is discarded

cmd/ksuid/main.go:109:2

108func printTime(id ksuid.KSUID) {
109 fmt.Println(id.Time())
110}
113:2discarded-error-resulterror result returned by fmt.Println is discarded

cmd/ksuid/main.go:113:2

112func printTimestamp(id ksuid.KSUID) {
113 fmt.Println(id.Timestamp())
114}
117:2discarded-error-resulterror result returned by os.Stdout.Write is discarded

cmd/ksuid/main.go:117:2

116func printPayload(id ksuid.KSUID) {
117 os.Stdout.Write(id.Payload())
118}
121:2discarded-error-resulterror result returned by os.Stdout.Write is discarded

cmd/ksuid/main.go:121:2

120func printRaw(id ksuid.KSUID) {
121 os.Stdout.Write(id.Bytes())
122}
127:2discarded-error-resulterror result returned by t.Execute is discarded

cmd/ksuid/main.go:127:2

126 t := template.Must(template.New("").Parse(tpltxt))
127 t.Execute(b, struct {
128 String string
127:15nested-structsmove nested anonymous struct types to named declarations

cmd/ksuid/main.go:127:15

126 t := template.Must(template.New("").Parse(tpltxt))
127 t.Execute(b, struct {
128 String string
141:2discarded-error-resulterror result returned by io.Copy is discarded

cmd/ksuid/main.go:141:2

140 b.WriteByte('\n')
141 io.Copy(os.Stdout, b)
142}

ksuid.go76

1:1formatfile is not formatted

ksuid.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt ksuid.go`
1:9package-commentspackage should have a documentation comment

ksuid.go:1:9

1package ksuid
2
40:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:40:1

39
40// KSUIDs are 20 bytes:
41// 00-03 byte: uint32 BE UTC timestamp with custom epoch
43:6exported-declaration-commentexported type should have a comment beginning with its name

ksuid.go:43:6

42// 04-19 byte: random "payload"
43type KSUID [byteLength]byte
44
45:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

ksuid.go:45:1

44
45var (
46 rander = rand.Reader
46:2no-package-varpackage variables introduce mutable global state

ksuid.go:46:2

45var (
46 rander = rand.Reader
47 randMutex = sync.Mutex{}
47:2no-package-varpackage variables introduce mutable global state

ksuid.go:47:2

46 rander = rand.Reader
47 randMutex = sync.Mutex{}
48 randBuffer = [payloadLengthInBytes]byte{}
48:2no-package-varpackage variables introduce mutable global state

ksuid.go:48:2

47 randMutex = sync.Mutex{}
48 randBuffer = [payloadLengthInBytes]byte{}
49
50:2no-package-varpackage variables introduce mutable global state

ksuid.go:50:2

49
50 errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength)
51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
50:30error-stringserror string should not be capitalized or end with punctuation

ksuid.go:50:30

49
50 errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength)
51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
51:2no-package-varpackage variables introduce mutable global state

ksuid.go:51:2

50 errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength)
51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
51:30error-stringserror string should not be capitalized or end with punctuation

ksuid.go:51:30

50 errSize = fmt.Errorf("Valid KSUIDs are %v bytes", byteLength)
51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
52:2no-package-varpackage variables introduce mutable global state

ksuid.go:52:2

51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
53 errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)
52:30error-stringserror string should not be capitalized or end with punctuation

ksuid.go:52:30

51 errStrSize = fmt.Errorf("Valid encoded KSUIDs are %v characters", stringEncodedLength)
52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
53 errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)
53:2no-package-varpackage variables introduce mutable global state

ksuid.go:53:2

52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
53 errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)
54
53:30error-stringserror string should not be capitalized or end with punctuation

ksuid.go:53:30

52 errStrValue = fmt.Errorf("Valid encoded KSUIDs are bounded by %s and %s", minStringEncoded, maxStringEncoded)
53 errPayloadSize = fmt.Errorf("Valid KSUID payloads are %v bytes", payloadLengthInBytes)
54
55:2doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:55:2

54
55 // Represents a completely empty (invalid) KSUID
56 Nil KSUID
56:2exported-declaration-commentexported declaration should have a comment beginning with its name

ksuid.go:56:2

55 // Represents a completely empty (invalid) KSUID
56 Nil KSUID
57 // Represents the highest value a KSUID can have
56:2no-package-varpackage variables introduce mutable global state

ksuid.go:56:2

55 // Represents a completely empty (invalid) KSUID
56 Nil KSUID
57 // Represents the highest value a KSUID can have
57:2doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:57:2

56 Nil KSUID
57 // Represents the highest value a KSUID can have
58 Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
58:2exported-declaration-commentexported declaration should have a comment beginning with its name

ksuid.go:58:2

57 // Represents the highest value a KSUID can have
58 Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
59)
58:2no-package-varpackage variables introduce mutable global state

ksuid.go:58:2

57 // Represents the highest value a KSUID can have
58 Max = KSUID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
59)
63:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:63:16

62// potentially larger memory area.
63func (i KSUID) Append(b []byte) []byte {
64 return fastAppendEncodeBase62(b, i[:])
67:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:67:1

66
67// The timestamp portion of the ID as a Time object
68func (i KSUID) Time() time.Time {
68:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:68:16

67// The timestamp portion of the ID as a Time object
68func (i KSUID) Time() time.Time {
69 return correctedUTCTimestampToTime(i.Timestamp())
74:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:74:16

73// for KSUID's special epoch.
74func (i KSUID) Timestamp() uint32 {
75 return binary.BigEndian.Uint32(i[:timestampLengthInBytes])
78:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:78:1

77
78// The 16-byte random payload without the timestamp
79func (i KSUID) Payload() []byte {
79:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:79:16

78// The 16-byte random payload without the timestamp
79func (i KSUID) Payload() []byte {
80 return i[timestampLengthInBytes:]
83:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:83:1

82
83// String-encoded representation that can be passed through Parse()
84func (i KSUID) String() string {
88:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:88:1

87
88// Raw byte representation of KSUID
89func (i KSUID) Bytes() []byte {
89:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:89:16

88// Raw byte representation of KSUID
89func (i KSUID) Bytes() []byte {
90 // Safe because this is by-value
94:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:94:1

93
94// IsNil returns true if this is a "nil" KSUID
95func (i KSUID) IsNil() bool {
101:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:101:16

100// part of of the command line options of a program.
101func (i KSUID) Get() interface{} {
102 return i
101:22use-anyuse any instead of interface{}

ksuid.go:101:22

100// part of of the command line options of a program.
101func (i KSUID) Get() interface{} {
102 return i
107:17exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:107:17

106// part of of the command line options of a program.
107func (i *KSUID) Set(s string) error {
108 return i.UnmarshalText([]byte(s))
111:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:111:16

110
111func (i KSUID) MarshalText() ([]byte, error) {
112 return []byte(i.String()), nil
115:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:115:16

114
115func (i KSUID) MarshalBinary() ([]byte, error) {
116 return i.Bytes(), nil
119:7marshal-receivermarshal and unmarshal methods should use a consistent receiver type

ksuid.go:119:7

118
119func (i *KSUID) UnmarshalText(b []byte) error {
120 id, err := Parse(string(b))
119:17exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:119:17

118
119func (i *KSUID) UnmarshalText(b []byte) error {
120 id, err := Parse(string(b))
128:7marshal-receivermarshal and unmarshal methods should use a consistent receiver type

ksuid.go:128:7

127
128func (i *KSUID) UnmarshalBinary(b []byte) error {
129 id, err := FromBytes(b)
128:17exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:128:17

127
128func (i *KSUID) UnmarshalBinary(b []byte) error {
129 id, err := FromBytes(b)
139:16exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:139:16

138// directly use the KSUID as parameter to a SQL query.
139func (i KSUID) Value() (driver.Value, error) {
140 if i.IsNil() {
141:3nil-value-with-nil-errornil payload is returned with a nil error; return a meaningful value or a descriptive error

ksuid.go:141:3

140 if i.IsNil() {
141 return nil, nil
142 }
149:17exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:149:17

148// another type will return an error.
149func (i *KSUID) Scan(src interface{}) error {
150 switch v := src.(type) {
149:26use-anyuse any instead of interface{}

ksuid.go:149:26

148// another type will return an error.
149func (i *KSUID) Scan(src interface{}) error {
150 switch v := src.(type) {
158:21error-stringserror string should not be capitalized or end with punctuation

ksuid.go:158:21

157 default:
158 return fmt.Errorf("Scan: unable to scan type %T into KSUID", v)
159 }
162:17confusing-namingname scan differs from Scan only by capitalization

ksuid.go:162:17

161
162func (i *KSUID) scan(b []byte) error {
163 switch len(b) {
163:2single-case-switchswitch with one case can be replaced by an if statement

ksuid.go:163:2

162func (i *KSUID) scan(b []byte) error {
163 switch len(b) {
164 case 0:
176:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:176:1

175
176// Parse decodes a string-encoded representation of a KSUID object
177func Parse(s string) (KSUID, error) {
196:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:196:6

195// Same behavior as Parse, but returns a Nil KSUID on error.
196func ParseOrNil(s string) KSUID {
197 ksuid, err := Parse(s)
214:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:214:6

213// can't be read, it will panic.
214func New() KSUID {
215 ksuid, err := NewRandom()
222:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:222:1

221
222// Generates a new KSUID
223func NewRandom() (ksuid KSUID, err error) {
223:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:223:6

222// Generates a new KSUID
223func NewRandom() (ksuid KSUID, err error) {
224 return NewRandomWithTime(time.Now())
227:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:227:6

226
227func NewRandomWithTime(t time.Time) (ksuid KSUID, err error) {
228 // Go's default random number generators are not safe for concurrent use by
240:3no-naked-returnreturn values must be explicit

ksuid.go:240:3

239 ksuid = Nil // don't leak random bytes on error
240 return
241 }
245:2no-naked-returnreturn values must be explicit

ksuid.go:245:2

244 binary.BigEndian.PutUint32(ksuid[:timestampLengthInBytes], ts)
245 return
246}
248:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:248:1

247
248// Constructs a KSUID from constituent parts
249func FromParts(t time.Time, payload []byte) (KSUID, error) {
249:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:249:6

248// Constructs a KSUID from constituent parts
249func FromParts(t time.Time, payload []byte) (KSUID, error) {
250 if len(payload) != payloadLengthInBytes {
266:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:266:6

265// Same behavior as FromParts, but returns a Nil KSUID on error.
266func FromPartsOrNil(t time.Time, payload []byte) KSUID {
267 ksuid, err := FromParts(t, payload)
274:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:274:1

273
274// Constructs a KSUID from a 20-byte binary representation
275func FromBytes(b []byte) (KSUID, error) {
275:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:275:6

274// Constructs a KSUID from a 20-byte binary representation
275func FromBytes(b []byte) (KSUID, error) {
276 var ksuid KSUID
288:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:288:6

287// Same behavior as FromBytes, but returns a Nil KSUID on error.
288func FromBytesOrNil(b []byte) KSUID {
289 ksuid, err := FromBytes(b)
300:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:300:6

299// on ordering.
300func SetRand(r io.Reader) {
301 if r == nil {
308:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:308:1

307
308// Implements comparison for KSUID type
309func Compare(a, b KSUID) int {
309:6exported-declaration-commentexported function or method should have a comment beginning with its name

ksuid.go:309:6

308// Implements comparison for KSUID type
309func Compare(a, b KSUID) int {
310 return bytes.Compare(a[:], b[:])
313:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:313:1

312
313// Sorts the given slice of KSUIDs
314func Sort(ids []KSUID) {
318:1doc-comment-perioddocumentation comment should end with punctuation

ksuid.go:318:1

317
318// IsSorted checks whether a slice of KSUIDs is sorted
319func IsSorted(ids []KSUID) bool {
321:3redefines-builtin-ididentifier min shadows a predeclared identifier

ksuid.go:321:3

320 if len(ids) != 0 {
321 min := ids[0]
322 for _, id := range ids[1:] {
332:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

ksuid.go:332:6

331
332func quickSort(a []KSUID, lo int, hi int) {
333 if lo < hi {
340:5modifies-parameterassignment modifies parameter a

ksuid.go:340:5

339 i++
340 a[i], a[j] = a[j], a[i]
341 }
340:11modifies-parameterassignment modifies parameter a

ksuid.go:340:11

339 i++
340 a[i], a[j] = a[j], a[i]
341 }
346:4modifies-parameterassignment modifies parameter a

ksuid.go:346:4

345 if bytes.Compare(a[hi][:], a[i][:]) < 0 {
346 a[i], a[hi] = a[hi], a[i]
347 }
346:10modifies-parameterassignment modifies parameter a

ksuid.go:346:10

345 if bytes.Compare(a[hi][:], a[i][:]) < 0 {
346 a[i], a[hi] = a[hi], a[i]
347 }
355:7receiver-namingreceiver name id is inconsistent with i

ksuid.go:355:7

354// Next returns the next KSUID after id.
355func (id KSUID) Next() KSUID {
356 zero := makeUint128(0, 0)
370:7receiver-namingreceiver name id is inconsistent with i

ksuid.go:370:7

369// Prev returns the previoud KSUID before id.
370func (id KSUID) Prev() KSUID {
371 max := makeUint128(math.MaxUint64, math.MaxUint64)
371:2redefines-builtin-ididentifier max shadows a predeclared identifier

ksuid.go:371:2

370func (id KSUID) Prev() KSUID {
371 max := makeUint128(math.MaxUint64, math.MaxUint64)
372

ksuid_test.go38

1:1formatfile is not formatted

ksuid_test.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt ksuid_test.go`
14:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:14:6

13
14func TestConstructionTimestamp(t *testing.T) {
15 x := New()
19:5time-value-equalitycompare time.Time values with Time.Equal instead of == or !=

ksuid_test.go:19:5

18
19 if xTime != nowTime {
20 t.Fatal(xTime, "!=", nowTime)
24:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:24:6

23
24func TestNil(t *testing.T) {
25 if !Nil.IsNil() {
29:10discarded-error-resulterror result returned by FromBytes is discarded

ksuid_test.go:29:10

28
29 x, _ := FromBytes(make([]byte, byteLength))
30 if !x.IsNil() {
35:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:35:6

34
35func TestEncoding(t *testing.T) {
36 x, _ := FromBytes(make([]byte, byteLength))
36:10discarded-error-resulterror result returned by FromBytes is discarded

ksuid_test.go:36:10

35func TestEncoding(t *testing.T) {
36 x, _ := FromBytes(make([]byte, byteLength))
37 if !x.IsNil() {
49:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:49:6

48
49func TestPadding(t *testing.T) {
50 b := make([]byte, byteLength)
55:10discarded-error-resulterror result returned by FromBytes is discarded

ksuid_test.go:55:10

54
55 x, _ := FromBytes(b)
56 xEncoded := x.String()
64:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:64:6

63
64func TestParse(t *testing.T) {
65 _, err := Parse("123")
92:11add-constantstring literal "Unexpected error" appears more than twice; define a constant

ksuid_test.go:92:11

91 if err != nil {
92 t.Fatal("Unexpected error", err)
93 }
100:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:100:6

99
100func TestIssue25(t *testing.T) {
101 // https://github.com/segmentio/ksuid/issues/25
113:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:113:6

112
113func TestEncodeAndDecode(t *testing.T) {
114 x := New()
125:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:125:6

124
125func TestMarshalText(t *testing.T) {
126 var id1 = New()
144:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:144:6

143
144func TestMarshalBinary(t *testing.T) {
145 var id1 = New()
153:16add-constantstring literal "!=" appears more than twice; define a constant

ksuid_test.go:153:16

152 if id1 != id2 {
153 t.Fatal(id1, "!=", id2)
154 }
163:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:163:6

162
163func TestMashalJSON(t *testing.T) {
164 var id1 = New()
176:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:176:6

175
176func TestFlag(t *testing.T) {
177 var id1 = New()
192:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:192:6

191
192func TestSqlValuer(t *testing.T) {
193 id, _ := Parse(maxStringEncoded)
193:11discarded-error-resulterror result returned by Parse is discarded

ksuid_test.go:193:11

192func TestSqlValuer(t *testing.T) {
193 id, _ := Parse(maxStringEncoded)
194
204:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:204:6

203
204func TestSqlValuerNilValue(t *testing.T) {
205 if v, err := Nil.Value(); err != nil {
212:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:212:6

211
212func TestSqlScanner(t *testing.T) {
213 id1 := New()
216:13nested-structsmove nested anonymous struct types to named declarations

ksuid_test.go:216:13

215
216 tests := []struct {
217 ksuid KSUID
218:9use-anyuse any instead of interface{}

ksuid_test.go:218:9

217 ksuid KSUID
218 value interface{}
219 }{
226:40range-value-captureclosure captures reused range variable test

ksuid_test.go:226:40

225 for _, test := range tests {
226 t.Run(fmt.Sprintf("%T", test.value), func(t *testing.T) {
227 var id KSUID
226:40test-parallelismconsider calling t.Parallel() when this subtest begins

ksuid_test.go:226:40

225 for _, test := range tests {
226 t.Run(fmt.Sprintf("%T", test.value), func(t *testing.T) {
227 var id KSUID
242:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:242:6

241
242func TestAppend(t *testing.T) {
243 for _, repr := range []string{"0pN1Own7255s7jwpwy495bAZeEa", "aWgEPTl1tmebfsQzFP4bxwgy80V"} {
244:11discarded-error-resulterror result returned by Parse is discarded

ksuid_test.go:244:11

243 for _, repr := range []string{"0pN1Own7255s7jwpwy495bAZeEa", "aWgEPTl1tmebfsQzFP4bxwgy80V"} {
244 k, _ := Parse(repr)
245 a := make([]byte, 0, stringEncodedLength)
256:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:256:6

255
256func TestSort(t *testing.T) {
257 ids1 := [11]KSUID{}
265:2use-slices-sortuse slices.Sort or slices.SortFunc when possible

ksuid_test.go:265:2

264 ids2 = ids1
265 sort.Slice(ids2[:], func(i, j int) bool {
266 return Compare(ids2[i], ids2[j]) < 0
282:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:282:6

281
282func TestPrevNext(t *testing.T) {
283 tests := []struct {
283:13nested-structsmove nested anonymous struct types to named declarations

ksuid_test.go:283:13

282func TestPrevNext(t *testing.T) {
283 tests := []struct {
284 id KSUID
301:27range-value-captureclosure captures reused range variable test

ksuid_test.go:301:27

300 for _, test := range tests {
301 t.Run(test.id.String(), func(t *testing.T) {
302 testPrevNext(t, test.id, test.prev, test.next)
301:27test-parallelismconsider calling t.Parallel() when this subtest begins

ksuid_test.go:301:27

300 for _, test := range tests {
301 t.Run(test.id.String(), func(t *testing.T) {
302 testPrevNext(t, test.id, test.prev, test.next)
307:6test-parallelismconsider calling t.Parallel() when this test begins

ksuid_test.go:307:6

306
307func TestGetTimestamp(t *testing.T) {
308 nowTime := time.Now()
309:10discarded-error-resulterror result returned by NewRandomWithTime is discarded

ksuid_test.go:309:10

308 nowTime := time.Now()
309 x, _ := NewRandomWithTime(nowTime)
310 xTime := int64(x.Timestamp())
317:6confusing-namingname testPrevNext differs from TestPrevNext only by capitalization

ksuid_test.go:317:6

316
317func testPrevNext(t *testing.T, id, prev, next KSUID) {
318 id1 := id.Prev()
349:3discarded-error-resulterror result returned by Parse is discarded

ksuid_test.go:349:3

348 for i := 0; i != b.N; i++ {
349 Parse(maxStringEncoded)
350 }

rand.go11

1:1formatfile is not formatted

rand.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt rand.go`
1:9package-commentspackage should have a documentation comment

rand.go:1:9

1package ksuid
2
4:2import-alias-namingimport alias should contain lower-case letters and digits

rand.go:4:2

3import (
4 cryptoRand "crypto/rand"
5 "encoding/binary"
14:5exported-declaration-commentexported declaration should have a comment beginning with its name

rand.go:14:5

13// cryptographically secure KSUIDs and are generating a lot of them.
14var FastRander = newRBG()
15
14:5no-package-varpackage variables introduce mutable global state

rand.go:14:5

13// cryptographically secure KSUIDs and are generating a lot of them.
14var FastRander = newRBG()
15
28:3no-naked-returnreturn values must be explicit

rand.go:28:3

27 if seed, err = readCryptoRandomSeed(); err != nil {
28 return
29 }
31:52unchecked-type-assertionuse the checked two-result form of the type assertion

rand.go:31:52

30
31 r = &randSourceReader{source: rand.NewSource(seed).(rand.Source64)}
32 return
32:2no-naked-returnreturn values must be explicit

rand.go:32:2

31 r = &randSourceReader{source: rand.NewSource(seed).(rand.Source64)}
32 return
33}
39:3no-naked-returnreturn values must be explicit

rand.go:39:3

38 if _, err = io.ReadFull(cryptoRand.Reader, b[:]); err != nil {
39 return
40 }
43:2no-naked-returnreturn values must be explicit

rand.go:43:2

42 seed = int64(binary.LittleEndian.Uint64(b[:]))
43 return
44}
46:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

rand.go:46:1

45
46type randSourceReader struct {
47 source rand.Source64

sequence.go5

1:9package-commentspackage should have a documentation comment

sequence.go:1:9

1package ksuid
2
31:22exported-declaration-commentexported function or method should have a comment beginning with its name

sequence.go:31:22

30// sequence has been exhausted.
31func (seq *Sequence) Next() (KSUID, error) {
32 id := seq.Seed // copy
44:22exported-declaration-commentexported function or method should have a comment beginning with its name

sequence.go:44:22

43// returned min value is equal to the max.
44func (seq *Sequence) Bounds() (min KSUID, max KSUID) {
45 count := seq.count
44:32redefines-builtin-ididentifier min shadows a predeclared identifier

sequence.go:44:32

43// returned min value is equal to the max.
44func (seq *Sequence) Bounds() (min KSUID, max KSUID) {
45 count := seq.count
44:43redefines-builtin-ididentifier max shadows a predeclared identifier

sequence.go:44:43

43// returned min value is equal to the max.
44func (seq *Sequence) Bounds() (min KSUID, max KSUID) {
45 count := seq.count

sequence_test.go7

1:1formatfile is not formatted

sequence_test.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt sequence_test.go`
9:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

sequence_test.go:9:6

8
9func TestSequence(t *testing.T) {
10 seq := Sequence{Seed: New()}
9:6test-parallelismconsider calling t.Parallel() when this test begins

sequence_test.go:9:6

8
9func TestSequence(t *testing.T) {
10 seq := Sequence{Seed: New()}
12:5redefines-builtin-ididentifier min shadows a predeclared identifier

sequence_test.go:12:5

11
12 if min, max := seq.Bounds(); min == max {
13 t.Error("min and max of KSUID range must differ when no ids have been generated")
12:10redefines-builtin-ididentifier max shadows a predeclared identifier

sequence_test.go:12:10

11
12 if min, max := seq.Bounds(); min == max {
13 t.Error("min and max of KSUID range must differ when no ids have been generated")
30:5redefines-builtin-ididentifier min shadows a predeclared identifier

sequence_test.go:30:5

29
30 if min, max := seq.Bounds(); min != max {
31 t.Error("after all KSUIDs were generated the min and max must be equal")
30:10redefines-builtin-ididentifier max shadows a predeclared identifier

sequence_test.go:30:10

29
30 if min, max := seq.Bounds(); min != max {
31 t.Error("after all KSUIDs were generated the min and max must be equal")

set.go28

1:1formatfile is not formatted

set.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt set.go`
1:9package-commentspackage should have a documentation comment

set.go:1:9

1package ksuid
2
30:26exported-declaration-commentexported function or method should have a comment beginning with its name

set.go:30:26

29// the set.
30func (set CompressedSet) GoString() string {
31 b := bytes.Buffer{}
54:6exported-declaration-commentexported function or method should have a comment beginning with its name

set.go:54:6

53// as arguments.
54func Compress(ids ...KSUID) CompressedSet {
55 c := 1 + byteLength + (len(ids) / 5)
67:6cognitive-complexityfunction has cognitive complexity 16; maximum is 7

set.go:67:6

66// to waste.
67func AppendCompressed(set []byte, ids ...KSUID) CompressedSet {
68 if len(ids) != 0 {
67:6exported-declaration-commentexported function or method should have a comment beginning with its name

set.go:67:6

66// to waste.
67func AppendCompressed(set []byte, ids ...KSUID) CompressedSet {
68 if len(ids) != 0 {
76:3modifies-parameterassignment modifies parameter set

set.go:76:3

75 // point for all deltas.
76 set = append(set, byte(rawKSUID))
77 set = append(set, ids[0][:]...)
76:21redundant-conversionconversion from byte to the identical type is redundant

set.go:76:21

75 // point for all deltas.
76 set = append(set, byte(rawKSUID))
77 set = append(set, ids[0][:]...)
77:3modifies-parameterassignment modifies parameter set

set.go:77:3

76 set = append(set, byte(rawKSUID))
77 set = append(set, ids[0][:]...)
78
97:5modifies-parameterassignment modifies parameter set

set.go:97:5

96
97 set = append(set, timeDelta|byte(n))
98 set = appendVarint32(set, d, n)
98:5modifies-parameterassignment modifies parameter set

set.go:98:5

97 set = append(set, timeDelta|byte(n))
98 set = appendVarint32(set, d, n)
99 set = append(set, id[timestampLengthInBytes:]...)
99:5modifies-parameterassignment modifies parameter set

set.go:99:5

98 set = appendVarint32(set, d, n)
99 set = append(set, id[timestampLengthInBytes:]...)
100
108:6modifies-parameterassignment modifies parameter set

set.go:108:6

107
108 set = append(set, payloadDelta|byte(n))
109 set = appendVarint128(set, d, n)
109:6modifies-parameterassignment modifies parameter set

set.go:109:6

108 set = append(set, payloadDelta|byte(n))
109 set = appendVarint128(set, d, n)
110 } else {
115:6modifies-parameterassignment modifies parameter set

set.go:115:6

114
115 set = append(set, payloadRange|byte(n))
116 set = appendVarint64(set, m, n)
116:6modifies-parameterassignment modifies parameter set

set.go:116:6

115 set = append(set, payloadRange|byte(n))
116 set = appendVarint64(set, m, n)
117
131:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

set.go:131:6

130
131func rangeLength(ids []KSUID, timestamp uint32, lastKSUID KSUID, lastValue uint128) (length int, count int) {
132 one := makeUint128(0, 1)
143:4no-naked-returnreturn values must be explicit

set.go:143:4

142 count = i
143 return
144 }
150:4no-naked-returnreturn values must be explicit

set.go:150:4

149 count = i
150 return
151 }
153:3modifies-parameterassignment modifies parameter lastKSUID

set.go:153:3

152
153 lastKSUID = id
154 lastValue = v
154:3modifies-parameterassignment modifies parameter lastValue

set.go:154:3

153 lastKSUID = id
154 lastValue = v
155 length++
159:2no-naked-returnreturn values must be explicit

set.go:159:2

158 count = len(ids)
159 return
160}
205:2single-case-switchswitch with one case can be replaced by an if statement

set.go:205:2

204func varintLength64(v uint64) int {
205 switch {
206 case (v & 0xFFFFFFFFFFFFFF00) == 0:
226:2single-case-switchswitch with one case can be replaced by an if statement

set.go:226:2

225func varintLength32(v uint32) int {
226 switch {
227 case (v & 0xFFFFFF00) == 0:
238:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

set.go:238:1

237
238const (
239 rawKSUID = 0
257:6exported-declaration-commentexported type should have a comment beginning with its name

set.go:257:6

256// goroutines.
257type CompressedSetIter struct {
258 // KSUID is modified by calls to the Next method to hold the KSUID loaded
272:30exported-declaration-commentexported function or method should have a comment beginning with its name

set.go:272:30

271// or false if the iterator as reached the end of the set it was created from.
272func (it *CompressedSetIter) Next() bool {
273 if it.seqlength != 0 {
292:2single-case-switchswitch with one case can be replaced by an if statement

set.go:292:2

291
292 switch tag {
293 case rawKSUID:

set_test.go27

1:1formatfile is not formatted

set_test.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt set_test.go`
8:6test-parallelismconsider calling t.Parallel() when this test begins

set_test.go:8:6

7
8func TestCompressedSet(t *testing.T) {
9 tests := []struct {
9:13nested-structsmove nested anonymous struct types to named declarations

set_test.go:9:13

8func TestCompressedSet(t *testing.T) {
9 tests := []struct {
10 scenario string
61:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:61:12

60func testCompressedSetString(t *testing.T) {
61 id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk")
62 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
62:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:62:12

61 id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk")
62 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
63 id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")
63:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:63:12

62 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
63 id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")
64
73:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:73:12

72func testCompressedSetGoString(t *testing.T) {
73 id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk")
74 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
74:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:74:12

73 id1, _ := Parse("0uHjRkQoL2JKAQIULPdqqb5fOkk")
74 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
75 id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")
75:12discarded-error-resulterror result returned by Parse is discarded

set_test.go:75:12

74 id2, _ := Parse("0uHjRvkOG5CbtoXW5oCEp3L2xBu")
75 id3, _ := Parse("0uHjSJ4Pe5606kT2XWixK6dirlo")
76
84:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

set_test.go:84:6

83
84func testCompressedSetSparse(t *testing.T) {
85 now := time.Now()
94:18discarded-error-resulterror result returned by NewRandomWithTime is discarded

set_test.go:94:18

93 for i := range ksuids {
94 ksuids[i], _ = NewRandomWithTime(times[i%len(times)])
95 }
113:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

set_test.go:113:6

112
113func testCompressedSetPacked(t *testing.T) {
114 sequences := [10]Sequence{}
121:18discarded-error-resulterror result returned by sequences[i%len(sequences)].Next is discarded

set_test.go:121:18

120 for i := range ksuids {
121 ksuids[i], _ = sequences[i%len(sequences)].Next()
122 }
140:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

set_test.go:140:6

139
140func testCompressedSetMixed(t *testing.T) {
141 now := time.Now()
150:14discarded-error-resulterror result returned by NewRandomWithTime is discarded

set_test.go:150:14

149 for i := range sequences {
150 seed, _ := NewRandomWithTime(times[i%len(times)])
151 sequences[i] = Sequence{Seed: seed}
156:18discarded-error-resulterror result returned by sequences[i%len(sequences)].Next is discarded

set_test.go:156:18

155 for i := range ksuids {
156 ksuids[i], _ = sequences[i%len(sequences)].Next()
157 }
163:12add-constantstring literal "too many KSUIDs were produced by the set iterator" appears more than twice; define a constant

set_test.go:163:12

162 if i >= len(ksuids) {
163 t.Error("too many KSUIDs were produced by the set iterator")
164 break
167:13add-constantstring literal "bad KSUID at index %d: expected %s but found %s" appears more than twice; define a constant

set_test.go:167:13

166 if ksuids[i] != it.KSUID {
167 t.Errorf("bad KSUID at index %d: expected %s but found %s", i, ksuids[i], it.KSUID)
168 }
175:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

set_test.go:175:6

174
175func testCompressedSetDuplicates(t *testing.T) {
176 sequence := Sequence{Seed: New()}
180:18discarded-error-resulterror result returned by sequence.Next is discarded

set_test.go:180:18

179 for i := range ksuids[:10] {
180 ksuids[i], _ = sequence.Next() // exercise dedupe on the id range code path
181 }
189:25nested-structsmove nested anonymous struct types to named declarations

set_test.go:189:25

188
189 miss := make(map[KSUID]struct{})
190 uniq := make(map[KSUID]struct{})
190:25nested-structsmove nested anonymous struct types to named declarations

set_test.go:190:25

189 miss := make(map[KSUID]struct{})
190 uniq := make(map[KSUID]struct{})
191
193:14nested-structsmove nested anonymous struct types to named declarations

set_test.go:193:14

192 for _, id := range ksuids {
193 miss[id] = struct{}{}
194 }
202:20nested-structsmove nested anonymous struct types to named declarations

set_test.go:202:20

201 }
202 uniq[it.KSUID] = struct{}{}
203 delete(miss, it.KSUID)
246:15discarded-error-resulterror result returned by seq.Next is discarded

set_test.go:246:15

245 for i := 0; i < 5; i++ {
246 ids[i], _ = seq.Next()
247 }
260:12error-stringserror string should not be capitalized or end with punctuation

set_test.go:260:12

259 if index != 5 {
260 t.Errorf("Expected 5 ids, got %d", index)
261 }
297:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

set_test.go:297:6

296
297func BenchmarkCompressedSet(b *testing.B) {
298 ksuids1 := [1000]KSUID{}

uint128.go7

1:1formatfile is not formatted

uint128.go:1:1

1package ksuid
2
  • Fix (safe): run `strider fmt uint128.go`
1:9package-commentspackage should have a documentation comment

uint128.go:1:9

1package ksuid
2
31:2no-naked-returnreturn values must be explicit

uint128.go:31:2

30 binary.BigEndian.PutUint64(out[12:], v[0]) // low
31 return
32}
37:2no-naked-returnreturn values must be explicit

uint128.go:37:2

36 binary.BigEndian.PutUint64(out[8:], v[0])
37 return
38}
64:2no-naked-returnreturn values must be explicit

uint128.go:64:2

63 z[1], _ = bits.Add64(x[1], y[1], c)
64 return
65}
71:2no-naked-returnreturn values must be explicit

uint128.go:71:2

70 z[1], _ = bits.Sub64(x[1], y[1], b)
71 return
72}
78:2no-naked-returnreturn values must be explicit

uint128.go:78:2

77 z[1] = x[1] + c
78 return
79}

uint128_test.go13

8:6test-parallelismconsider calling t.Parallel() when this test begins

uint128_test.go:8:6

7
8func TestCmp128(t *testing.T) {
9 tests := []struct {
9:13nested-structsmove nested anonymous struct types to named declarations

uint128_test.go:9:13

8func TestCmp128(t *testing.T) {
9 tests := []struct {
10 x uint128
42:55range-value-captureclosure captures reused range variable test

uint128_test.go:42:55

41 for _, test := range tests {
42 t.Run(fmt.Sprintf("cmp128(%s,%s)", test.x, test.y), func(t *testing.T) {
43 if k := cmp128(test.x, test.y); k != test.k {
42:55test-parallelismconsider calling t.Parallel() when this subtest begins

uint128_test.go:42:55

41 for _, test := range tests {
42 t.Run(fmt.Sprintf("cmp128(%s,%s)", test.x, test.y), func(t *testing.T) {
43 if k := cmp128(test.x, test.y); k != test.k {
50:6test-parallelismconsider calling t.Parallel() when this test begins

uint128_test.go:50:6

49
50func TestAdd128(t *testing.T) {
51 tests := []struct {
51:13nested-structsmove nested anonymous struct types to named declarations

uint128_test.go:51:13

50func TestAdd128(t *testing.T) {
51 tests := []struct {
52 x uint128
89:55range-value-captureclosure captures reused range variable test

uint128_test.go:89:55

88 for _, test := range tests {
89 t.Run(fmt.Sprintf("add128(%s,%s)", test.x, test.y), func(t *testing.T) {
90 if z := add128(test.x, test.y); z != test.z {
89:55test-parallelismconsider calling t.Parallel() when this subtest begins

uint128_test.go:89:55

88 for _, test := range tests {
89 t.Run(fmt.Sprintf("add128(%s,%s)", test.x, test.y), func(t *testing.T) {
90 if z := add128(test.x, test.y); z != test.z {
97:6test-parallelismconsider calling t.Parallel() when this test begins

uint128_test.go:97:6

96
97func TestSub128(t *testing.T) {
98 tests := []struct {
98:13nested-structsmove nested anonymous struct types to named declarations

uint128_test.go:98:13

97func TestSub128(t *testing.T) {
98 tests := []struct {
99 x uint128
136:55range-value-captureclosure captures reused range variable test

uint128_test.go:136:55

135 for _, test := range tests {
136 t.Run(fmt.Sprintf("sub128(%s,%s)", test.x, test.y), func(t *testing.T) {
137 if z := sub128(test.x, test.y); z != test.z {
136:55test-parallelismconsider calling t.Parallel() when this subtest begins

uint128_test.go:136:55

135 for _, test := range tests {
136 t.Run(fmt.Sprintf("sub128(%s,%s)", test.x, test.y), func(t *testing.T) {
137 if z := sub128(test.x, test.y); z != test.z {
138:16add-constantstring literal "!=" appears more than twice; define a constant

uint128_test.go:138:16

137 if z := sub128(test.x, test.y); z != test.z {
138 t.Error(z, "!=", test.z)
139 }