32 msformat245 mscheck 536total 244errors 155warnings 137notes

assert_test.go4

1:1formatfile is not formatted

assert_test.go:1:1

1package bigcache
2
  • Fix (safe): run `strider fmt assert_test.go`
12:49use-anyuse any instead of interface{}

assert_test.go:12:49

11
12func assertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
13 if !objectsAreEqual(expected, actual) {
12:76use-anyuse any instead of interface{}

assert_test.go:12:76

11
12func assertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
13 if !objectsAreEqual(expected, actual) {
32:39use-anyuse any instead of interface{}

assert_test.go:32:39

31
32func objectsAreEqual(expected, actual interface{}) bool {
33 if expected == nil || actual == nil {

bigcache.go38

1:1formatfile is not formatted

bigcache.go:1:1

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

bigcache.go:1:9

1package bigcache
2
16:6exported-declaration-commentexported type should have a comment beginning with its name

bigcache.go:16:6

15// therefore entries (de)serialization in front of the cache will be needed in most use cases.
16type BigCache struct {
17 shards []*cacheShard
23:2redefines-builtin-ididentifier close shadows a predeclared identifier

bigcache.go:23:2

22 shardMask uint64
23 close chan struct{}
24}
23:18nested-structsmove nested anonymous struct types to named declarations

bigcache.go:23:18

22 shardMask uint64
23 close chan struct{}
24}
26:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:26:1

25
26// Response will contain metadata about the entry for which GetWithInfo(key) was called
27type Response struct {
34:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

bigcache.go:34:1

33
34const (
35 _ RemoveReason = iota
40:2exported-declaration-commentexported declaration should have a comment beginning with its name

bigcache.go:40:2

39 // entry exceeded the maximum shard size.
40 NoSpace
41 // Deleted means Delete was called and this key was removed as a result.
45:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:45:1

44
45// New initialize new instance of BigCache
46func New(ctx context.Context, config Config) (*BigCache, error) {
50:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:50:1

49
50// NewBigCache initialize new instance of BigCache
51//
55:6exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache.go:55:6

54// shutdown with context cancellations
55func NewBigCache(config Config) (*BigCache, error) {
56 return newBigCache(context.Background(), config, &systemClock{})
59:6cognitive-complexityfunction has cognitive complexity 19; maximum is 7

bigcache.go:59:6

58
59func newBigCache(ctx context.Context, config Config, clock clock) (*BigCache, error) {
60 if !isPowerOfTwo(config.Shards) {
59:6confusing-namingname newBigCache differs from NewBigCache only by capitalization

bigcache.go:59:6

58
59func newBigCache(ctx context.Context, config Config, clock clock) (*BigCache, error) {
60 if !isPowerOfTwo(config.Shards) {
59:6cyclomatic-complexityfunction complexity is 17; maximum is 10

bigcache.go:59:6

58
59func newBigCache(ctx context.Context, config Config, clock clock) (*BigCache, error) {
60 if !isPowerOfTwo(config.Shards) {
61:26error-stringserror string should not be capitalized or end with punctuation

bigcache.go:61:26

60 if !isPowerOfTwo(config.Shards) {
61 return nil, errors.New("Shards number must be power of two") //nolint:staticcheck // keep for backward compatibility
62 }
64:26error-stringserror string should not be capitalized or end with punctuation

bigcache.go:64:26

63 if config.MaxEntrySize < 0 {
64 return nil, errors.New("MaxEntrySize must be >= 0")
65 }
67:26error-stringserror string should not be capitalized or end with punctuation

bigcache.go:67:26

66 if config.MaxEntriesInWindow < 0 {
67 return nil, errors.New("MaxEntriesInWindow must be >= 0")
68 }
70:26error-stringserror string should not be capitalized or end with punctuation

bigcache.go:70:26

69 if config.HardMaxCacheSize < 0 {
70 return nil, errors.New("HardMaxCacheSize must be >= 0")
71 }
75:26error-stringserror string should not be capitalized or end with punctuation

bigcache.go:75:26

74 if config.CleanWindow > 0 && lifeWindowSeconds == 0 {
75 return nil, errors.New("LifeWindow must be >= 1s when CleanWindow is set")
76 }
79:3modifies-parameterassignment modifies parameter config

bigcache.go:79:3

78 if config.Hasher == nil {
79 config.Hasher = newDefaultHasher()
80 }
89:25nested-structsmove nested anonymous struct types to named declarations

bigcache.go:89:25

88 shardMask: uint64(config.Shards - 1),
89 close: make(chan struct{}),
90 }
130:20exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache.go:130:20

129// kept to the cache preventing GC of the entire cache.
130func (c *BigCache) Close() error {
131 close(c.close)
138:20exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache.go:138:20

137// no entry exists for the given key.
138func (c *BigCache) Get(key string) ([]byte, error) {
139 hashedKey := c.hash.Sum64(key)
147:20exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache.go:147:20

146// no entry exists for the given key.
147func (c *BigCache) GetWithInfo(key string) ([]byte, Response, error) {
148 hashedKey := c.hash.Sum64(key)
153:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:153:1

152
153// Set saves entry under the key
154func (c *BigCache) Set(key string, entry []byte) error {
163:20exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache.go:163:20

162// concatenate multiple entries under the same key in a lock-optimized way.
163func (c *BigCache) Append(key string, entry []byte) error {
164 hashedKey := c.hash.Sum64(key)
169:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:169:1

168
169// Delete removes the key
170func (c *BigCache) Delete(key string) error {
176:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:176:1

175
176// Reset empties all cache shards
177func (c *BigCache) Reset() error {
184:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:184:1

183
184// ResetStats resets cache stats
185func (c *BigCache) ResetStats() error {
194:6redefines-builtin-ididentifier len shadows a predeclared identifier

bigcache.go:194:6

193func (c *BigCache) Len() int {
194 var len int
195 for _, shard := range c.shards {
203:6redefines-builtin-ididentifier len shadows a predeclared identifier

bigcache.go:203:6

202func (c *BigCache) Capacity() int {
203 var len int
204 for _, shard := range c.shards {
210:1doc-comment-perioddocumentation comment should end with punctuation

bigcache.go:210:1

209
210// Stats returns cache's statistics
211func (c *BigCache) Stats() Stats {
242:3discarded-error-resulterror result returned by evict is discarded

bigcache.go:242:3

241 if currentTimestamp-oldestTimestamp > c.lifeWindow {
242 evict(Expired)
243 return true
258:58unused-parameterparameter reason is unused

bigcache.go:258:58

257
258func (c *BigCache) providedOnRemove(wrappedEntry []byte, reason RemoveReason) {
259 c.config.OnRemove(readKeyFromEntry(wrappedEntry), readEntry(wrappedEntry))
268:7unused-receiverreceiver c is unused

bigcache.go:268:7

267
268func (c *BigCache) notProvidedOnRemove(wrappedEntry []byte, reason RemoveReason) {
269}
268:40unused-parameterparameter wrappedEntry is unused

bigcache.go:268:40

267
268func (c *BigCache) notProvidedOnRemove(wrappedEntry []byte, reason RemoveReason) {
269}
268:61unused-parameterparameter reason is unused

bigcache.go:268:61

267
268func (c *BigCache) notProvidedOnRemove(wrappedEntry []byte, reason RemoveReason) {
269}
271:70unused-parameterparameter reason is unused

bigcache.go:271:70

270
271func (c *BigCache) providedOnRemoveWithMetadata(wrappedEntry []byte, reason RemoveReason) {
272 key := readKeyFromEntry(wrappedEntry)

bigcache_bench_test.go30

1:1formatfile is not formatted

bigcache_bench_test.go:1:1

1package bigcache
2
  • Fix (safe): run `strider fmt bigcache_bench_test.go`
12:5no-package-varpackage variables introduce mutable global state

bigcache_bench_test.go:12:5

11
12var message = blob('a', 256)
13
20:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:20:14

19 m := blob('a', 1024)
20 cache, _ := New(context.Background(), Config{
21 Shards: 1,
30:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_bench_test.go:30:3

29 for i := 0; i < b.N; i++ {
30 cache.Set(fmt.Sprintf("key-%d", i), m)
31 }
36:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:36:14

35 m := blob('a', 1024)
36 cache, _ := New(context.Background(), Config{
37 Shards: 1,
45:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_bench_test.go:45:3

44 for i := 0; i < b.N; i++ {
45 cache.Set(fmt.Sprintf("key-%d", i), m)
46 }
51:43range-value-captureclosure captures reused range variable shards

bigcache_bench_test.go:51:43

50 for _, shards := range []int{1, 512, 1024, 8192} {
51 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
52 writeToCache(b, shards, 100*time.Second, b.N)
58:43range-value-captureclosure captures reused range variable shards

bigcache_bench_test.go:58:43

57 for _, shards := range []int{1, 512, 1024, 8192} {
58 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
59 appendToCache(b, shards, 100*time.Second, b.N)
66:21add-constantstring literal "%d-shards" appears more than twice; define a constant

bigcache_bench_test.go:66:21

65 for _, shards := range []int{1, 512, 1024, 8192} {
66 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
67 readFromCache(b, shards, false)
66:43range-value-captureclosure captures reused range variable shards

bigcache_bench_test.go:66:43

65 for _, shards := range []int{1, 512, 1024, 8192} {
66 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
67 readFromCache(b, shards, false)
74:43range-value-captureclosure captures reused range variable shards

bigcache_bench_test.go:74:43

73 for _, shards := range []int{1, 512, 1024, 8192} {
74 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
75 readFromCache(b, shards, true)
79:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

bigcache_bench_test.go:79:6

78}
79func BenchmarkIterateOverCache(b *testing.B) {
80
84:43range-value-captureclosure captures reused range variable shards

bigcache_bench_test.go:84:43

83 for _, shards := range []int{512, 1024, 8192} {
84 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
85 cache, _ := New(context.Background(), Config{
85:16discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:85:16

84 b.Run(fmt.Sprintf("%d-shards", shards), func(b *testing.B) {
85 cache, _ := New(context.Background(), Config{
86 Shards: shards,
93:5discarded-error-resulterror result returned by cache.Set is discarded

bigcache_bench_test.go:93:5

92 for i := 0; i < b.N; i++ {
93 cache.Set(fmt.Sprintf("key-%d", i), m)
94 }
93:27add-constantstring literal "key-%d" appears more than twice; define a constant

bigcache_bench_test.go:93:27

92 for i := 0; i < b.N; i++ {
93 cache.Set(fmt.Sprintf("key-%d", i), m)
94 }
104:7discarded-error-resulterror result returned by it.Value is discarded

bigcache_bench_test.go:104:7

103 if it.SetNext() {
104 it.Value()
105 }
125:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:125:14

124func writeToCache(b *testing.B, shards int, lifeWindow time.Duration, requestsInLifeWindow int) {
125 cache, _ := New(context.Background(), Config{
126 Shards: shards,
139:4discarded-error-resulterror result returned by cache.Set is discarded

bigcache_bench_test.go:139:4

138 for pb.Next() {
139 cache.Set(fmt.Sprintf("key-%d-%d", id, counter), message)
140 counter = counter + 1
140:4increment-decrementuse ++ or -- instead of assigning an addition or subtraction of one

bigcache_bench_test.go:140:4

139 cache.Set(fmt.Sprintf("key-%d-%d", id, counter), message)
140 counter = counter + 1
141 }
146:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:146:14

145func appendToCache(b *testing.B, shards int, lifeWindow time.Duration, requestsInLifeWindow int) {
146 cache, _ := New(context.Background(), Config{
147 Shards: shards,
162:5discarded-error-resulterror result returned by cache.Append is discarded

bigcache_bench_test.go:162:5

161 for j := 0; j < 7; j++ {
162 cache.Append(key, message)
163 }
164:4increment-decrementuse ++ or -- instead of assigning an addition or subtraction of one

bigcache_bench_test.go:164:4

163 }
164 counter = counter + 1
165 }
169:46flag-parameterboolean parameter info controls function flow

bigcache_bench_test.go:169:46

168
169func readFromCache(b *testing.B, shards int, info bool) {
170 cache, _ := New(context.Background(), Config{
170:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:170:14

169func readFromCache(b *testing.B, shards int, info bool) {
170 cache, _ := New(context.Background(), Config{
171 Shards: shards,
177:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_bench_test.go:177:3

176 for i := 0; i < b.N; i++ {
177 cache.Set(strconv.Itoa(i), message)
178 }
186:5discarded-error-resulterror result returned by cache.GetWithInfo is discarded

bigcache_bench_test.go:186:5

185 if info {
186 cache.GetWithInfo(strconv.Itoa(rand.Intn(b.N)))
187 } else {
188:5discarded-error-resulterror result returned by cache.Get is discarded

bigcache_bench_test.go:188:5

187 } else {
188 cache.Get(strconv.Itoa(rand.Intn(b.N)))
189 }
195:14discarded-error-resulterror result returned by New is discarded

bigcache_bench_test.go:195:14

194func readFromCacheNonExistentKeys(b *testing.B, shards int) {
195 cache, _ := New(context.Background(), Config{
196 Shards: shards,
207:4discarded-error-resulterror result returned by cache.Get is discarded

bigcache_bench_test.go:207:4

206 for pb.Next() {
207 cache.Get(strconv.Itoa(rand.Intn(b.N)))
208 }

bigcache_test.go183

1:1file-length-limitfile has 1391 lines; maximum is 500

bigcache_test.go:1:1

1package bigcache
2
1:1formatfile is not formatted

bigcache_test.go:1:1

1package bigcache
2
  • Fix (safe): run `strider fmt bigcache_test.go`
20:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:20:14

19 // given
20 cache, _ := New(context.Background(), DefaultConfig(5*time.Second))
21 value := []byte("value")
24:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:24:2

23 // when
24 cache.Set("key", value)
25 cachedValue, err := cache.Get("key")
36:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:36:14

35 // given
36 cache, _ := New(context.Background(), DefaultConfig(5*time.Second))
37 key := "key"
37:9add-constantstring literal "key" appears more than twice; define a constant

bigcache_test.go:37:9

36 cache, _ := New(context.Background(), DefaultConfig(5*time.Second))
37 key := "key"
38 value1 := make([]byte, 50)
39:2discarded-error-resulterror result returned by rand.Read is discarded

bigcache_test.go:39:2

38 value1 := make([]byte, 50)
39 rand.Read(value1)
40 value2 := make([]byte, 50)
41:2discarded-error-resulterror result returned by rand.Read is discarded

bigcache_test.go:41:2

40 value2 := make([]byte, 50)
41 rand.Read(value2)
42 value3 := make([]byte, 50)
43:2discarded-error-resulterror result returned by rand.Read is discarded

bigcache_test.go:43:2

42 value3 := make([]byte, 50)
43 rand.Read(value3)
44
52:2discarded-error-resulterror result returned by cache.Append is discarded

bigcache_test.go:52:2

51 // when
52 cache.Append(key, value1)
53 cachedValue, err := cache.Get(key)
60:2discarded-error-resulterror result returned by cache.Append is discarded

bigcache_test.go:60:2

59 // when
60 cache.Append(key, value2)
61 cachedValue, err = cache.Get(key)
66:24append-to-sized-slicevalue1 already has a positive length; use make with length zero and capacity, or reslice to zero before append

bigcache_test.go:66:24

65 expectedValue := value1
66 expectedValue = append(expectedValue, value2...)
67 assertEqual(t, expectedValue, cachedValue)
70:2discarded-error-resulterror result returned by cache.Append is discarded

bigcache_test.go:70:2

69 // when
70 cache.Append(key, value3)
71 cachedValue, err = cache.Get(key)
82:6cognitive-complexityfunction has cognitive complexity 12; maximum is 7

bigcache_test.go:82:6

81// TestAppendRandomly does simultaneous appends to check for corruption errors.
82func TestAppendRandomly(t *testing.T) {
83 t.Parallel()
128:5discarded-error-resulterror result returned by cache.Append is discarded

bigcache_test.go:128:5

127 }
128 cache.Append(key, []byte(key))
129 }
149:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:149:14

148 // given
149 cache, _ := New(context.Background(), Config{
150 Shards: 1,
155:23redundant-conversionconversion from hashStub to the identical type is redundant

bigcache_test.go:155:23

154 Verbose: true,
155 Hasher: hashStub(5),
156 })
159:2discarded-error-resulterror result returned by cache.Append is discarded

bigcache_test.go:159:2

158 //when
159 cache.Append("a", []byte("1"))
160 cachedValue, err := cache.Get("a")
171:43redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:171:43

170 noError(t, err)
171 assertEqual(t, cache.Stats().Collisions, int64(1))
172 cachedValue, err = cache.Get("b")
182:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:182:14

181 // given
182 cache, _ := New(context.Background(), Config{
183 Shards: 16,
196:23nested-structsmove nested anonymous struct types to named declarations

bigcache_test.go:196:23

195
196 for _, tc := range []struct {
197 cfg Config
217:18range-value-captureclosure captures reused range variable tc

bigcache_test.go:217:18

216 } {
217 t.Run(tc.want, func(t *testing.T) {
218 cache, error := New(context.Background(), tc.cfg)
217:18test-parallelismconsider calling t.Parallel() when this subtest begins

bigcache_test.go:217:18

216 } {
217 t.Run(tc.want, func(t *testing.T) {
218 cache, error := New(context.Background(), tc.cfg)
218:11redefines-builtin-ididentifier error shadows a predeclared identifier

bigcache_test.go:218:11

217 t.Run(tc.want, func(t *testing.T) {
218 cache, error := New(context.Background(), tc.cfg)
219
230:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:230:14

229 // given
230 cache, _ := New(context.Background(), Config{
231 Shards: 16,
249:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:249:14

248 clock := mockedClock{value: 0}
249 cache, _ := newBigCache(context.Background(), Config{
250 Shards: 1,
256:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:256:2

255
256 cache.Set("key", []byte("value"))
257
259:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:259:2

258 // when
259 cache.Set("key2", []byte("value2"))
260 _, err := cache.Get("key")
267:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:267:2

266 clock.set(5)
267 cache.Set("key2", []byte("value2"))
268 _, err = cache.Get("key")
279:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:279:14

278 clock := mockedClock{value: 0}
279 cache, _ := newBigCache(context.Background(), Config{
280 Shards: 4,
287:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:287:2

286 // when
287 cache.Set("key", []byte("value"))
288 clock.set(5)
287:26add-constantstring literal "value" appears more than twice; define a constant

bigcache_test.go:287:26

286 // when
287 cache.Set("key", []byte("value"))
288 clock.set(5)
289:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:289:2

288 clock.set(5)
289 cache.Set("key2", []byte("value 2"))
290 value, err := cache.Get("key")
289:12add-constantstring literal "key2" appears more than twice; define a constant

bigcache_test.go:289:12

288 clock.set(5)
289 cache.Set("key2", []byte("value 2"))
290 value, err := cache.Get("key")
301:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:301:14

300 // given
301 cache, _ := New(context.Background(), Config{
302 Shards: 4,
310:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:310:2

309 // when
310 cache.Set("key", []byte("value"))
311 <-time.After(3 * time.Second)
334:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:334:14

333 }
334 cache, _ := newBigCache(context.Background(), Config{
335 Shards: 1,
344:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:344:2

343 // when
344 cache.Set("key", []byte("value"))
345 clock.set(5)
346:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:346:2

345 clock.set(5)
346 cache.Set("key2", []byte("value2"))
347
346:27add-constantstring literal "value2" appears more than twice; define a constant

bigcache_test.go:346:27

345 clock.set(5)
346 cache.Set("key2", []byte("value2"))
347
363:26redundant-conversionconversion from RemoveReason to the identical type is redundant

bigcache_test.go:363:26

362 assertEqual(t, []byte("value"), entry)
363 assertEqual(t, reason, RemoveReason(Expired))
364 }
365:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:365:14

364 }
365 cache, _ := newBigCache(context.Background(), Config{
366 Shards: 1,
374:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:374:2

373 // when
374 cache.Set("key", []byte("value"))
375 clock.set(5)
376:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:376:2

375 clock.set(5)
376 cache.Set("key2", []byte("value2"))
377
399:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:399:14

398
399 cache, _ := newBigCache(context.Background(), c, &clock)
400
402:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:402:2

401 // when
402 cache.Set("key", []byte("value"))
403 clock.set(5)
404:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:404:2

403 clock.set(5)
404 cache.Set("key2", []byte("value2"))
405
410:2discarded-error-resulterror result returned by cache.Delete is discarded

bigcache_test.go:410:2

409 // and when
410 cache.Delete("key2")
411
416:6test-parallelismconsider calling t.Parallel() when this test begins

bigcache_test.go:416:6

415
416func TestOnRemoveFilterExpired(t *testing.T) {
417 // t.Parallel()
424:3single-case-switchswitch with one case can be replaced by an if statement

bigcache_test.go:424:3

423 onRemove := func(key string, entry []byte, reason RemoveReason) {
424 switch reason {
425
450:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:450:2

449
450 cache.Set("key", []byte("value"))
451 clock.set(5)
466:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:466:2

465
466 cache.Set("key2", []byte("value2"))
467 err = cache.Delete("key2")
482:11redundant-conversionconversion from uint32 to the identical type is redundant

bigcache_test.go:482:11

481 clock := mockedClock{value: 0}
482 count := uint32(0)
483 onRemove := func(key string, entry []byte, keyMetadata Metadata) {
495:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:495:14

494
495 cache, _ := newBigCache(context.Background(), c, &clock)
496
498:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:498:2

497 // when
498 cache.Set("key", []byte("value"))
499
501:3discarded-error-resulterror result returned by cache.Get is discarded

bigcache_test.go:501:3

500 for i := 0; i < 100; i++ {
501 cache.Get("key")
502 }
504:2discarded-error-resulterror result returned by cache.Delete is discarded

bigcache_test.go:504:2

503
504 cache.Delete("key")
505
507:17redundant-conversionconversion from uint32 to the identical type is redundant

bigcache_test.go:507:17

506 // then
507 assertEqual(t, uint32(100), count)
508}
514:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:514:14

513 // given
514 cache, _ := New(context.Background(), Config{
515 Shards: 8,
524:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:524:3

523 for i := 0; i < keys; i++ {
524 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
525 }
524:25add-constantstring literal "key%d" appears more than twice; define a constant

bigcache_test.go:524:25

523 for i := 0; i < keys; i++ {
524 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
525 }
535:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:535:14

534 // given
535 cache, _ := New(context.Background(), Config{
536 Shards: 8,
545:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:545:3

544 for i := 0; i < keys; i++ {
545 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
546 }
557:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:557:14

556 // given
557 cache, _ := New(context.Background(), Config{
558 Shards: 1,
572:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:572:3

571 for i := 0; i < keys; i++ {
572 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
573 }
584:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:584:14

583 // given
584 cache, _ := New(context.Background(), Config{
585 Shards: 1,
595:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:595:2

594 // when
595 cache.Set("key", value)
596 cache.Set("key", value)
596:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:596:2

595 cache.Set("key", value)
596 cache.Set("key", value)
597 cache.Set("key", value)
597:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:597:2

596 cache.Set("key", value)
597 cache.Set("key", value)
598 cache.Set("key", value)
598:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:598:2

597 cache.Set("key", value)
598 cache.Set("key", value)
599 cache.Set("key", value)
599:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:599:2

598 cache.Set("key", value)
599 cache.Set("key", value)
600 cachedValue, err := cache.Get("key")
611:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:611:14

610 // given
611 cache, _ := New(context.Background(), Config{
612 Shards: 8,
620:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:620:3

619 for i := 0; i < 100; i++ {
620 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
621 }
643:29redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:643:29

642 stats := cache.Stats()
643 assertEqual(t, stats.Hits, int64(10))
644 assertEqual(t, stats.Misses, int64(10))
644:31redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:644:31

643 assertEqual(t, stats.Hits, int64(10))
644 assertEqual(t, stats.Misses, int64(10))
645 assertEqual(t, stats.DelHits, int64(10))
645:32redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:645:32

644 assertEqual(t, stats.Misses, int64(10))
645 assertEqual(t, stats.DelHits, int64(10))
646 assertEqual(t, stats.DelMisses, int64(10))
646:34redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:646:34

645 assertEqual(t, stats.DelHits, int64(10))
646 assertEqual(t, stats.DelMisses, int64(10))
647}
652:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:652:14

651 // given
652 cache, _ := New(context.Background(), Config{
653 Shards: 8,
660:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:660:2

659
660 cache.Set("key0", []byte("value"))
661
668:35add-constantstring literal "key0" appears more than twice; define a constant

bigcache_test.go:668:35

667 // then
668 keyMetadata := cache.KeyMetadata("key0")
669 assertEqual(t, uint32(10), keyMetadata.RequestCount)
669:17redundant-conversionconversion from uint32 to the identical type is redundant

bigcache_test.go:669:17

668 keyMetadata := cache.KeyMetadata("key0")
669 assertEqual(t, uint32(10), keyMetadata.RequestCount)
670}
676:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:676:14

675 // given
676 cache, _ := New(context.Background(), Config{
677 Shards: 8,
685:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:685:3

684 for i := 0; i < 100; i++ {
685 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
686 }
707:29redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:707:29

706 stats := cache.Stats()
707 assertEqual(t, stats.Hits, int64(10))
708 assertEqual(t, stats.Misses, int64(10))
708:31redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:708:31

707 assertEqual(t, stats.Hits, int64(10))
708 assertEqual(t, stats.Misses, int64(10))
709 assertEqual(t, stats.DelHits, int64(10))
709:32redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:709:32

708 assertEqual(t, stats.Misses, int64(10))
709 assertEqual(t, stats.DelHits, int64(10))
710 assertEqual(t, stats.DelMisses, int64(10))
710:34redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:710:34

709 assertEqual(t, stats.DelHits, int64(10))
710 assertEqual(t, stats.DelMisses, int64(10))
711
713:2discarded-error-resulterror result returned by cache.ResetStats is discarded

bigcache_test.go:713:2

712 //then
713 cache.ResetStats()
714 stats = cache.Stats()
715:29redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:715:29

714 stats = cache.Stats()
715 assertEqual(t, stats.Hits, int64(0))
716 assertEqual(t, stats.Misses, int64(0))
716:31redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:716:31

715 assertEqual(t, stats.Hits, int64(0))
716 assertEqual(t, stats.Misses, int64(0))
717 assertEqual(t, stats.DelHits, int64(0))
717:32redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:717:32

716 assertEqual(t, stats.Misses, int64(0))
717 assertEqual(t, stats.DelHits, int64(0))
718 assertEqual(t, stats.DelMisses, int64(0))
718:34redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:718:34

717 assertEqual(t, stats.DelHits, int64(0))
718 assertEqual(t, stats.DelMisses, int64(0))
719}
725:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:725:14

724 // given
725 cache, _ := New(context.Background(), DefaultConfig(time.Second))
726
734:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:734:2

733 // and when
734 cache.Set("existingKey", nil)
735 err = cache.Delete("existingKey")
736:20discarded-error-resulterror result returned by cache.Get is discarded

bigcache_test.go:736:20

735 err = cache.Delete("existingKey")
736 cachedValue, _ := cache.Get("existingKey")
737
736:30add-constantstring literal "existingKey" appears more than twice; define a constant

bigcache_test.go:736:30

735 err = cache.Delete("existingKey")
736 cachedValue, _ := cache.Get("existingKey")
737
744:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

bigcache_test.go:744:6

743// TestCacheDelRandomly does simultaneous deletes, puts and gets, to check for corruption errors.
744func TestCacheDelRandomly(t *testing.T) {
745 t.Parallel()
760:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:760:14

759
760 cache, _ := New(context.Background(), c)
761 var wg sync.WaitGroup
769:4discarded-error-resulterror result returned by cache.Delete is discarded

bigcache_test.go:769:4

768
769 cache.Delete(key)
770 }
783:4discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:783:4

782 }
783 cache.Set(key, val)
784 }
791:23add-constantstring literal "thekey%d" appears more than twice; define a constant

bigcache_test.go:791:23

790 r := byte(rand.Int())
791 key := fmt.Sprintf("thekey%d", r)
792
811:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:811:14

810
811 cache, _ := New(context.Background(), c)
812 var wg sync.WaitGroup
842:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:842:14

841 // given
842 cache, _ := New(context.Background(), Config{
843 Shards: 8,
852:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:852:3

851 for i := 0; i < keys; i++ {
852 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
853 }
859:2discarded-error-resulterror result returned by cache.Reset is discarded

bigcache_test.go:859:2

858 // and when
859 cache.Reset()
860
866:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:866:3

865 for i := 0; i < keys; i++ {
866 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
867 }
877:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:877:14

876 // given
877 cache, _ := New(context.Background(), Config{
878 Shards: 8,
887:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:887:3

886 for i := 0; i < keys; i++ {
887 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
888 }
889:2discarded-error-resulterror result returned by cache.Reset is discarded

bigcache_test.go:889:2

888 }
889 cache.Reset()
890
901:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:901:14

900 // given
901 cache, _ := New(context.Background(), Config{
902 Shards: 8,
911:3discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:911:3

910 for i := 0; i < keys; i++ {
911 cache.Set(fmt.Sprintf("key%d", i), []byte("value"))
912 }
914:2discarded-error-resulterror result returned by cache.Reset is discarded

bigcache_test.go:914:2

913
914 cache.Reset()
915
928:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:928:14

927 clock := mockedClock{value: 0}
928 cache, _ := newBigCache(context.Background(), Config{
929 Shards: 1,
936:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:936:2

935 // when
936 cache.Set("key", []byte("value"))
937 clock.set(5)
938:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:938:2

937 clock.set(5)
938 cache.Set("key", []byte("value2"))
939 clock.set(7)
940:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:940:2

939 clock.set(7)
940 cache.Set("key2", []byte("value3"))
941 cachedValue, _ := cache.Get("key")
941:20discarded-error-resulterror result returned by cache.Get is discarded

bigcache_test.go:941:20

940 cache.Set("key2", []byte("value3"))
941 cachedValue, _ := cache.Get("key")
942
951:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:951:14

950 // given
951 cache, _ := New(context.Background(), Config{
952 Shards: 1,
960:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:960:2

959 // when
960 cache.Set("key1", blob('a', 1024*400))
961 cache.Set("key2", blob('b', 1024*400))
961:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:961:2

960 cache.Set("key1", blob('a', 1024*400))
961 cache.Set("key2", blob('b', 1024*400))
962 cache.Set("key3", blob('c', 1024*800))
962:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:962:2

961 cache.Set("key2", blob('b', 1024*400))
962 cache.Set("key3", blob('c', 1024*800))
963
964:26add-constantstring literal "key1" appears more than twice; define a constant

bigcache_test.go:964:26

963
964 _, key1Err := cache.Get("key1")
965 _, key2Err := cache.Get("key2")
966:15discarded-error-resulterror result returned by cache.Get is discarded

bigcache_test.go:966:15

965 _, key2Err := cache.Get("key2")
966 entry3, _ := cache.Get("key3")
967
978:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:978:14

977 // given
978 cache, _ := New(context.Background(), Config{
979 Shards: 1,
985:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:985:2

984 })
985 cache.Set("key1", blob('a', 1024*400))
986 value, key1Err := cache.Get("key1")
990:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:990:2

989 // override queue
990 cache.Set("key2", blob('b', 1024*400))
991 cache.Set("key3", blob('c', 1024*400))
991:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:991:2

990 cache.Set("key2", blob('b', 1024*400))
991 cache.Set("key3", blob('c', 1024*400))
992 cache.Set("key4", blob('d', 1024*400))
991:12add-constantstring literal "key3" appears more than twice; define a constant

bigcache_test.go:991:12

990 cache.Set("key2", blob('b', 1024*400))
991 cache.Set("key3", blob('c', 1024*400))
992 cache.Set("key4", blob('d', 1024*400))
992:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:992:2

991 cache.Set("key3", blob('c', 1024*400))
992 cache.Set("key4", blob('d', 1024*400))
993 cache.Set("key5", blob('d', 1024*400))
993:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:993:2

992 cache.Set("key4", blob('d', 1024*400))
993 cache.Set("key5", blob('d', 1024*400))
994
1004:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1004:14

1003 // given
1004 cache, _ := New(context.Background(), Config{
1005 Shards: 1,
1024:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1024:14

1023 // given
1024 cache, _ := New(context.Background(), Config{
1025 Shards: 16,
1030:23redundant-conversionconversion from hashStub to the identical type is redundant

bigcache_test.go:1030:23

1029 Verbose: true,
1030 Hasher: hashStub(5),
1031 Logger: ml,
1035:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1035:2

1034 // when
1035 cache.Set("liquid", []byte("value"))
1036 cachedValue, err := cache.Get("liquid")
1043:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1043:2

1042 // when
1043 cache.Set("costarring", []byte("value 2"))
1044 cachedValue, err = cache.Get("costarring")
1048:24add-constantstring literal "value 2" appears more than twice; define a constant

bigcache_test.go:1048:24

1047 noError(t, err)
1048 assertEqual(t, []byte("value 2"), cachedValue)
1049
1051:31add-constantstring literal "liquid" appears more than twice; define a constant

bigcache_test.go:1051:31

1050 // when
1051 cachedValue, err = cache.Get("liquid")
1052
1058:43redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:1058:43

1057 assertEqual(t, "Collision detected. Both %q and %q have the same hash %x", ml.lastFormat)
1058 assertEqual(t, cache.Stats().Collisions, int64(1))
1059}
1065:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1065:14

1064 // given
1065 cache, _ := New(context.Background(), Config{
1066 Shards: 1,
1074:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1074:2

1073 // when
1074 cache.Set("Kierkegaard", []byte{})
1075 cachedValue, err := cache.Get("Kierkegaard")
1082:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1082:2

1081 // when
1082 cache.Set("Sartre", nil)
1083 cachedValue, err = cache.Get("Sartre")
1090:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1090:2

1089 // when
1090 cache.Set("Nietzsche", []byte(nil))
1091 cachedValue, err = cache.Get("Nietzsche")
1098:6test-parallelismconsider calling t.Parallel() when this test begins

bigcache_test.go:1098:6

1097
1098func TestClosing(t *testing.T) {
1099 // given
1109:15discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1109:15

1108 for i := 0; i < 100; i++ {
1109 cache, _ := New(context.Background(), config)
1110 cache.Close()
1110:3discarded-error-resulterror result returned by cache.Close is discarded

bigcache_test.go:1110:3

1109 cache, _ := New(context.Background(), config)
1110 cache.Close()
1111 }
1127:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:1127:14

1126 clock := mockedClock{value: 0}
1127 cache, _ := newBigCache(context.Background(), Config{
1128 Shards: 1,
1138:35redundant-conversionconversion from RemoveReason to the identical type is redundant

bigcache_test.go:1138:35

1137 assertEqual(t, ErrEntryNotFound, err)
1138 assertEqual(t, resp.EntryStatus, RemoveReason(0))
1139 assertEqual(t, cache.Stats().Misses, int64(1))
1139:39redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:1139:39

1138 assertEqual(t, resp.EntryStatus, RemoveReason(0))
1139 assertEqual(t, cache.Stats().Misses, int64(1))
1140 assertEqual(t, []byte(nil), value)
1148:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:1148:14

1147 clock := mockedClock{value: 0}
1148 cache, _ := newBigCache(context.Background(), Config{
1149 Shards: 1,
1159:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1159:2

1158 value := "100"
1159 cache.Set(key, []byte(value))
1160
1161:23nested-structsmove nested anonymous struct types to named declarations

bigcache_test.go:1161:23

1160
1161 for _, tc := range []struct {
1162 name string
1192:18range-value-captureclosure captures reused range variable tc

bigcache_test.go:1192:18

1191 } {
1192 t.Run(tc.name, func(t *testing.T) {
1193 clock.set(tc.clock)
1192:18test-parallelismconsider calling t.Parallel() when this subtest begins

bigcache_test.go:1192:18

1191 } {
1192 t.Run(tc.name, func(t *testing.T) {
1193 clock.set(tc.clock)
1207:14discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1207:14

1206 // given
1207 cache, _ := New(context.Background(), Config{
1208 Shards: 1,
1213:23redundant-conversionconversion from hashStub to the identical type is redundant

bigcache_test.go:1213:23

1212 Verbose: true,
1213 Hasher: hashStub(5),
1214 })
1217:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1217:2

1216 //when
1217 cache.Set("a", []byte("1"))
1218 cachedValue, resp, err := cache.GetWithInfo("a")
1217:12add-constantstring literal "a" appears more than twice; define a constant

bigcache_test.go:1217:12

1216 //when
1217 cache.Set("a", []byte("1"))
1218 cachedValue, resp, err := cache.GetWithInfo("a")
1217:24add-constantstring literal "1" appears more than twice; define a constant

bigcache_test.go:1217:24

1216 //when
1217 cache.Set("a", []byte("1"))
1218 cachedValue, resp, err := cache.GetWithInfo("a")
1226:45add-constantstring literal "b" appears more than twice; define a constant

bigcache_test.go:1226:45

1225 // when
1226 cachedValue, resp, err = cache.GetWithInfo("b")
1227
1232:43redundant-conversionconversion from int64 to the identical type is redundant

bigcache_test.go:1232:43

1231 assertEqual(t, ErrEntryNotFound, err)
1232 assertEqual(t, cache.Stats().Collisions, int64(1))
1233
1236:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

bigcache_test.go:1236:1

1235
1236type mockedLogger struct {
1237 lastFormat string
1238:15use-anyuse any instead of interface{}

bigcache_test.go:1238:15

1237 lastFormat string
1238 lastArgs []interface{}
1239}
1241:25exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache_test.go:1241:25

1240
1241func (ml *mockedLogger) Printf(format string, v ...interface{}) {
1242 ml.lastFormat = format
1241:52use-anyuse any instead of interface{}

bigcache_test.go:1241:52

1240
1241func (ml *mockedLogger) Printf(format string, v ...interface{}) {
1242 ml.lastFormat = format
1250:24exported-declaration-commentexported function or method should have a comment beginning with its name

bigcache_test.go:1250:24

1249
1250func (mc *mockedClock) Epoch() int64 {
1251 return mc.value
1258:22redefines-builtin-ididentifier len shadows a predeclared identifier

bigcache_test.go:1258:22

1257
1258func blob(char byte, len int) []byte {
1259 return bytes.Repeat([]byte{char}, len)
1262:6test-parallelismconsider calling t.Parallel() when this test begins

bigcache_test.go:1262:6

1261
1262func TestCache_SetWithoutCleanWindow(t *testing.T) {
1263
1267:11discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1267:11

1266 opt.HardMaxCacheSize = 1
1267 bc, _ := New(context.Background(), opt)
1268
1276:6test-parallelismconsider calling t.Parallel() when this test begins

bigcache_test.go:1276:6

1275
1276func TestCache_RepeatedSetWithBiggerEntry(t *testing.T) {
1277
1283:11discarded-error-resulterror result returned by New is discarded

bigcache_test.go:1283:11

1282 opt.HardMaxCacheSize = 1
1283 bc, _ := New(context.Background(), opt)
1284
1308:15add-constantstring literal "8573" appears more than twice; define a constant

bigcache_test.go:1308:15

1307
1308 err = bc.Set("8573", make([]byte, 200))
1309 if nil != err {
1316:1doc-comment-perioddocumentation comment should end with punctuation

bigcache_test.go:1316:1

1315
1316// TestBigCache_allocateAdditionalMemoryLeadPanic
1317// The new commit 16df11e change the encoding method,it can fix issue #300
1321:14discarded-error-resulterror result returned by newBigCache is discarded

bigcache_test.go:1321:14

1320 clock := mockedClock{value: 0}
1321 cache, _ := newBigCache(context.Background(), Config{
1322 Shards: 1,
1328:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1328:2

1327 clock.set(ts)
1328 cache.Set("a", blob(0xff, 235))
1329 ts += 2
1331:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1331:2

1330 clock.set(ts)
1331 cache.Set("b", blob(0xff, 235))
1332 // expire the key "a"
1336:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1336:2

1335 // move tail to leftMargin,insert before head
1336 cache.Set("c", blob(0xff, 108))
1337 // reallocate memory,fill the tail to head with zero byte,move head to leftMargin
1338:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1338:2

1337 // reallocate memory,fill the tail to head with zero byte,move head to leftMargin
1338 cache.Set("d", blob(0xff, 1024))
1339 ts += 4
1342:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1342:2

1341 // expire the key "c"
1342 cache.Set("e", blob(0xff, 3))
1343 // expire the zero bytes
1344:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1344:2

1343 // expire the zero bytes
1344 cache.Set("f", blob(0xff, 3))
1345 // expire the key "b"
1346:2discarded-error-resulterror result returned by cache.Set is discarded

bigcache_test.go:1346:2

1345 // expire the key "b"
1346 cache.Set("g", blob(0xff, 3))
1347 _, err := cache.Get("b")
1349:13discarded-error-resulterror result returned by cache.Get is discarded

bigcache_test.go:1349:13

1348 assertEqual(t, err, ErrEntryNotFound)
1349 data, _ := cache.Get("g")
1350 assertEqual(t, []byte{0xff, 0xff, 0xff}, data)
1353:6test-parallelismconsider calling t.Parallel() when this test begins

bigcache_test.go:1353:6

1352
1353func TestRemoveNonExpiredData(t *testing.T) {
1354 onRemove := func(key string, entry []byte, reason RemoveReason) {
1357:14error-stringserror string should not be capitalized or end with punctuation

bigcache_test.go:1357:14

1356 if reason == Expired {
1357 t.Errorf("[%d]Expired OnRemove [%s]\n", reason, key)
1358 t.FailNow()

bytes.go3

1:1formatfile is not formatted

bytes.go:1:1

1//go:build !appengine
2// +build !appengine
  • Fix (safe): run `strider fmt bytes.go`
2:1redundant-build-taglegacy +build line is redundant with go:build

bytes.go:2:1

1//go:build !appengine
2// +build !appengine
3
4:9package-commentspackage should have a documentation comment

bytes.go:4:9

3
4package bigcache
5

bytes_appengine.go1

3:9package-commentspackage should have a documentation comment

bytes_appengine.go:3:9

2
3package bigcache
4

clock.go4

1:1formatfile is not formatted

clock.go:1:1

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

clock.go:1:9

1package bigcache
2
12:7unused-receiverreceiver c is unused

clock.go:12:7

11
12func (c systemClock) Epoch() int64 {
13 return time.Now().Unix()
12:22exported-declaration-commentexported function or method should have a comment beginning with its name

clock.go:12:22

11
12func (c systemClock) Epoch() int64 {
13 return time.Now().Unix()

config.go6

1:9package-commentspackage should have a documentation comment

config.go:1:9

1package bigcache
2
5:1doc-comment-perioddocumentation comment should end with punctuation

config.go:5:1

4
5// Config for BigCache
6type Config struct {
57:6exported-declaration-commentexported function or method should have a comment beginning with its name

config.go:57:6

56// When load for BigCache can be predicted in advance then it is better to use custom config.
57func DefaultConfig(eviction time.Duration) Config {
58 return Config{
90:17exported-declaration-commentexported function or method should have a comment beginning with its name

config.go:90:17

89// Filtering out reasons prevents bigcache from unwrapping them, which saves cpu.
90func (c Config) OnRemoveFilterSet(reasons ...RemoveReason) Config {
91 c.onRemoveFilter = 0
91:2modifies-value-receiverassignment modifies value receiver c

config.go:91:2

90func (c Config) OnRemoveFilterSet(reasons ...RemoveReason) Config {
91 c.onRemoveFilter = 0
92 for i := range reasons {
93:3modifies-value-receiverassignment modifies value receiver c

config.go:93:3

92 for i := range reasons {
93 c.onRemoveFilter |= 1 << uint(reasons[i])
94 }

encoding.go4

1:1formatfile is not formatted

encoding.go:1:1

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

encoding.go:1:9

1package bigcache
2
19:3modifies-parameterassignment modifies parameter buffer

encoding.go:19:3

18 if blobLength > len(*buffer) {
19 *buffer = make([]byte, blobLength)
20 }
35:3modifies-parameterassignment modifies parameter buffer

encoding.go:35:3

34 if blobLength > len(*buffer) {
35 *buffer = make([]byte, blobLength)
36 }

encoding_test.go5

1:1formatfile is not formatted

encoding_test.go:1:1

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

encoding_test.go:8:6

7
8func TestEncodeDecode(t *testing.T) {
9 // given
11:10redundant-conversionconversion from uint64 to the identical type is redundant

encoding_test.go:11:10

10 now := uint64(time.Now().Unix())
11 hash := uint64(42)
12 key := "key"
27:6test-parallelismconsider calling t.Parallel() when this test begins

encoding_test.go:27:6

26
27func TestAllocateBiggerBuffer(t *testing.T) {
28 //given
30:10redundant-conversionconversion from uint64 to the identical type is redundant

encoding_test.go:30:10

29 now := uint64(time.Now().Unix())
30 hash := uint64(42)
31 key := "1"

entry_not_found_error.go4

1:9package-commentspackage should have a documentation comment

entry_not_found_error.go:1:9

1package bigcache
2
6:2doc-comment-perioddocumentation comment should end with punctuation

entry_not_found_error.go:6:2

5var (
6 // ErrEntryNotFound is an error type struct which is returned when entry was not found for provided key
7 ErrEntryNotFound = errors.New("Entry not found") //nolint:staticcheck // keep for backward compatibility
7:2no-package-varpackage variables introduce mutable global state

entry_not_found_error.go:7:2

6 // ErrEntryNotFound is an error type struct which is returned when entry was not found for provided key
7 ErrEntryNotFound = errors.New("Entry not found") //nolint:staticcheck // keep for backward compatibility
8)
7:32error-stringserror string should not be capitalized or end with punctuation

entry_not_found_error.go:7:32

6 // ErrEntryNotFound is an error type struct which is returned when entry was not found for provided key
7 ErrEntryNotFound = errors.New("Entry not found") //nolint:staticcheck // keep for backward compatibility
8)

examples_test.go9

13:14discarded-error-resulterror result returned by bigcache.New is discarded

examples_test.go:13:14

12func Example() {
13 cache, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(10*time.Minute))
14
15:2discarded-error-resulterror result returned by cache.Set is discarded

examples_test.go:15:2

14
15 cache.Set("my-unique-key", []byte("value"))
16
17:14discarded-error-resulterror result returned by cache.Get is discarded

examples_test.go:17:14

16
17 entry, _ := cache.Get("my-unique-key")
18 fmt.Println(string(entry))
18:2discarded-error-resulterror result returned by fmt.Println is discarded

examples_test.go:18:2

17 entry, _ := cache.Get("my-unique-key")
18 fmt.Println(string(entry))
19 // Output: value
65:3deep-exitprocess-exit calls should be confined to main or init

examples_test.go:65:3

64 if initErr != nil {
65 log.Fatal(initErr)
66 }
68:19add-constantstring literal "my-unique-key" appears more than twice; define a constant

examples_test.go:68:19

67
68 err := cache.Set("my-unique-key", []byte("value"))
69 if err != nil {
70:3deep-exitprocess-exit calls should be confined to main or init

examples_test.go:70:3

69 if err != nil {
70 log.Fatal(err)
71 }
75:3deep-exitprocess-exit calls should be confined to main or init

examples_test.go:75:3

74 if err != nil {
75 log.Fatal(err)
76 }
77:2discarded-error-resulterror result returned by fmt.Println is discarded

examples_test.go:77:2

76 }
77 fmt.Println(string(entry))
78 // Output: value

fnv.go4

1:1formatfile is not formatted

fnv.go:1:1

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

fnv.go:1:9

1package bigcache
2
10:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

fnv.go:10:1

9
10type fnv64a struct{}
11
20:7unused-receiverreceiver f is unused

fnv.go:20:7

19// Sum64 gets the string and returns its uint64 hash value.
20func (f fnv64a) Sum64(key string) uint64 {
21 var hash uint64 = offset64

fnv_bench_test.go1

5:5no-package-varpackage variables introduce mutable global state

fnv_bench_test.go:5:5

4
5var text = "abcdefg"
6

fnv_test.go4

1:1formatfile is not formatted

fnv_test.go:1:1

1package bigcache
2
  • Fix (safe): run `strider fmt fnv_test.go`
13:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

fnv_test.go:13:1

12
13var testCases = []testCase{
14 {"", stdLibFnvSum64("")},
13:5no-package-varpackage variables introduce mutable global state

fnv_test.go:13:5

12
13var testCases = []testCase{
14 {"", stdLibFnvSum64("")},
21:6test-parallelismconsider calling t.Parallel() when this test begins

fnv_test.go:21:6

20
21func TestFnvHashSum64(t *testing.T) {
22 h := newDefaultHasher()

hash.go2

1:9package-commentspackage should have a documentation comment

hash.go:1:9

1package bigcache
2
6:6exported-declaration-commentexported type should have a comment beginning with its name

hash.go:6:6

5// you can use FarmHash family).
6type Hasher interface {
7 Sum64(string) uint64

hash_test.go1

5:22exported-declaration-commentexported function or method should have a comment beginning with its name

hash_test.go:5:22

4
5func (stub hashStub) Sum64(_ string) uint64 {
6 return uint64(stub)

iterator.go20

1:1formatfile is not formatted

iterator.go:1:1

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

iterator.go:1:9

1package bigcache
2
13:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:13:1

12
13// ErrInvalidIteratorState is reported when iterator is in invalid state
14const ErrInvalidIteratorState = iteratorError("Iterator is in invalid state. Use SetNext() to move to next position")
14:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

iterator.go:14:1

13// ErrInvalidIteratorState is reported when iterator is in invalid state
14const ErrInvalidIteratorState = iteratorError("Iterator is in invalid state. Use SetNext() to move to next position")
15
14:33redundant-conversionconversion from iteratorError to the identical type is redundant

iterator.go:14:33

13// ErrInvalidIteratorState is reported when iterator is in invalid state
14const ErrInvalidIteratorState = iteratorError("Iterator is in invalid state. Use SetNext() to move to next position")
15
16:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:16:1

15
16// ErrCannotRetrieveEntry is reported when entry cannot be retrieved from underlying
17const ErrCannotRetrieveEntry = iteratorError("Could not retrieve entry from cache")
17:32redundant-conversionconversion from iteratorError to the identical type is redundant

iterator.go:17:32

16// ErrCannotRetrieveEntry is reported when entry cannot be retrieved from underlying
17const ErrCannotRetrieveEntry = iteratorError("Could not retrieve entry from cache")
18
19:5no-package-varpackage variables introduce mutable global state

iterator.go:19:5

18
19var emptyEntryInfo = EntryInfo{}
20
21:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:21:1

20
21// EntryInfo holds informations about entry in the cache
22type EntryInfo struct {
30:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:30:1

29
30// Key returns entry's underlying key
31func (e EntryInfo) Key() string {
31:20confusing-namingname Key differs from key only by capitalization

iterator.go:31:20

30// Key returns entry's underlying key
31func (e EntryInfo) Key() string {
32 return e.key
35:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:35:1

34
35// Hash returns entry's hash value
36func (e EntryInfo) Hash() uint64 {
36:20confusing-namingname Hash differs from hash only by capitalization

iterator.go:36:20

35// Hash returns entry's hash value
36func (e EntryInfo) Hash() uint64 {
37 return e.hash
40:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:40:1

39
40// Timestamp returns entry's timestamp (time of insertion)
41func (e EntryInfo) Timestamp() uint64 {
41:20confusing-namingname Timestamp differs from timestamp only by capitalization

iterator.go:41:20

40// Timestamp returns entry's timestamp (time of insertion)
41func (e EntryInfo) Timestamp() uint64 {
42 return e.timestamp
45:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:45:1

44
45// Value returns entry's underlying value
46func (e EntryInfo) Value() []byte {
46:20confusing-namingname Value differs from value only by capitalization

iterator.go:46:20

45// Value returns entry's underlying value
46func (e EntryInfo) Value() []byte {
47 return e.value
50:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:50:1

49
50// EntryInfoIterator allows to iterate over entries in the cache
51type EntryInfoIterator struct {
63:30cognitive-complexityfunction has cognitive complexity 9; maximum is 7

iterator.go:63:30

62// SetNext moves to next element and returns true if it exists.
63func (it *EntryInfoIterator) SetNext() bool {
64 it.mutex.Lock()
139:1doc-comment-perioddocumentation comment should end with punctuation

iterator.go:139:1

138
139// Value returns current value from the iterator
140func (it *EntryInfoIterator) Value() (EntryInfo, error) {

iterator_test.go23

1:1formatfile is not formatted

iterator_test.go:1:1

1package bigcache
2
  • Fix (safe): run `strider fmt iterator_test.go`
19:14discarded-error-resulterror result returned by New is discarded

iterator_test.go:19:14

18 keysCount := 1000
19 cache, _ := New(context.Background(), Config{
20 Shards: 8,
28:3discarded-error-resulterror result returned by cache.Set is discarded

iterator_test.go:28:3

27 for i := 0; i < keysCount; i++ {
28 cache.Set(fmt.Sprintf("key%d", i), value)
29 }
32:26nested-structsmove nested anonymous struct types to named declarations

iterator_test.go:32:26

31 // when
32 keys := make(map[string]struct{})
33 iterator := cache.Iterator()
39:26nested-structsmove nested anonymous struct types to named declarations

iterator_test.go:39:26

38 if err == nil {
39 keys[current.Key()] = struct{}{}
40 }
52:14discarded-error-resulterror result returned by newBigCache is discarded

iterator_test.go:52:14

51 clock := mockedClock{value: 0}
52 cache, _ := newBigCache(context.Background(), Config{
53 Shards: 8,
59:2discarded-error-resulterror result returned by cache.Set is discarded

iterator_test.go:59:2

58
59 cache.Set("key", []byte("value"))
60
66:12error-stringserror string should not be capitalized or end with punctuation

iterator_test.go:66:12

65 if !iterator.SetNext() {
66 t.Errorf("Iterator should contain at least single element")
67 }
74:17redundant-conversionconversion from uint64 to the identical type is redundant

iterator_test.go:74:17

73 assertEqual(t, "key", current.Key())
74 assertEqual(t, uint64(0x3dc94a19365b10ec), current.Hash())
75 assertEqual(t, []byte("value"), current.Value())
75:24add-constantstring literal "value" appears more than twice; define a constant

iterator_test.go:75:24

74 assertEqual(t, uint64(0x3dc94a19365b10ec), current.Hash())
75 assertEqual(t, []byte("value"), current.Value())
76 assertEqual(t, uint64(0), current.Timestamp())
76:17redundant-conversionconversion from uint64 to the identical type is redundant

iterator_test.go:76:17

75 assertEqual(t, []byte("value"), current.Value())
76 assertEqual(t, uint64(0), current.Timestamp())
77}
83:14discarded-error-resulterror result returned by New is discarded

iterator_test.go:83:14

82 // given
83 cache, _ := New(context.Background(), Config{
84 Shards: 1,
90:2discarded-error-resulterror result returned by cache.Set is discarded

iterator_test.go:90:2

89
90 cache.Set("key", []byte("value"))
91
90:12add-constantstring literal "key" appears more than twice; define a constant

iterator_test.go:90:12

89
90 cache.Set("key", []byte("value"))
91
97:12error-stringserror string should not be capitalized or end with punctuation

iterator_test.go:97:12

96 if !iterator.SetNext() {
97 t.Errorf("Iterator should contain at least single element")
98 }
125:14discarded-error-resulterror result returned by New is discarded

iterator_test.go:125:14

124 // given
125 cache, _ := New(context.Background(), Config{
126 Shards: 1,
137:12error-stringserror string should not be capitalized or end with punctuation

iterator_test.go:137:12

136 if iterator.SetNext() {
137 t.Errorf("Iterator should not contain any elements")
138 }
145:14discarded-error-resulterror result returned by New is discarded

iterator_test.go:145:14

144 // given
145 cache, _ := New(context.Background(), Config{
146 Shards: 1,
161:6test-parallelismconsider calling t.Parallel() when this test begins

iterator_test.go:161:6

160
161func TestEntriesIteratorParallelAdd(t *testing.T) {
162 bc, err := New(context.Background(), DefaultConfig(1*time.Minute))
161:37unused-parameterparameter t is unused

iterator_test.go:161:37

160
161func TestEntriesIteratorParallelAdd(t *testing.T) {
162 bc, err := New(context.Background(), DefaultConfig(1*time.Minute))
184:11discarded-error-resulterror result returned by iter.Value is discarded

iterator_test.go:184:11

183 for iter.SetNext() {
184 _, _ = iter.Value()
185 }
190:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

iterator_test.go:190:6

189
190func TestParallelSetAndIteration(t *testing.T) {
191 t.Parallel()
195:14discarded-error-resulterror result returned by New is discarded

iterator_test.go:195:14

194
195 cache, _ := New(context.Background(), Config{
196 Shards: 1,

logger.go7

1:1formatfile is not formatted

logger.go:1:1

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

logger.go:1:9

1package bigcache
2
8:1doc-comment-perioddocumentation comment should end with punctuation

logger.go:8:1

7
8// Logger is invoked when `Config.Verbose=true`
9type Logger interface {
10:29use-anyuse any instead of interface{}

logger.go:10:29

9type Logger interface {
10 Printf(format string, v ...interface{})
11}
16:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

logger.go:16:1

15// see https://golang.org/doc/faq#guarantee_satisfies_interface
16var _ Logger = &log.Logger{}
17
18:1doc-comment-perioddocumentation comment should end with punctuation

logger.go:18:1

17
18// DefaultLogger returns a `Logger` implementation
19// backed by stdlib's log
20:6exported-declaration-commentexported function or method should have a comment beginning with its name

logger.go:20:6

19// backed by stdlib's log
20func DefaultLogger() *log.Logger {
21 return log.New(os.Stdout, "", log.LstdFlags)

queue/bytes_queue.go27

1:1formatfile is not formatted

queue/bytes_queue.go:1:1

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

queue/bytes_queue.go:1:9

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

queue/bytes_queue.go:17:2

16var (
17 errEmptyQueue = &queueError{"Empty queue"}
18 errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
18:2no-package-varpackage variables introduce mutable global state

queue/bytes_queue.go:18:2

17 errEmptyQueue = &queueError{"Empty queue"}
18 errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
19 errIndexOutOfBounds = &queueError{"Index out of range"}
19:2no-package-varpackage variables introduce mutable global state

queue/bytes_queue.go:19:2

18 errInvalidIndex = &queueError{"Index must be greater than zero. Invalid index."}
19 errIndexOutOfBounds = &queueError{"Index out of range"}
20 errFullQueue = &queueError{"Full queue. Maximum size limit reached."}
20:2no-package-varpackage variables introduce mutable global state

queue/bytes_queue.go:20:2

19 errIndexOutOfBounds = &queueError{"Index out of range"}
20 errFullQueue = &queueError{"Full queue. Maximum size limit reached."}
21)
23:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:23:1

22
23// BytesQueue is a non-thread safe queue type of fifo based on bytes array.
24// For every push operation index of entry is returned. It can be used to read the entry later
25:6exported-declaration-commentexported type should have a comment beginning with its name

queue/bytes_queue.go:25:6

24// For every push operation index of entry is returned. It can be used to read the entry later
25type BytesQueue struct {
26 full bool
45:2single-case-switchswitch with one case can be replaced by an if statement

queue/bytes_queue.go:45:2

44 var header int
45 switch {
46 case length < 127: // 1<<7-1
61:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:61:1

60
61// NewBytesQueue initialize new bytes queue.
62// capacity is used in bytes array allocation
64:6exported-declaration-commentexported function or method should have a comment beginning with its name

queue/bytes_queue.go:64:6

63// When verbose flag is set then information about memory allocation are printed
64func NewBytesQueue(capacity int, maxCapacity int, verbose bool) *BytesQueue {
65 return &BytesQueue{
77:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:77:1

76
77// Reset removes all entries from queue
78func (q *BytesQueue) Reset() {
89:22exported-declaration-commentexported function or method should have a comment beginning with its name

queue/bytes_queue.go:89:22

88// Returns index for pushed data or error if maximum size queue limit is reached.
89func (q *BytesQueue) Push(data []byte) (int, error) {
90 neededSize := getNeededSize(len(data))
95:13optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

queue/bytes_queue.go:95:13

94 q.tail = leftMarginIndex
95 } else if q.capacity+neededSize >= q.maxCapacity && q.maxCapacity > 0 {
96 return -1, errFullQueue
97:5no-else-after-returnremove else and unindent its body after the return

queue/bytes_queue.go:97:5

96 return -1, errFullQueue
97 } else {
98 q.allocateAdditionalMemory(neededSize)
109:22cognitive-complexityfunction has cognitive complexity 9; maximum is 7

queue/bytes_queue.go:109:22

108
109func (q *BytesQueue) allocateAdditionalMemory(minimum int) {
110 start := time.Now()
143:22confusing-namingname push differs from Push only by capitalization

queue/bytes_queue.go:143:22

142
143func (q *BytesQueue) push(data []byte, len int) {
144 headerEntrySize := binary.PutUvarint(q.headerBuffer, uint64(len))
143:40redefines-builtin-ididentifier len shadows a predeclared identifier

queue/bytes_queue.go:143:40

142
143func (q *BytesQueue) push(data []byte, len int) {
144 headerEntrySize := binary.PutUvarint(q.headerBuffer, uint64(len))
159:40redefines-builtin-ididentifier len shadows a predeclared identifier

queue/bytes_queue.go:159:40

158
159func (q *BytesQueue) copy(data []byte, len int) {
160 q.tail += copy(q.array[q.tail:], data[:len])
163:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:163:1

162
163// Pop reads the oldest entry from queue and moves head pointer to the next one
164func (q *BytesQueue) Pop() ([]byte, error) {
186:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:186:1

185
186// Peek reads the oldest entry from list without moving head pointer
187func (q *BytesQueue) Peek() ([]byte, error) {
192:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:192:1

191
192// Get reads entry from index
193func (q *BytesQueue) Get(index int) ([]byte, error) {
198:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:198:1

197
198// CheckGet checks if an entry can be read from index
199func (q *BytesQueue) CheckGet(index int) error {
203:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:203:1

202
203// Capacity returns number of allocated bytes for queue
204func (q *BytesQueue) Capacity() int {
208:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:208:1

207
208// Len returns number of entries kept in queue
209func (q *BytesQueue) Len() int {
213:1doc-comment-perioddocumentation comment should end with punctuation

queue/bytes_queue.go:213:1

212
213// Error returns error message
214func (e *queueError) Error() string {
236:22confusing-namingname peek differs from Peek only by capitalization

queue/bytes_queue.go:236:22

235// peek returns the data from index and the number of bytes to encode the length of the data in uvarint format
236func (q *BytesQueue) peek(index int) ([]byte, int, error) {
237 err := q.peekCheckErr(index)

queue/bytes_queue_test.go84

1:1file-length-limitfile has 511 lines; maximum is 500

queue/bytes_queue_test.go:1:1

1package queue
2
1:1formatfile is not formatted

queue/bytes_queue_test.go:1:1

1package queue
2
  • Fix (safe): run `strider fmt queue/bytes_queue_test.go`
26:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:26:2

25 // when
26 queue.Push(entry)
27
41:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:41:2

40 // when
41 queue.Push(entry)
42
52:18add-constantstring literal "hello" appears more than twice; define a constant

queue/bytes_queue_test.go:52:18

51 queue := NewBytesQueue(100, 0, false)
52 entry := []byte("hello")
53
63:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:63:2

62 // when
63 queue.Push(entry)
64 read, err = queue.Peek()
81:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:81:2

80 // when
81 queue.Push(blob('a', 3))
82 queue.Push(blob('b', 4))
82:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:82:2

81 queue.Push(blob('a', 3))
82 queue.Push(blob('b', 4))
83
93:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:93:2

92 queue.Reset()
93 queue.Push(blob('c', 8)) // should not trigger a re-allocation
94
108:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:108:2

107 // when
108 queue.Push(entry)
109 queue.Push(entry)
109:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:109:2

108 queue.Push(entry)
109 queue.Push(entry)
110 queue.Push(entry)
110:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:110:2

109 queue.Push(entry)
110 queue.Push(entry)
111
116:17add-constantstring literal "Empty queue" appears more than twice; define a constant

queue/bytes_queue_test.go:116:17

115 // then
116 assertEqual(t, "Empty queue", err.Error())
117 assertEqual(t, 0, len(read))
120:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:120:2

119 // when
120 queue.Push(entry)
121 read, err = queue.Peek()
143:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:143:2

142 // when
143 queue.Push(blob('a', 70))
144 queue.Push(blob('b', 20))
144:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:144:2

143 queue.Push(blob('a', 70))
144 queue.Push(blob('b', 20))
145 queue.Pop()
145:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:145:2

144 queue.Push(blob('b', 20))
145 queue.Pop()
146 queue.Push(blob('c', 20))
146:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:146:2

145 queue.Pop()
146 queue.Push(blob('c', 20))
147
160:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:160:2

159 // when
160 queue.Push([]byte("hello1"))
161 queue.Push([]byte("hello2"))
161:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:161:2

160 queue.Push([]byte("hello1"))
161 queue.Push([]byte("hello2"))
162
174:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:174:2

173 // when
174 queue.Push(blob('a', 3)) // header + entry + left margin = 5 bytes
175 queue.Push(blob('b', 6)) // additional 7 bytes
175:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:175:2

174 queue.Push(blob('a', 3)) // header + entry + left margin = 5 bytes
175 queue.Push(blob('b', 6)) // additional 7 bytes
176 queue.Pop() // space freed, 4 bytes available at the beginning
176:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:176:2

175 queue.Push(blob('b', 6)) // additional 7 bytes
176 queue.Pop() // space freed, 4 bytes available at the beginning
177 queue.Push(blob('c', 6)) // 7 bytes needed, 13 bytes available at the tail
177:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:177:2

176 queue.Pop() // space freed, 4 bytes available at the beginning
177 queue.Push(blob('c', 6)) // 7 bytes needed, 13 bytes available at the tail
178
192:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:192:2

191 // when
192 queue.Push(blob('a', 3)) // header + entry + left margin = 5 bytes
193 index, _ := queue.Push(blob('b', 6)) // additional 7 bytes
193:14discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:193:14

192 queue.Push(blob('a', 3)) // header + entry + left margin = 5 bytes
193 index, _ := queue.Push(blob('b', 6)) // additional 7 bytes
194 queue.Pop() // space freed, 4 bytes available at the beginning
194:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:194:2

193 index, _ := queue.Push(blob('b', 6)) // additional 7 bytes
194 queue.Pop() // space freed, 4 bytes available at the beginning
195 newestIndex, _ := queue.Push(blob('c', 6)) // 7 bytes needed, 13 available at the tail
195:20discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:195:20

194 queue.Pop() // space freed, 4 bytes available at the beginning
195 newestIndex, _ := queue.Push(blob('c', 6)) // 7 bytes needed, 13 available at the tail
196
210:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:210:2

209 // when
210 queue.Push(blob('a', 70)) // header + entry + left margin = 72 bytes
211 queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
211:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:211:2

210 queue.Push(blob('a', 70)) // header + entry + left margin = 72 bytes
211 queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
212 queue.Pop() // space freed at the beginning
212:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:212:2

211 queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
212 queue.Pop() // space freed at the beginning
213 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
213:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:213:2

212 queue.Pop() // space freed at the beginning
213 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
214 queue.Push(blob('d', 40)) // 41 bytes needed but no available in one segment, allocate new memory
214:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:214:2

213 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
214 queue.Push(blob('d', 40)) // 41 bytes needed but no available in one segment, allocate new memory
215
234:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:234:2

233 // when
234 queue.Push(blob('a', 30)) // header + entry + left margin = 32 bytes
235 queue.Push(blob('b', 1)) // 32 + 128 + 1 = 161 bytes
235:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:235:2

234 queue.Push(blob('a', 30)) // header + entry + left margin = 32 bytes
235 queue.Push(blob('b', 1)) // 32 + 128 + 1 = 161 bytes
236 queue.Push(blob('b', 125)) // 32 + 128 + 1 = 161 bytes
236:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:236:2

235 queue.Push(blob('b', 1)) // 32 + 128 + 1 = 161 bytes
236 queue.Push(blob('b', 125)) // 32 + 128 + 1 = 161 bytes
237 queue.Push(blob('c', 20)) // 160 + 20 + 1 = 182
237:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:237:2

236 queue.Push(blob('b', 125)) // 32 + 128 + 1 = 161 bytes
237 queue.Push(blob('c', 20)) // 160 + 20 + 1 = 182
238 queue.Pop() // space freed at the beginning
238:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:238:2

237 queue.Push(blob('c', 20)) // 160 + 20 + 1 = 182
238 queue.Pop() // space freed at the beginning
239 queue.Pop() // free 2 bytes
239:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:239:2

238 queue.Pop() // space freed at the beginning
239 queue.Pop() // free 2 bytes
240 queue.Pop() // free 126
240:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:240:2

239 queue.Pop() // free 2 bytes
240 queue.Pop() // free 126
241 queue.Push(blob('d', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer, now free space is 128 bytes
241:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:241:2

240 queue.Pop() // free 126
241 queue.Push(blob('d', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer, now free space is 128 bytes
242 queue.Push(blob('e', 160)) // invoke allocateAdditionalMemory but fill 127 bytes free space (It should be 128 bytes, but 127 are filled, leaving one byte unfilled)
242:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:242:2

241 queue.Push(blob('d', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer, now free space is 128 bytes
242 queue.Push(blob('e', 160)) // invoke allocateAdditionalMemory but fill 127 bytes free space (It should be 128 bytes, but 127 are filled, leaving one byte unfilled)
243
259:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:259:2

258 // when
259 queue.Push(blob('a', 70)) // header + entry + left margin = 72 bytes
260 index, _ := queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
260:14discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:260:14

259 queue.Push(blob('a', 70)) // header + entry + left margin = 72 bytes
260 index, _ := queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
261 queue.Pop() // space freed at the beginning
261:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:261:2

260 index, _ := queue.Push(blob('b', 10)) // 72 + 10 + 1 = 83 bytes
261 queue.Pop() // space freed at the beginning
262 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
262:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:262:2

261 queue.Pop() // space freed at the beginning
262 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
263 newestIndex, _ := queue.Push(blob('d', 40)) // 41 bytes needed but no available in one segment, allocate new memory
263:20discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:263:20

262 queue.Push(blob('c', 30)) // 31 bytes used at the beginning, tail pointer is before head pointer
263 newestIndex, _ := queue.Push(blob('d', 40)) // 41 bytes needed but no available in one segment, allocate new memory
264
278:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:278:2

277 // when
278 queue.Push(blob('a', 100))
279 // then
292:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:292:2

291 // when
292 queue.Push(make([]byte, 2))
293 queue.Push(make([]byte, 2))
293:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:293:2

292 queue.Push(make([]byte, 2))
293 queue.Push(make([]byte, 2))
294 queue.Push(make([]byte, 100))
294:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:294:2

293 queue.Push(make([]byte, 2))
294 queue.Push(make([]byte, 100))
295
297:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:297:2

296 // then
297 queue.Pop()
298 queue.Pop()
298:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:298:2

297 queue.Pop()
298 queue.Pop()
299 assertEqual(t, make([]byte, 100), pop(queue))
311:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:311:2

310 // when
311 queue.Push([]byte("a"))
312 queue.Push([]byte("b"))
312:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:312:2

311 queue.Push([]byte("a"))
312 queue.Push([]byte("b"))
313 queue.Pop()
313:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:313:2

312 queue.Push([]byte("b"))
313 queue.Pop()
314 queue.Pop()
314:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:314:2

313 queue.Pop()
314 queue.Pop()
315 queue.Push([]byte("c"))
315:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:315:2

314 queue.Pop()
315 queue.Push([]byte("c"))
316
329:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:329:2

328 // when
329 queue.Push([]byte("a"))
330 index, _ := queue.Push([]byte("b"))
330:14discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:330:14

329 queue.Push([]byte("a"))
330 index, _ := queue.Push([]byte("b"))
331 queue.Push([]byte("c"))
331:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:331:2

330 index, _ := queue.Push([]byte("b"))
331 queue.Push([]byte("c"))
332 result, _ := queue.Get(index)
331:20add-constantstring literal "c" appears more than twice; define a constant

queue/bytes_queue_test.go:331:20

330 index, _ := queue.Push([]byte("b"))
331 queue.Push([]byte("c"))
332 result, _ := queue.Get(index)
332:15discarded-error-resulterror result returned by queue.Get is discarded

queue/bytes_queue_test.go:332:15

331 queue.Push([]byte("c"))
332 result, _ := queue.Get(index)
333
335:24add-constantstring literal "b" appears more than twice; define a constant

queue/bytes_queue_test.go:335:24

334 // then
335 assertEqual(t, []byte("b"), result)
336}
343:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:343:2

342 queue := NewBytesQueue(1, 0, false)
343 queue.Push([]byte("a"))
344
343:20add-constantstring literal "a" appears more than twice; define a constant

queue/bytes_queue_test.go:343:20

342 queue := NewBytesQueue(1, 0, false)
343 queue.Push([]byte("a"))
344
360:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:360:2

359 queue := NewBytesQueue(1, 0, false)
360 queue.Push([]byte("a"))
361
395:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:395:2

394 // when
395 queue.Push(blob('a', 25))
396 queue.Push(blob('b', 5))
396:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:396:2

395 queue.Push(blob('a', 25))
396 queue.Push(blob('b', 5))
397 capacity := queue.Capacity()
414:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:414:2

413 // when
414 queue.Push([]byte("aaa"))
415 queue.Push([]byte("bb"))
415:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:415:2

414 queue.Push([]byte("aaa"))
415 queue.Push([]byte("bb"))
416 queue.Pop()
416:2discarded-error-resulterror result returned by queue.Pop is discarded

queue/bytes_queue_test.go:416:2

415 queue.Push([]byte("bb"))
416 queue.Pop()
417
420:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:420:2

419 assertEqual(t, 9, queue.Capacity())
420 queue.Push([]byte("c"))
421 assertEqual(t, 18, queue.Capacity())
435:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:435:2

434 // when
435 queue.Push([]byte("aaa"))
436 queue.Push([]byte("bb"))
436:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:436:2

435 queue.Push([]byte("aaa"))
436 queue.Push([]byte("bb"))
437 _, err := queue.Pop()
440:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:440:2

439
440 queue.Push([]byte("c"))
441 queue.Push([]byte("d"))
441:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:441:2

440 queue.Push([]byte("c"))
441 queue.Push([]byte("d"))
442 queue.Push([]byte("e"))
442:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:442:2

441 queue.Push([]byte("d"))
442 queue.Push([]byte("e"))
443 _, err = queue.Pop()
447:2discarded-error-resulterror result returned by queue.Push is discarded

queue/bytes_queue_test.go:447:2

446 noError(t, err)
447 queue.Push([]byte("fff"))
448 _, err = queue.Pop()
468:22redefines-builtin-ididentifier len shadows a predeclared identifier

queue/bytes_queue_test.go:468:22

467
468func blob(char byte, len int) []byte {
469 return bytes.Repeat([]byte{char}, len)
472:49use-anyuse any instead of interface{}

queue/bytes_queue_test.go:472:49

471
472func assertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
473 if !objectsAreEqual(expected, actual) {
472:76use-anyuse any instead of interface{}

queue/bytes_queue_test.go:472:76

471
472func assertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
473 if !objectsAreEqual(expected, actual) {
487:3dynamic-printfprintf-style function with dynamic format string and no further arguments should use print-style function instead

queue/bytes_queue_test.go:487:3

486 file = path.Base(file)
487 t.Errorf(fmt.Sprintf("\n%s:%d: Error is not nil: \n"+
488 "actual : %T(%#v)\n", file, line, e, e))
492:39use-anyuse any instead of interface{}

queue/bytes_queue_test.go:492:39

491
492func objectsAreEqual(expected, actual interface{}) bool {
493 if expected == nil || actual == nil {

server/cache_handlers.go9

1:1formatfile is not formatted

server/cache_handlers.go:1:1

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

server/cache_handlers.go:1:9

1package main
2
12:3single-case-switchswitch with one case can be replaced by an if statement

server/cache_handlers.go:12:3

11 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12 switch r.Method {
13 case http.MethodGet:
29:40unused-parameterparameter r is unused

server/cache_handlers.go:29:40

28
29func clearCache(w http.ResponseWriter, r *http.Request) {
30 if err := cache.Reset(); err != nil {
39:6get-function-return-valueGet-prefixed function should return a value

server/cache_handlers.go:39:6

38// handles get requests.
39func getCacheHandler(w http.ResponseWriter, r *http.Request) {
40 target := r.URL.Path[len(cachePath):]
43:3discarded-error-resulterror result returned by w.Write is discarded

server/cache_handlers.go:43:3

42 w.WriteHeader(http.StatusBadRequest)
43 w.Write([]byte("can't get a key if there is no key."))
44 log.Print("empty request.")
59:2discarded-error-resulterror result returned by w.Write is discarded

server/cache_handlers.go:59:2

58 }
59 w.Write(entry)
60}
66:3discarded-error-resulterror result returned by w.Write is discarded

server/cache_handlers.go:66:3

65 w.WriteHeader(http.StatusBadRequest)
66 w.Write([]byte("can't put a key if there is no key."))
67 log.Print("empty request.")
78:30redundant-conversionconversion from []byte to the identical type is redundant

server/cache_handlers.go:78:30

77
78 if err := cache.Set(target, []byte(entry)); err != nil {
79 log.Print(err)

server/middleware.go3

1:1formatfile is not formatted

server/middleware.go:1:1

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

server/middleware.go:1:9

1package main
2
15:3modifies-parameterassignment modifies parameter h

server/middleware.go:15:3

14 for _, svc := range svcs {
15 h = svc(h)
16 }

server/middleware_test.go5

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

server/middleware_test.go:19:6

18
19func TestServiceLoader(t *testing.T) {
20 req, err := http.NewRequest("GET", "/api/v1/stats", nil)
20:30standard-http-method-constantreplace the HTTP method literal with http.MethodGet

server/middleware_test.go:20:30

19func TestServiceLoader(t *testing.T) {
20 req, err := http.NewRequest("GET", "/api/v1/stats", nil)
21 if err != nil {
32:6test-parallelismconsider calling t.Parallel() when this test begins

server/middleware_test.go:32:6

31
32func TestRequestMetrics(t *testing.T) {
33 var b bytes.Buffer
35:30standard-http-method-constantreplace the HTTP method literal with http.MethodGet

server/middleware_test.go:35:30

34 logger := log.New(&b, "", log.LstdFlags)
35 req, err := http.NewRequest("GET", "/api/v1/cache/empty", nil)
36 if err != nil {
44:12error-stringserror string should not be capitalized or end with punctuation

server/middleware_test.go:44:12

43 if len(targetTestString) == 0 {
44 t.Errorf("we are not logging request length strings.")
45 }

server/server.go8

1:9package-commentspackage should have a documentation comment

server/server.go:1:9

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

server/server.go:29:2

28var (
29 port int
30 logfile string
30:2no-package-varpackage variables introduce mutable global state

server/server.go:30:2

29 port int
30 logfile string
31 ver bool
31:2no-package-varpackage variables introduce mutable global state

server/server.go:31:2

30 logfile string
31 ver bool
32
34:2no-package-varpackage variables introduce mutable global state

server/server.go:34:2

33 // cache-specific settings.
34 cache *bigcache.BigCache
35 config = bigcache.Config{}
35:2no-package-varpackage variables introduce mutable global state

server/server.go:35:2

34 cache *bigcache.BigCache
35 config = bigcache.Config{}
36)
38:6no-initreplace init with explicit initialization

server/server.go:38:6

37
38func init() {
39 flag.BoolVar(&config.Verbose, "v", false, "Verbose logging.")
54:3discarded-error-resulterror result returned by fmt.Printf is discarded

server/server.go:54:3

53 if ver {
54 fmt.Printf("BigCache HTTP Server v%s", version)
55 os.Exit(0)

server/server_test.go28

1:1formatfile is not formatted

server/server_test.go:1:1

1package main
2
  • Fix (safe): run `strider fmt server/server_test.go`
17:19insecure-url-schemeURL uses insecure http scheme

server/server_test.go:17:19

16const (
17 testBaseString = "http://bigcache.org"
18)
21:13discarded-error-resulterror result returned by bigcache.New is discarded

server/server_test.go:21:13

20func testCacheSetup() {
21 cache, _ = bigcache.New(context.Background(), bigcache.Config{
22 Shards: 1024,
65:29add-constantstring literal "GET" appears more than twice; define a constant

server/server_test.go:65:29

64 t.Parallel()
65 req := httptest.NewRequest("GET", testBaseString+"/api/v1/cache/getKey", nil)
66 rr := httptest.NewRecorder()
69:2discarded-error-resulterror result returned by cache.Set is discarded

server/server_test.go:69:2

68 // set something.
69 cache.Set("getKey", []byte("123"))
70
80:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:80:12

79 if string(body) != "123" {
80 t.Errorf("want: 123; got: %s.\n\tcan't get existing key getKey.", string(body))
81 }
86:98add-constantstring literal "123" appears more than twice; define a constant

server/server_test.go:86:98

85 t.Parallel()
86 req := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer([]byte("123")))
87 rr := httptest.NewRecorder()
97:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:97:12

96 if string(testPutKeyResult) != "123" {
97 t.Errorf("want: 123; got: %s.\n\tcan't get PUT key putKey.", string(testPutKeyResult))
98 }
118:54add-constantstring literal "/api/v1/cache/" appears more than twice; define a constant

server/server_test.go:118:54

117
118 req := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/", bytes.NewBuffer([]byte("123")))
119 rr := httptest.NewRecorder()
125:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:125:12

124 if resp.StatusCode != 404 {
125 t.Errorf("want: 404; got: %d.\n\tapparently we're trying to delete empty keys.", resp.StatusCode)
126 }
139:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:139:12

138 if resp.StatusCode != 404 {
139 t.Errorf("want: 404; got: %d.\n\tapparently we're trying to delete invalid keys.", resp.StatusCode)
140 }
146:29add-constantstring literal "DELETE" appears more than twice; define a constant

server/server_test.go:146:29

145
146 req := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/testDeleteKey", bytes.NewBuffer([]byte("123")))
147 rr := httptest.NewRecorder()
157:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:157:12

156 if resp.StatusCode != 200 {
157 t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
158 }
164:36add-constantstring literal "PUT" appears more than twice; define a constant

server/server_test.go:164:36

163
164 putRequest := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer([]byte("123")))
165 putResponseRecorder := httptest.NewRecorder()
180:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:180:12

179 if resp.StatusCode != 200 {
180 t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
181 }
207:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:207:12

206 if testStats.Hits == 0 {
207 t.Errorf("want: > 0; got: 0.\n\thandler not properly returning stats info.")
208 }
216:54add-constantstring literal "/api/v1/stats" appears more than twice; define a constant

server/server_test.go:216:54

215 getreq := httptest.NewRequest("GET", testBaseString+"/api/v1/stats", nil)
216 putreq := httptest.NewRequest("PUT", testBaseString+"/api/v1/stats", nil)
217 rr := httptest.NewRecorder()
220:22add-constantstring literal "incrementStats" appears more than twice; define a constant

server/server_test.go:220:22

219 // manually enter a key so there are some stats. get it so there's at least 1 hit.
220 if err := cache.Set("incrementStats", []byte("123")); err != nil {
221 t.Errorf("error setting cache value. error %s", err)
237:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:237:12

236 if testStats.Hits == 0 {
237 t.Errorf("want: > 0; got: 0.\n\thandler not properly returning stats info.")
238 }
249:6test-parallelismconsider calling t.Parallel() when this test begins

server/server_test.go:249:6

248
249func TestCacheIndexHandler(t *testing.T) {
250 getreq := httptest.NewRequest("GET", testBaseString+"/api/v1/cache/testkey", nil)
252:57add-constantstring literal "/api/v1/cache/testkey" appears more than twice; define a constant

server/server_test.go:252:57

251 putreq := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/testkey", bytes.NewBuffer([]byte("123")))
252 delreq := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/testkey", bytes.NewBuffer([]byte("123")))
253
262:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:262:12

261 if resp.StatusCode != 201 {
262 t.Errorf("want: 201; got: %d.\n\tcan't put keys.", resp.StatusCode)
263 }
267:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:267:12

266 if resp.StatusCode != 200 {
267 t.Errorf("want: 200; got: %d.\n\tcan't get keys.", resp.StatusCode)
268 }
272:12add-constantstring literal "want: 200; got: %d.\n\tcan't delete keys." appears more than twice; define a constant

server/server_test.go:272:12

271 if resp.StatusCode != 200 {
272 t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
273 }
272:12error-stringserror string should not be capitalized or end with punctuation

server/server_test.go:272:12

271 if resp.StatusCode != 200 {
272 t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
273 }
278:51add-constantstring literal "/api/v1/cache/putKey" appears more than twice; define a constant

server/server_test.go:278:51

277 t.Parallel()
278 req := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer(bytes.Repeat([]byte("a"), 8*1024*1024)))
279 rr := httptest.NewRecorder()
291:75redundant-conversionconversion from errReader to the identical type is redundant

server/server_test.go:291:75

290 t.Parallel()
291 req := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", errReader(0))
292 rr := httptest.NewRecorder()
302:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

server/server_test.go:302:1

301
302type errReader int
303

server/stats_handler.go6

1:1formatfile is not formatted

server/stats_handler.go:1:1

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

server/stats_handler.go:1:9

1package main
2
12:3single-case-switchswitch with one case can be replaced by an if statement

server/stats_handler.go:12:3

11 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12 switch r.Method {
13 case http.MethodGet:
22:6get-function-return-valueGet-prefixed function should return a value

server/stats_handler.go:22:6

21// returns the cache's statistics.
22func getCacheStatsHandler(w http.ResponseWriter, r *http.Request) {
23 target, err := json.Marshal(cache.Stats())
22:50unused-parameterparameter r is unused

server/stats_handler.go:22:50

21// returns the cache's statistics.
22func getCacheStatsHandler(w http.ResponseWriter, r *http.Request) {
23 target, err := json.Marshal(cache.Stats())
31:2discarded-error-resulterror result returned by w.Write is discarded

server/stats_handler.go:31:2

30 w.Header().Set("Content-Type", "application/json; charset=utf-8")
31 w.Write(target)
32}

shard.go10

1:1formatfile is not formatted

shard.go:1:1

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

shard.go:1:9

1package bigcache
2
13:1doc-comment-perioddocumentation comment should end with punctuation

shard.go:13:1

12
13// Metadata contains information of a specific entry
14type Metadata struct {
110:20add-constantstring literal "Collision detected. Both %q and %q have the same hash %x" appears more than twice; define a constant

shard.go:110:20

109 if s.isVerbose {
110 s.logger.Printf("Collision detected. Both %q and %q have the same hash %x", key, readKeyFromEntry(wrappedEntry), hashedKey)
111 }
120:22cognitive-complexityfunction has cognitive complexity 11; maximum is 7

shard.go:120:22

119
120func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error {
121 currentTimestamp := uint64(s.clock.Epoch())
154:22cognitive-complexityfunction has cognitive complexity 8; maximum is 7

shard.go:154:22

153
154func (s *cacheShard) addNewWithoutLock(key string, hashedKey uint64, entry []byte) error {
155 currentTimestamp := uint64(s.clock.Epoch())
176:22cognitive-complexityfunction has cognitive complexity 11; maximum is 7

shard.go:176:22

175
176func (s *cacheShard) setWrappedEntryWithoutLock(currentTimestamp uint64, w []byte, hashedKey uint64) error {
177 if previousIndex := s.hashmap[hashedKey]; previousIndex != 0 {
195:22add-constantstring literal "entry is bigger than max shard size" appears more than twice; define a constant

shard.go:195:22

194 if s.removeOldestEntry(NoSpace) != nil {
195 return errors.New("entry is bigger than max shard size")
196 }
278:3discarded-error-resulterror result returned by evict is discarded

shard.go:278:3

277 if s.isExpired(oldestEntry, currentTimestamp) {
278 evict(Expired)
279 return true
292:22cognitive-complexityfunction has cognitive complexity 8; maximum is 7

shard.go:292:22

291
292func (s *cacheShard) cleanUp(currentTimestamp uint64) {
293 s.lock.Lock()

stats.go2

1:9package-commentspackage should have a documentation comment

stats.go:1:9

1package bigcache
2
3:1doc-comment-perioddocumentation comment should end with punctuation

stats.go:3:1

2
3// Stats stores cache statistics
4type Stats struct {

utils.go1

1:9package-commentspackage should have a documentation comment

utils.go:1:9

1package bigcache
2