Skip to content

Commit 7debd3d

Browse files
authored
enable linters: misspell, bodyclose (#28736)
1 parent 0059cd2 commit 7debd3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+140
-125
lines changed

go/.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ linters:
4343
- ineffassign # Phase 1: Ineffectual assignments
4444
- unused # Phase 1: Unused code
4545
- staticcheck # Phase 1: Static analysis
46+
- misspell # Phase 2: Spelling checks
47+
- bodyclose # Phase 2: HTTP response body checks
4648

4749
disable:
4850
# Disabled by default in v1, keeping disabled for incremental migration
4951
- errcheck # Error checking - enabled by default in v2, many unchecked errors
5052

5153
# Additional linters from kbfs-server/keybase examples (disabled for now)
5254
# These can be enabled incrementally in future work
53-
# - bodyclose # HTTP response body checks
54-
# - misspell # Spelling checks
5555
# - gosec # Security checks
5656
# - unparam # Unused parameters
5757

go/avatars/fullcaching.go

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -392,59 +392,60 @@ func (c *FullCachingSource) removeFile(m libkb.MetaContext, ent *lru.DiskLRUEntr
392392

393393
func (c *FullCachingSource) populateCacheWorker(m libkb.MetaContext) {
394394
for arg := range c.populateCacheCh {
395-
c.debug(m, "populateCacheWorker: fetching: name: %s format: %s url: %s", arg.name,
396-
arg.format, arg.url)
397-
// Grab image data first
398-
url := arg.url.String()
399-
resp, err := libkb.ProxyHTTPGet(m.G(), m.G().GetEnv(), url, "FullCachingSource: Avatar")
395+
err := c.populateCacheJob(m, arg)
400396
if err != nil {
401-
c.debug(m, "populateCacheWorker: failed to download avatar: %s", err)
402-
continue
403-
}
404-
// Find any previous path we stored this image at on the disk
405-
var previousEntry lruEntry
406-
var previousPath string
407-
key := c.avatarKey(arg.name, arg.format)
408-
found, ent, err := c.diskLRU.Get(m.Ctx(), m.G(), key)
409-
if err != nil {
410-
c.debug(m, "populateCacheWorker: failed to read previous entry in LRU: %s", err)
411-
err = libkb.DiscardAndCloseBody(resp)
412-
if err != nil {
413-
c.debug(m, "populateCacheWorker: error closing body: %+v", err)
414-
}
415-
continue
416-
}
417-
if found {
418-
previousEntry = c.processLRUHit(ent)
419-
previousPath = c.normalizeFilenameFromCache(m, previousEntry.Path)
397+
c.debug(m, "populateCacheWorker: %s", err)
420398
}
399+
}
400+
}
421401

422-
// Save to disk
423-
path, err := c.commitAvatarToDisk(m, resp.Body, previousPath)
424-
discardErr := libkb.DiscardAndCloseBody(resp)
425-
if discardErr != nil {
426-
c.debug(m, "populateCacheWorker: error closing body: %+v", discardErr)
427-
}
428-
if err != nil {
429-
c.debug(m, "populateCacheWorker: failed to write to disk: %s", err)
430-
continue
431-
}
432-
v := lruEntry{
433-
Path: path,
434-
URL: &url,
435-
}
436-
evicted, err := c.diskLRU.Put(m.Ctx(), m.G(), key, v)
437-
if err != nil {
438-
c.debug(m, "populateCacheWorker: failed to put into LRU: %s", err)
439-
continue
440-
}
441-
// Remove any evicted file (if there is one)
442-
c.removeFile(m, evicted)
402+
func (c *FullCachingSource) populateCacheJob(m libkb.MetaContext, arg populateArg) (err error) {
403+
c.debug(m, "populateCacheWorker: fetching: name: %s format: %s url: %s", arg.name,
404+
arg.format, arg.url)
405+
// Grab image data first
406+
url := arg.url.String()
407+
resp, err := libkb.ProxyHTTPGet(m.G(), m.G().GetEnv(), url, "FullCachingSource: Avatar")
408+
defer func() { _ = libkb.DiscardAndCloseBody(resp) }()
409+
if err != nil {
410+
c.debug(m, "populateCacheWorker: failed to download avatar: %s", err)
411+
return err
412+
}
413+
// Find any previous path we stored this image at on the disk
414+
var previousEntry lruEntry
415+
var previousPath string
416+
key := c.avatarKey(arg.name, arg.format)
417+
found, ent, err := c.diskLRU.Get(m.Ctx(), m.G(), key)
418+
if err != nil {
419+
c.debug(m, "populateCacheWorker: failed to read previous entry in LRU: %s", err)
420+
return err
421+
}
422+
if found {
423+
previousEntry = c.processLRUHit(ent)
424+
previousPath = c.normalizeFilenameFromCache(m, previousEntry.Path)
425+
}
443426

444-
if c.populateSuccessCh != nil {
445-
c.populateSuccessCh <- struct{}{}
446-
}
427+
// Save to disk
428+
path, err := c.commitAvatarToDisk(m, resp.Body, previousPath)
429+
if err != nil {
430+
c.debug(m, "populateCacheWorker: failed to write to disk: %s", err)
431+
return err
447432
}
433+
v := lruEntry{
434+
Path: path,
435+
URL: &url,
436+
}
437+
evicted, err := c.diskLRU.Put(m.Ctx(), m.G(), key, v)
438+
if err != nil {
439+
c.debug(m, "populateCacheWorker: failed to put into LRU: %s", err)
440+
return err
441+
}
442+
// Remove any evicted file (if there is one)
443+
c.removeFile(m, evicted)
444+
445+
if c.populateSuccessCh != nil {
446+
c.populateSuccessCh <- struct{}{}
447+
}
448+
return nil
448449
}
449450

450451
func (c *FullCachingSource) dispatchPopulateFromRes(m libkb.MetaContext, res keybase1.LoadAvatarsRes,

go/avatars/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func FetchAvatar(ctx context.Context, g *globals.Context, username string) (res
5656
return res, err
5757
}
5858
if resp.StatusCode >= 400 {
59+
resp.Body.Close()
5960
avatarReader = getAvatarPlaceholder()
6061
} else {
6162
avatarReader = resp.Body

go/chat/attachment_httpsrv_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func TestChatSrvAttachmentHTTPSrv(t *testing.T) {
155155
readAsset := func(msg chat1.UIMessage, cacheHit bool) {
156156
httpRes, err := http.Get(msg.Valid().AssetUrlInfo.FullUrl)
157157
require.NoError(t, err)
158+
defer httpRes.Body.Close()
158159
body, err := io.ReadAll(httpRes.Body)
159160
require.NoError(t, err)
160161
require.Equal(t, "HI", string(body))

go/chat/attachments/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func AssetFromMessage(ctx context.Context, g *globals.Context, uid gregor1.UID,
6565
attachment = chat1.MessageAttachment{
6666
Object: uploaded.Object,
6767
Previews: uploaded.Previews,
68-
Metadata: uploaded.Metadata,
68+
Metadata: uploaded.Metadata, //nolint:govet // keeping metadata for completeness
6969
}
7070
default:
7171
return res, errors.New("not an attachment message")

go/chat/bots/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (b *CachingBotCommandManager) createConv(ctx context.Context, typ chat1.Bot
159159
if teamName == nil {
160160
return res, errors.New("missing team name")
161161
} else if convID != nil {
162-
return res, errors.New("convID cannot be specified for team advertisments use type 'conv'")
162+
return res, errors.New("convID cannot be specified for team advertisements use type 'conv'")
163163
}
164164

165165
topicName := fmt.Sprintf("___keybase_botcommands_team_%s_%v", username, typ)

go/chat/boxer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ func TestChatMessageDeletedNotSuperseded(t *testing.T) {
10681068
// The server was not setting supersededBy on EDITs when their TEXT got deleted.
10691069
// So there are existing messages which have no supersededBy but are legitimately deleted.
10701070
// Tracked in CORE-4662
1071-
require.NoError(t, err, "suprisingly, should be able to unbox with deleted but no supersededby")
1071+
require.NoError(t, err, "surprisingly, should be able to unbox with deleted but no supersededby")
10721072
require.Equal(t, chat1.MessageBody{}, unboxed.MessageBody)
10731073
})
10741074
}

go/chat/emojisource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ func (s *DevConvEmojiSource) getCrossTeamConv(ctx context.Context, uid gregor1.U
765765
s.testingCreatedSyncConv <- struct{}{}
766766
}
767767
} else {
768-
s.Debug(ctx, "getCrossTeamConv: using exising sync conv: %s (topicID: %s)", res.GetConvID(), topicID)
768+
s.Debug(ctx, "getCrossTeamConv: using existing sync conv: %s (topicID: %s)", res.GetConvID(), topicID)
769769
}
770770
return res, nil
771771
}

go/chat/flip/flip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type GameStateUpdateMessage struct {
4747
Result *Result
4848
}
4949

50-
// Dealer is a peristent process that runs in the chat client that deals out a game. It can have multiple
50+
// Dealer is a persistent process that runs in the chat client that deals out a game. It can have multiple
5151
// games running at once.
5252
type Dealer struct {
5353
sync.Mutex

go/chat/maps/livelocation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (l *LiveLocationTracker) Start(ctx context.Context, uid gregor1.UID) {
5555
l.Lock()
5656
defer l.Unlock()
5757
l.uid = uid
58-
// bring back any trackers that we have stored. This is most relavent when being woken
58+
// bring back any trackers that we have stored. This is most relevant when being woken
5959
// up on iOS due to a location update. THe app might need to recreate all of its trackers
6060
// if the app had been killed.
6161
l.restoreLocked(ctx)

0 commit comments

Comments
 (0)