Skip to content

Commit

Permalink
stfu linter
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 10, 2024
1 parent cfbe5b5 commit 2434c9d
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 125 deletions.
42 changes: 21 additions & 21 deletions auth/auth_ui/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ var (
ErrRequired = errors.New("can not be empty")
)

func valURLSafe(s string) error {
for _, c := range s {
if !isRuneURLSafe(c) {
return ErrNotURLSafe
}
}
return nil
}
// func valURLSafe(s string) error {
// for _, c := range s {
// if !isRuneURLSafe(c) {
// return ErrNotURLSafe
// }
// }
// return nil
// }

func isRuneURLSafe(r rune) bool {
switch {
case 'a' <= r && r <= 'z':
return true
case 'A' <= r && r <= 'Z':
return true
case '0' <= r && r <= '9':
return true
case r == '-' || r == '.' || r == '_' || r == '~':
return true
}
return false
}
// func isRuneURLSafe(r rune) bool {
// switch {
// case 'a' <= r && r <= 'z':
// return true
// case 'A' <= r && r <= 'Z':
// return true
// case '0' <= r && r <= '9':
// return true
// case r == '-' || r == '.' || r == '_' || r == '~':
// return true
// }
// return false
// }

func valRequired(s string) error {
if s == "" {
Expand Down
6 changes: 5 additions & 1 deletion auth/browser/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func (cl *Client) Authenticate(ctx context.Context) (string, []*http.Cookie, err
if err != nil {
return "", nil, err
}
defer pw.Stop()
defer func() {
if err := pw.Stop(); err != nil {
l().Printf("failed to stop playwright: %v", err)
}
}()

opts := playwright.BrowserTypeLaunchOptions{
Headless: _b(false),
Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"os"
"strings"

"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/armor"
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
"golang.org/x/crypto/openpgp/packet"
)

// pub rsa4096 2020-03-22 [SC] [expires: 2029-03-21]
Expand Down
5 changes: 4 additions & 1 deletion cmd/slackdump/internal/diag/rawoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ func sendReq(w io.Writer, cl *http.Client, ep string, v url.Values) (bool, error
log.Printf("error while retrieving body: %s", err)
}
if resp.StatusCode != http.StatusOK {
io.Copy(w, bytes.NewReader(data))
_, err := io.Copy(w, bytes.NewReader(data))
if err != nil {
return false, err
}
return false, fmt.Errorf("server NOT OK: %s", resp.Status)
}
if len(data) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion cmd/slackdump/internal/diag/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ func runSearch(ctx context.Context, cmd *base.Command, args []string) error {
lg.Printf("cursor %s", sm.NextCursor)
p.Cursor = sm.NextCursor

lim.Wait(ctx)
if err := lim.Wait(ctx); err != nil {
return err
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/diag/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func generateThread(ctx context.Context, client *slack.Client, channelID string,
l := network.NewLimiter(network.Tier3, network.DefLimits.Tier3.Burst, int(network.DefLimits.Tier3.Boost))
pb := progressbar.Default(int64(numMsg))
pb.Describe("posting messages")
defer pb.Finish()
defer func() { _ = pb.Finish() }()
for i := 0; i < numMsg; i++ {
if err := network.WithRetry(ctx, l, 3, func() error {
_, _, err := client.PostMessageContext(ctx, channelID, slack.MsgOptionTS(ts), slack.MsgOptionText(fmt.Sprintf("message: %d", i), false))
Expand Down Expand Up @@ -144,7 +144,7 @@ func delMessages(ctx context.Context, client *slack.Client, channelID string, ms
pb := progressbar.Default(int64(len(msgs)))
pb.Describe("deleting messages")

defer pb.Finish()
defer func() { _ = pb.Finish() }()

l := network.NewLimiter(network.Tier3, network.DefLimits.Tier3.Burst, int(network.DefLimits.Tier3.Boost))
for _, m := range msgs {
Expand Down
5 changes: 0 additions & 5 deletions cmd/slackdump/internal/emoji/emojidl/emoji_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"reflect"
"sync"
"testing"
"time"

"go.uber.org/mock/gomock"

Expand All @@ -37,10 +36,6 @@ func setGlobalFetchFn(fn fetchFunc) {
fetchFn = fn
}

func init() {
rand.Seed(time.Now().UnixNano())
}

func Test_fetchEmoji(t *testing.T) {
type args struct {
ctx context.Context
Expand Down
10 changes: 5 additions & 5 deletions cmd/slackdump/internal/export/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func exportV3(ctx context.Context, sess *slackdump.Session, fsa fsadapter.FS, li
}
defer chunkdir.Close()
if !lg.IsDebug() {
defer chunkdir.RemoveAll()
defer func() { _ = chunkdir.RemoveAll() }()
}
updFn := func() func(_ *slack.Channel, m *slack.Message) error {
// hack: wrapper around the message update function, which does not
Expand All @@ -63,15 +63,15 @@ func exportV3(ctx context.Context, sess *slackdump.Session, fsa fsadapter.FS, li
progressbar.OptionSpinnerType(8)),
lg.IsDebug(),
)
pb.RenderBlank()
_ = pb.RenderBlank()

stream := sess.Stream(
stream.OptOldest(params.Oldest),
stream.OptLatest(params.Latest),
stream.OptResultFn(func(sr stream.Result) error {
lg.Debugf("conversations: %s", sr.String())
pb.Describe(sr.String())
pb.Add(1)
_ = pb.Add(1)
return nil
}),
)
Expand All @@ -90,10 +90,10 @@ func exportV3(ctx context.Context, sess *slackdump.Session, fsa fsadapter.FS, li

lg.Print("running export...")
if err := ctr.Run(ctx, list); err != nil {
pb.Finish()
_ = pb.Finish()
return err
}
pb.Finish()
_ = pb.Finish()
// at this point no goroutines are running, we are safe to assume that
// everything we need is in the chunk directory.
if err := conv.WriteIndex(); err != nil {
Expand Down
26 changes: 0 additions & 26 deletions cmd/slackdump/internal/export/v3_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package export

import (
"bytes"
"compress/gzip"
"context"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -93,26 +90,3 @@ func Test_exportV3(t *testing.T) {
}
})
}

func load(t *testing.T, filename string) io.ReadSeeker {
absPath, err := filepath.Abs(filename)
if err != nil {
t.Fatal(err)
}
t.Log("test file", absPath)
f, err := os.Open(absPath)
if err != nil {
t.Fatal(err)
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
t.Fatal(err)
}
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
if err != nil {
t.Fatal(err)
}
return bytes.NewReader(buf.Bytes())
}
6 changes: 5 additions & 1 deletion cmd/slackdump/internal/golang/base/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ func YesNoWR(w io.Writer, r io.Reader, message string) bool {
for {
fmt.Fprint(w, message, "? (y/N) ")
var resp string
fmt.Fscanln(r, &resp)
_, err := fmt.Fscanln(r, &resp)
if err != nil {
fmt.Fprintln(w, "Please answer yes or no and press Enter or Return.")
continue
}
resp = strings.TrimSpace(resp)
if len(resp) > 0 {
switch strings.ToLower(resp)[0] {
Expand Down
1 change: 0 additions & 1 deletion cmd/slackdump/internal/list/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (u *users) Retrieve(ctx context.Context, sess *slackdump.Session, m *cache.
if err != nil {
return err
}
m.CacheUsers(sess.Info().TeamID, users)
u.data = users
return nil
}
Expand Down
1 change: 0 additions & 1 deletion cmd/slackdump/internal/ui/ask/timerange.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TimeRange() (oldest, latest time.Time, err error) {
if oldest, err = ui.Time("Earliest message"); err != nil && !errors.Is(err, ui.ErrEmptyOptionalInput) {
return
}
err = nil
if latest, err = ui.Time("Latest message"); err != nil && !errors.Is(err, ui.ErrEmptyOptionalInput) {
return
}
Expand Down
7 changes: 0 additions & 7 deletions cmd/slackdump/internal/ui/bubbles/btime/btime.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,6 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
return m, nil
}

func (m *Model) whatIf(digit int, hasVal int) int {
whatIf := make([]int, len(m.entry))
copy(whatIf, m.entry[:])
whatIf[digit] = hasVal
return tupleVal(whatIf, m.cursor/2)
}

func (m *Model) updateTime() {
hour := tupleVal(m.entry[:], 0)
minute := tupleVal(m.entry[:], 1)
Expand Down
30 changes: 0 additions & 30 deletions cmd/slackdump/internal/wizard/config.go

This file was deleted.

6 changes: 4 additions & 2 deletions downloader/deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
file9 = slack.File{ID: "f9", Name: "filename9.ext", URLPrivateDownload: "file9_url", Size: 900}
)

// TODO: figure out why this is deprecated.

func TestSession_SaveFileTo(t *testing.T) {
tmpdir := t.TempDir()

Expand Down Expand Up @@ -73,7 +75,7 @@ func TestSession_SaveFileTo(t *testing.T) {
func(mc *mock_downloader.MockDownloader) {
mc.EXPECT().
GetFile("file1_url", gomock.Any()).
SetArg(1, *fixtures.FilledFile(file1.Size)). // to mock the file size.
SetArg(1, *fixtures.FilledFile(t, file1.Size)). // to mock the file size.
Return(nil)
},
int64(file1.Size),
Expand Down Expand Up @@ -171,7 +173,7 @@ func TestSession_saveFile(t *testing.T) {
func(mc *mock_downloader.MockDownloader) {
mc.EXPECT().
GetFile("file1_url", gomock.Any()).
SetArg(1, *fixtures.FilledFile(file1.Size)).
SetArg(1, *fixtures.FilledFile(t, file1.Size)).
Return(nil)
},
int64(file1.Size),
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23

require (
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403
github.com/ProtonMail/go-crypto v1.1.2
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.2
github.com/charmbracelet/huh v0.6.0
Expand Down Expand Up @@ -36,7 +37,6 @@ require (
github.com/yuin/goldmark v1.7.8
github.com/yuin/goldmark-emoji v1.0.4
go.uber.org/mock v0.5.0
golang.org/x/crypto v0.28.0
golang.org/x/sync v0.8.0
golang.org/x/term v0.25.0
golang.org/x/text v0.19.0
Expand All @@ -52,6 +52,7 @@ require (
github.com/charmbracelet/x/ansi v0.4.2 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20241101155414-3df16cb7eefd // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand Down Expand Up @@ -81,6 +82,7 @@ require (
github.com/ysmood/gson v0.7.3 // indirect
github.com/ysmood/leakless v0.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403 h1:EtZwYyLbkEcIt+B//6sujwRCnHuTEK3qiSypAX5aJeM=
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403/go.mod h1:mM6WvakkX2m+NgMiPCfFFjwfH4KzENC07zeGEqq9U7s=
github.com/ProtonMail/go-crypto v1.1.2 h1:A7JbD57ThNqh7XjmHE+PXpQ3Dqt3BrSAC0AL0Go3KS0=
github.com/ProtonMail/go-crypto v1.1.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand All @@ -14,8 +16,6 @@ github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQW
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc=
github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E=
github.com/charmbracelet/huh v0.5.3 h1:3KLP4a/K1/S4dq4xFMTNMt3XWhgMl/yx8NYtygQ0bmg=
github.com/charmbracelet/huh v0.5.3/go.mod h1:OZC3lshuF+/y8laj//DoZdFSHxC51OrtXLJI8xWVouQ=
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
github.com/charmbracelet/huh/spinner v0.0.0-20241028115900-20a4d21717a8 h1:g+Bz64hsMLTf3lAgUqI6Rj1YEAlm/HN39IuhyneCokc=
Expand All @@ -32,6 +32,8 @@ github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4h
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -133,8 +135,6 @@ github.com/rusq/rbubbles v0.0.2 h1:U+rkywxtmBw0fdXABTCyND2YUZW9xydsxE12Co0tsFA=
github.com/rusq/rbubbles v0.0.2/go.mod h1:wOrwl1AiCCmaL9fLnjKDajOP4IglSC84fH7a74VsnLk=
github.com/rusq/secure v0.0.4 h1:svpiZHfHnx89eEDCCFI9OXG1Y8hL9kUWUG6fJbrWUOI=
github.com/rusq/secure v0.0.4/go.mod h1:F1QilMKreuFRjov0UY7DZSIXn77/8RqMVGu2zV0RtqY=
github.com/rusq/slack v0.9.6-0.20240712095442-5a0e2e405a99 h1:dqEcNs9hMc2PiMwhw8+Zi3wF8GNUHIK5OItZ01iM0Vk=
github.com/rusq/slack v0.9.6-0.20240712095442-5a0e2e405a99/go.mod h1:9O0zQAFN6W47z4KpTQbe6vOHOzBO76vMg1+gthPwaTI=
github.com/rusq/slack v0.9.6-0.20241104074952-d9b6e02955fa h1:meNaDH2eLwjAqvOxMlgb5+gaLz3Kufm9rVFkALhsCRs=
github.com/rusq/slack v0.9.6-0.20241104074952-d9b6e02955fa/go.mod h1:9O0zQAFN6W47z4KpTQbe6vOHOzBO76vMg1+gthPwaTI=
github.com/rusq/slackauth v0.5.1 h1:l+Gj96kYzHmljMYglRv76kgzuOJr/QbXDDA8JHyN71Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func initProvider(ctx context.Context, cacheDir string, filename string, workspa
if creds == nil || creds.IsEmpty() {
if prov, err := tryLoad(ctx, credsFile); err != nil {
msg := fmt.Sprintf("failed to load saved credentials: %s", err)
trace.Logf(ctx, "warn", msg)
trace.Log(ctx, "warn", msg)
if auth.IsInvalidAuthErr(err) {
lg.Println("authentication details expired, relogin is necessary")
}
Expand Down
Loading

0 comments on commit 2434c9d

Please sign in to comment.