Skip to content

Commit 7c2bc3b

Browse files
authored
lint for 1.13.7 (keybase#22604)
1 parent 5fcff43 commit 7c2bc3b

33 files changed

Lines changed: 126 additions & 165 deletions

‎Jenkinsfile‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -486,53 +486,53 @@ def testGo(prefix, packagesToTest) {
486486
println "Building citogo"
487487
sh '(cd citogo && go install)'
488488

489-
println "Installing golangci-lint"
490-
dir("..") {
491-
retry(5) {
492-
// This works with go1.12.12 but not go1.13.1 with an error containing "invalid pseudo-version"
493-
sh 'GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.16.0'
489+
if (prefix == "test_linux_go_") {
490+
// Only test golangci-lint on linux
491+
println "Installing golangci-lint"
492+
dir("..") {
493+
retry(5) {
494+
sh 'GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.6'
495+
}
494496
}
495-
}
496497

497498

498-
def hasKBFSChanges = packagesToTest.keySet().findIndexOf { key -> key =~ /^github.com\/keybase\/client\/go\/kbfs/ } >= 0
499-
if (hasKBFSChanges) {
500-
println "Running golangci-lint on KBFS"
501-
dir('kbfs') {
502-
retry(5) {
503-
timeout(activity: true, time: 180, unit: 'SECONDS') {
504-
// Ignore the `dokan` directory since it contains lots of c code.
505-
// Ignore the `protocol` directory, autogeneration has some critques
506-
sh 'go list -f "{{.Dir}}" ./... | fgrep -v dokan | xargs realpath --relative-to=. | xargs golangci-lint run'
499+
def hasKBFSChanges = packagesToTest.keySet().findIndexOf { key -> key =~ /^github.com\/keybase\/client\/go\/kbfs/ } >= 0
500+
if (hasKBFSChanges) {
501+
println "Running golangci-lint on KBFS"
502+
dir('kbfs') {
503+
retry(5) {
504+
timeout(activity: true, time: 180, unit: 'SECONDS') {
505+
// Ignore the `dokan` directory since it contains lots of c code.
506+
// Ignore the `protocol` directory, autogeneration has some critques
507+
sh 'go list -f "{{.Dir}}" ./... | fgrep -v dokan | xargs realpath --relative-to=. | xargs golangci-lint run'
508+
}
507509
}
508510
}
509511
}
510-
}
511512

512-
if (env.CHANGE_TARGET) {
513-
println("Running golangci-lint on new code")
514-
fetchChangeTarget()
515-
def BASE_COMMIT_HASH = getBaseCommitHash()
516-
timeout(activity: true, time: 360, unit: 'SECONDS') {
517-
sh "go list -f '{{.Dir}}' ./... | fgrep -v kbfs | fgrep -v protocol | xargs realpath --relative-to=. | xargs golangci-lint run --new-from-rev ${BASE_COMMIT_HASH} --deadline 5m0s"
518-
}
513+
if (env.CHANGE_TARGET) {
514+
println("Running golangci-lint on new code")
515+
fetchChangeTarget()
516+
def BASE_COMMIT_HASH = getBaseCommitHash()
517+
timeout(activity: true, time: 360, unit: 'SECONDS') {
518+
sh "go list -f '{{.Dir}}' ./... | fgrep -v kbfs | fgrep -v protocol | xargs realpath --relative-to=. | xargs golangci-lint run --new-from-rev ${BASE_COMMIT_HASH} --deadline 5m0s"
519+
}
519520

520-
println("Running golangci-lint for dead code")
521-
timeout(activity: true, time: 360, unit: 'SECONDS') {
522-
def diffFileList = getDiffFileList()
523-
def diffPackageList = sh(returnStdout: true, script: "bash -c \"set -o pipefail; echo '${diffFileList}' | { grep '^go\\/' || true; } | { grep -v 'go/revision' || true; } | { grep -v 'go/vendor' || true; } | { grep -v 'go/Makefile' || true; } | sed 's/^go\\///' | sed 's/^\\(.*\\)\\/[^\\/]*\$/\\1/' | sort | uniq\"").trim().split()
524-
diffPackageList.each { pkg ->
525-
dir(pkg) {
526-
// Ignore the exit code 5, which indicates that there were
527-
// no files to analyze -- that's expected if the files were
528-
// all tagged for a different platform.
529-
sh 'golangci-lint run --no-config --disable-all --enable=deadcode --deadline 5m0s || test $? -eq 5'
521+
println("Running golangci-lint for dead code")
522+
timeout(activity: true, time: 360, unit: 'SECONDS') {
523+
def diffFileList = getDiffFileList()
524+
def diffPackageList = sh(returnStdout: true, script: "bash -c \"set -o pipefail; echo '${diffFileList}' | { grep '^go\\/' || true; } | { grep -v 'go/revision' || true; } | { grep -v 'go/vendor' || true; } | { grep -v 'go/Makefile' || true; } | sed 's/^go\\///' | sed 's/^\\(.*\\)\\/[^\\/]*\$/\\1/' | sort | uniq\"").trim().split()
525+
diffPackageList.each { pkg ->
526+
dir(pkg) {
527+
// Ignore the exit code 5, which indicates that there were
528+
// no files to analyze -- that's expected if the files were
529+
// all tagged for a different platform.
530+
sh 'golangci-lint run --no-config --disable-all --enable=deadcode --deadline 5m0s || test $? -eq 5'
531+
}
530532
}
531533
}
532534
}
533-
}
534535

535-
if (prefix == "test_linux_go_") {
536536
// Windows `gofmt` pukes on CRLF.
537537
// Macos pukes on mockgen because ¯\_(ツ)_/¯.
538538
// So, only run on Linux.

‎go/Makefile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ shavendorstellar:
8989
echo "expecting f3a7d9906dab5c481669b5b4f852bf447388bd3d:"
9090
find vendor/github.com/stellar -type f -print0 | sort -z | xargs -0 shasum | shasum
9191

92+
GOLANGCI_RUN_OPT = --color auto
93+
94+
golangci-lint-kbfs:
95+
go list -f '{{.Dir}}' ./kbfs/... | fgrep -v dokan | xargs realpath --relative-to=. | xargs golangci-lint run $(GOLANGCI_RUN_OPT) --deadline 5m0s
96+
97+
golangci-lint-nonkbfs:
98+
go list -f '{{.Dir}}' ./... | fgrep -v protocol | fgrep -v kbfs | xargs realpath --relative-to=. | xargs golangci-lint run $(GOLANGCI_RUN_OPT) --deadline 5m0s
99+
92100
.PHONY: test splint fmt lint vet cover testclean coverclient coverdaemon coverengine coverlibcmdline coverlibkb coverclean shavendorstellar gen-deps

‎go/avatars/utils.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func GetBorderedCircleAvatar(ctx context.Context, g *globals.Context, username s
9090

9191
result := image.NewRGBA(bounds)
9292

93-
draw.Draw(result, bounds, &circle{middle, borderedRadius, blue}, image.ZP, draw.Over)
94-
draw.Draw(result, bounds, &circle{middle, avatarRadius + innerBorder, white}, image.ZP, draw.Over)
95-
draw.DrawMask(result, iconRect, scaledAvatar, image.ZP, mask, image.ZP, draw.Over)
93+
draw.Draw(result, bounds, &circle{middle, borderedRadius, blue}, image.Point{}, draw.Over)
94+
draw.Draw(result, bounds, &circle{middle, avatarRadius + innerBorder, white}, image.Point{}, draw.Over)
95+
draw.DrawMask(result, iconRect, scaledAvatar, image.Point{}, mask, image.Point{}, draw.Over)
9696

9797
var buf bytes.Buffer
9898
err = png.Encode(&buf, result)

‎go/bind/keybase.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var kbSvc *service.Service
4444
var conn net.Conn
4545
var startOnce sync.Once
4646
var logSendContext status.LogSendContext
47-
var kbfsConfig libkbfs.Config
4847

4948
var initMutex sync.Mutex
5049
var initComplete bool
@@ -250,7 +249,7 @@ func Init(homeDir, mobileSharedHome, logFile, runModeStr string,
250249
// before KBFS-on-mobile is ready.
251250
kbfsParams.Debug = true // false
252251
kbfsParams.Mode = libkbfs.InitConstrainedString // libkbfs.InitMinimalString
253-
kbfsConfig, _ = libkbfs.Init(
252+
_, _ = libkbfs.Init(
254253
context.Background(), kbfsCtx, kbfsParams, serviceCn{}, func() error { return nil },
255254
kbCtx.Log)
256255
}()

‎go/chat/attachment_httpsrv.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ func (r *AttachmentHTTPSrv) genURLKey(prefix string, payload interface{}) (strin
108108
h := r.hmacPool.Get().(hash.Hash)
109109
defer r.hmacPool.Put(h)
110110
h.Reset()
111-
h.Write([]byte(prefix))
111+
_, _ = h.Write([]byte(prefix))
112112
var data []byte
113113
mh := codec.MsgpackHandle{WriteExt: true}
114114
if err := codec.NewEncoderBytes(&data, &mh).Encode(payload); err != nil {
115115
return "", err
116116
}
117-
h.Write(data)
117+
_, _ = h.Write(data)
118118
return prefix + hex.EncodeToString(h.Sum(nil)), nil
119119
}
120120

‎go/chat/attachments/preview.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func previewDimensions(origBounds image.Rectangle) (uint, uint) {
262262
func imageToPaletted(img image.Image) *image.Paletted {
263263
b := img.Bounds()
264264
pm := image.NewPaletted(b, palette.Plan9)
265-
draw.FloydSteinberg.Draw(pm, b, img, image.ZP)
265+
draw.FloydSteinberg.Draw(pm, b, img, image.Point{})
266266
return pm
267267
}
268268

‎go/chat/maps/maps.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func DecorateMap(ctx context.Context, avatarReader, mapReader io.Reader) (res io
125125
iconRect := image.Rect(middle.X-avatarRadius, middle.Y-avatarRadius, middle.X+avatarRadius, middle.Y+avatarRadius)
126126

127127
decorated := image.NewRGBA(bounds)
128-
draw.Draw(decorated, bounds, mapPng, image.ZP, draw.Src)
129-
draw.Draw(decorated, iconRect, avatarImg, image.ZP, draw.Over)
128+
draw.Draw(decorated, bounds, mapPng, image.Point{}, draw.Src)
129+
draw.Draw(decorated, iconRect, avatarImg, image.Point{}, draw.Over)
130130

131131
var buf bytes.Buffer
132132
err = png.Encode(&buf, decorated)

‎go/chat/push.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
656656
g.Debug(ctx, "chat activity: readMessage: convID: %s msgID: %d", nm.ConvID, nm.MsgID)
657657

658658
uid := m.UID().Bytes()
659-
if conv, err = g.G().InboxSource.ReadMessage(ctx, uid, nm.InboxVers, nm.ConvID, nm.MsgID); err != nil {
659+
if _, err = g.G().InboxSource.ReadMessage(ctx, uid, nm.InboxVers, nm.ConvID, nm.MsgID); err != nil {
660660
g.Debug(ctx, "chat activity: unable to update inbox: %v", err)
661661
}
662662
case types.ActionSetStatus:
@@ -668,7 +668,8 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
668668
g.Debug(ctx, "chat activity: setStatus: convID: %s status: %d", nm.ConvID, nm.Status)
669669

670670
uid := m.UID().Bytes()
671-
if conv, err = g.G().InboxSource.SetStatus(ctx, uid, nm.InboxVers, nm.ConvID, nm.Status); err != nil {
671+
conv, err = g.G().InboxSource.SetStatus(ctx, uid, nm.InboxVers, nm.ConvID, nm.Status)
672+
if err != nil {
672673
g.Debug(ctx, "chat activity: unable to update inbox: %v", err)
673674
}
674675
activity = new(chat1.ChatActivity)

‎go/chat/sender_test.go‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,6 @@ func (n *chatListener) consumeConvUpdate(t *testing.T) chat1.ConversationID {
159159
}
160160
}
161161

162-
func (n *chatListener) consumeThreadsStale(t *testing.T) []chat1.ConversationStaleUpdate {
163-
select {
164-
case x := <-n.threadsStale:
165-
return x
166-
case <-time.After(20 * time.Second):
167-
require.Fail(t, "failed to get threadsStale notification")
168-
return nil
169-
}
170-
}
171-
172162
func newConvTriple(ctx context.Context, t *testing.T, tc *kbtest.ChatTestContext, username string) chat1.ConversationIDTriple {
173163
return newConvTripleWithMembersType(ctx, t, tc, username, chat1.ConversationMembersType_IMPTEAMNATIVE)
174164
}

‎go/chat/server.go‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ func (h *Server) GetInboxAndUnboxLocal(ctx context.Context, arg chat1.GetInboxAn
275275
// Read inbox from the source
276276
ib, _, err := h.G().InboxSource.Read(ctx, uid, types.ConversationLocalizerBlocking,
277277
types.InboxSourceDataSourceAll, nil, arg.Query)
278-
if err != nil {
279-
if _, ok := err.(UnknownTLFNameError); ok {
280-
h.Debug(ctx, "GetInboxAndUnboxLocal: got unknown TLF name error, returning blank results")
281-
ib.Convs = nil
282-
} else {
283-
return res, err
284-
}
278+
switch err.(type) {
279+
case nil:
280+
case UnknownTLFNameError:
281+
h.Debug(ctx, "GetInboxAndUnboxLocal: got unknown TLF name error, returning blank results")
282+
ib.Convs = nil
283+
default:
284+
return res, err
285285
}
286286

287287
return chat1.GetInboxAndUnboxLocalRes{
@@ -304,13 +304,13 @@ func (h *Server) GetInboxAndUnboxUILocal(ctx context.Context, arg chat1.GetInbox
304304
// Read inbox from the source
305305
ib, _, err := h.G().InboxSource.Read(ctx, uid, types.ConversationLocalizerBlocking,
306306
types.InboxSourceDataSourceAll, nil, arg.Query)
307-
if err != nil {
308-
if _, ok := err.(UnknownTLFNameError); ok {
309-
h.Debug(ctx, "GetInboxAndUnboxUILocal: got unknown TLF name error, returning blank results")
310-
ib.Convs = nil
311-
} else {
312-
return res, err
313-
}
307+
switch err.(type) {
308+
case nil:
309+
case UnknownTLFNameError:
310+
h.Debug(ctx, "GetInboxAndUnboxUILocal: got unknown TLF name error, returning blank results")
311+
ib.Convs = nil
312+
default:
313+
return res, err
314314
}
315315
return chat1.GetInboxAndUnboxUILocalRes{
316316
Conversations: utils.PresentConversationLocals(ctx, h.G(), uid, ib.Convs,

0 commit comments

Comments
 (0)