Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update golangci-lint to v1.62.0 and fix reported issues. #418

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ jobs:
- name: Get sources
uses: actions/checkout@v3

- name: Set up Go 1.21
- name: Set up Go 1.23.3
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.23.3'

- name: Run go mod tidy
run: go mod tidy

- name: Run golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@251ceaa228607dd3e0371694a1ab2c45d21cb744
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0
golangci-lint run --timeout=500s

- name: Run govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.21
go-version-input: 1.23
go-package: ./...

- name: Run tests
Expand Down
14 changes: 6 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
run:
go: 1.21
skip-files:
- internal/parser/parser.go
- internal/parser/extern
go: 1.23

linters:
presets:
- bugs
- comment
enable:
- wsl
disable:
- godox # Annoying, we have too many TODOs at the moment :p
- scopelint # Deprecated, replaced by exportloopref, which is enabled by default.
- musttag # We do not want to force annotating every field name.
- errorlint # Too many false positives

issues:
exclude-rules:
- path: benchmarks
Expand All @@ -27,3 +21,7 @@ issues:
- path: _test\.go
linters:
- dupword
linters-settings:
gosec:
excludes:
- G115 # Potential integer overflow when converting between integer types
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/gluon_benchmarks/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *Sync) Setup(ctx context.Context, benchmarkDir string) error {
gluon.WithLogger(loggerIn, loggerOut),
}

server, err := gluon.New(opts...)
server, err := gluon.New(opts...) //nolint:contextcheck
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/imap_benchmarks/server/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (*LocalServerBuilder) New(ctx context.Context, serverPath string, profiler
opts = append(opts, gluon.WithDataDir(serverPath))
opts = append(opts, gluon.WithDatabaseDir(serverPath))

server, err := gluon.New(opts...)
server, err := gluon.New(opts...) //nolint:contextcheck
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/reporter/json_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (j *JSONReporter) ProduceReport(reports []*BenchmarkReport) error {
return err
}

return os.WriteFile(j.outputPath, []byte(result), 0o600)
return os.WriteFile(j.outputPath, result, 0o600)
}

func NewJSONReporter(output string) *JSONReporter {
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/imaptest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
allowParallel = false
doFullIMAPtestLog = false
doFullIMAPTestLog = false
gluonLogLevel = "warn"
ignoreRecentError = true
)
Expand Down Expand Up @@ -120,14 +120,14 @@ func newScenario(c caseConfig, settingName string, s settingsConfig, port int) (
port: fmt.Sprintf("%d", port),
users: c.Users,
name: fmt.Sprintf("u%d_c%d_%s", c.Users, c.Clients, settingName),
timeout: time.Duration(time.Second),
timeout: time.Second,
}

if secs, err := strconv.Atoi(s["secs"]); err == nil {
sc.timeout = time.Duration(secs) * 2 * time.Second
}

// coomon arguments
// Common arguments
sc.imaptestParams = []string{
"host=127.0.0.1",
fmt.Sprintf("port=%d", port),
Expand Down Expand Up @@ -202,13 +202,13 @@ func (s *scenario) runGluon() {

fmt.Printf("Gluon[%s]:\n%s\nGluonEnd[%s]\n", s.name, out.String(), s.name)

assert.Error(s.t, err)
require.Error(s.t, err)
assert.Equal(s.t, "signal: killed", err.Error())
}

func (s *scenario) runIMAPTest() {
logPath := ""
if doFullIMAPtestLog {
if doFullIMAPTestLog {
logPath = s.t.TempDir() + "imaptest.log"
s.imaptestParams = append(s.imaptestParams, "output="+logPath)
}
Expand All @@ -223,12 +223,12 @@ func (s *scenario) runIMAPTest() {

fmt.Printf("IMAPTEST[%s]: %q\n%s\nIMAPTESTEND[%s]\n", s.name, s.imaptestParams, out.String(), s.name)

assert.NoError(s.t, err)
require.NoError(s.t, err)
assert.False(s.t, hasIMAPLogAnError(out.Bytes(), ignoreRecentError), "Error(s) found in imaptest log.")

if doFullIMAPtestLog {
if doFullIMAPTestLog {
log, err := os.ReadFile(logPath)
assert.NoError(s.t, err)
require.NoError(s.t, err)
fmt.Println("LOG", s.name, "\n", string(log), "\nLOG", s.name, "END")
}
}
Expand Down
6 changes: 3 additions & 3 deletions imap/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func TestFlagSet_Len(t *testing.T) {
}

func TestFlagSet_ToSlice(t *testing.T) {
require.True(t, len(NewFlagSet().ToSlice()) == 0)
require.Empty(t, NewFlagSet().ToSlice())

fs := NewFlagSet("flag1", "flag2", "FLAG2", "flag3")
require.True(t, len(fs.ToSlice()) == 3)
require.Len(t, fs.ToSlice(), 3)

// Check that we return a hard copy.
fs = NewFlagSet("flag1", "flag2", "flag3")
sl := fs.ToSlice()
require.Equal(t, 3, len(sl))
require.Len(t, sl, 3)

// Modify something in the returned slice.
sl[0] = "flag2"
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (b *Backend) GetState(ctx context.Context, username string, password []byte
return nil, err
}

state, err := b.users[userID].newState()
state, err := b.users[userID].newState() //nolint:contextcheck
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/db_impl/sqlite3/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sqlite3
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"testing"
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestMigration_VersionTooHigh(t *testing.T) {

err = client.Init(context.Background(), imap.DefaultEpochUIDValidityGenerator())
require.Error(t, err)
require.True(t, errors.Is(err, db.ErrInvalidDatabaseVersion))
require.ErrorIs(t, err, db.ErrInvalidDatabaseVersion)
}

func TestRunMigrations(t *testing.T) {
Expand All @@ -73,7 +72,7 @@ func TestRunMigrations(t *testing.T) {
runAndValidateDB(t, testDir, "foo", testData, uidGenerator)
}

func TestMigration_ConnectorSettingsEmtpyOnFirstUse(t *testing.T) {
func TestMigration_ConnectorSettingsEmptyOnFirstUse(t *testing.T) {
testDir := t.TempDir()

client, _, err := NewClient(testDir, "foo", false, false)
Expand Down Expand Up @@ -197,7 +196,7 @@ func runAndValidateDB(t *testing.T, testDir, user string, testData *testData, ui
return result.InternalID == m.messageID
})

require.True(t, idx >= 0)
require.GreaterOrEqual(t, idx, 0)

require.Equal(t, m.recent, msg[idx].Recent)
require.Equal(t, m.deleted, msg[idx].Deleted)
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Session) handleExamine(ctx context.Context, tag string, cmd *command.Ex
}

ch <- response.Flags().WithFlags(flags)
ch <- response.Exists().WithCount(imap.SeqID(mailbox.Count()))
ch <- response.Exists().WithCount(imap.SeqID(uint32(mailbox.Count())))
ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent)))
ch <- response.Ok().WithItems(response.ItemPermanentFlags(permFlags))
ch <- response.Ok().WithItems(response.ItemUIDNext(uidNext))
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Session) handleSelect(ctx context.Context, tag string, cmd *command.Sel
}

ch <- response.Flags().WithFlags(flags)
ch <- response.Exists().WithCount(imap.SeqID(mailbox.Count()))
ch <- response.Exists().WithCount(imap.SeqID(uint32(mailbox.Count())))
ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent)))
ch <- response.Ok().WithItems(response.ItemPermanentFlags(permFlags)).WithMessage("Flags permitted")
ch <- response.Ok().WithItems(response.ItemUIDNext(uidNext)).WithMessage("Predicted next UID")
Expand Down
2 changes: 1 addition & 1 deletion internal/state/mailbox_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m *Mailbox) Search(ctx context.Context, keys []command.SearchKey, decoder
if err := parallel.DoContext(ctx, parallelism, msgCount, func(ctx context.Context, i int) error {
defer async.HandlePanic(m.state.panicHandler)

msg, ok := m.snap.messages.getWithSeqID(imap.SeqID(i + 1))
msg, ok := m.snap.messages.getWithSeqID(imap.SeqID(uint32(i + 1)))
if !ok {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/state/responders.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (u *targetedExists) handle(ctx context.Context, snap *snapshot, stateID Sta
}
}

res := []response.Response{response.Exists().WithCount(imap.SeqID(snap.messages.len()))}
res := []response.Response{response.Exists().WithCount(imap.SeqID(uint32(snap.messages.len())))}

var dbUpdate responderDBUpdate

Expand Down
6 changes: 3 additions & 3 deletions internal/state/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (snap *snapshot) getAllMessages() []snapMsgWithSeq {

for i, v := range allMessages {
result[i] = snapMsgWithSeq{
Seq: imap.SeqID(i + 1),
Seq: imap.SeqID(uint32(i + 1)),
snapMsg: v,
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func (snap *snapshot) firstMessageWithFlag(flag string) (snapMsgWithSeq, bool) {

for i, msg := range snap.messages.msg {
if msg.flags.ContainsUnchecked(flagLower) {
return snapMsgWithSeq{Seq: imap.SeqID(i + 1), snapMsg: msg}, true
return snapMsgWithSeq{Seq: imap.SeqID(uint32(i + 1)), snapMsg: msg}, true
}
}

Expand All @@ -196,7 +196,7 @@ func (snap *snapshot) firstMessageWithoutFlag(flag string) (snapMsgWithSeq, bool

for i, msg := range snap.messages.msg {
if !msg.flags.ContainsUnchecked(flagLower) {
return snapMsgWithSeq{Seq: imap.SeqID(i + 1), snapMsg: msg}, true
return snapMsgWithSeq{Seq: imap.SeqID(uint32(i + 1)), snapMsg: msg}, true
}
}

Expand Down
22 changes: 11 additions & 11 deletions internal/state/snapshot_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (list *snapMsgList) where(fn func(seq snapMsgWithSeq) bool) []snapMsgWithSe
for idx, i := range list.msg {
snapWithSeq := snapMsgWithSeq{
snapMsg: i,
Seq: imap.SeqID(idx + 1),
Seq: imap.SeqID(uint32(idx + 1)),
}

if fn(snapWithSeq) {
Expand All @@ -148,7 +148,7 @@ func (list *snapMsgList) whereCount(fn func(seq snapMsgWithSeq) bool) int {
for idx, i := range list.msg {
snapWithSeq := snapMsgWithSeq{
snapMsg: i,
Seq: imap.SeqID(idx + 1),
Seq: imap.SeqID(uint32(idx + 1)),
}

if fn(snapWithSeq) {
Expand Down Expand Up @@ -177,13 +177,13 @@ func (list *snapMsgList) get(msgID imap.InternalMessageID) (snapMsgWithSeq, bool
}

return snapMsgWithSeq{
Seq: imap.SeqID(index + 1),
Seq: imap.SeqID(uint32(index + 1)),
snapMsg: list.msg[index],
}, ok
}

func (list *snapMsgList) seq(seq imap.SeqID) (snapMsgWithSeq, bool) {
if imap.SeqID(len(list.msg)) < seq {
if imap.SeqID(uint32(len(list.msg))) < seq {
return snapMsgWithSeq{}, false
}

Expand All @@ -195,7 +195,7 @@ func (list *snapMsgList) seq(seq imap.SeqID) (snapMsgWithSeq, bool) {

func (list *snapMsgList) last() snapMsgWithSeq {
return snapMsgWithSeq{
Seq: imap.SeqID(len(list.msg)),
Seq: imap.SeqID(uint32(len(list.msg))),
snapMsg: list.msg[len(list.msg)-1],
}
}
Expand All @@ -205,7 +205,7 @@ func (list *snapMsgList) seqRange(seqLo, seqHi imap.SeqID) []snapMsgWithSeq {
result := make([]snapMsgWithSeq, len(interval))

for i, v := range interval {
result[i].Seq = imap.SeqID(int(seqLo) + i)
result[i].Seq = imap.SeqID(uint32(seqLo) + uint32(i))
result[i].snapMsg = v
}

Expand Down Expand Up @@ -234,7 +234,7 @@ func (list *snapMsgList) uidRange(uidLo, uidHi imap.UID) []snapMsgWithSeq {
result := make([]snapMsgWithSeq, len(interval))

for i, v := range interval {
result[i].Seq = imap.SeqID(indexLo + i + 1)
result[i].Seq = imap.SeqID(uint32(indexLo + i + 1))
result[i].snapMsg = v
}

Expand All @@ -248,7 +248,7 @@ func (list *snapMsgList) getWithUID(uid imap.UID) (snapMsgWithSeq, bool) {
}

return snapMsgWithSeq{
Seq: imap.SeqID(index + 1),
Seq: imap.SeqID(uint32(index + 1)),
snapMsg: list.msg[index],
}, ok
}
Expand Down Expand Up @@ -380,10 +380,10 @@ func (list *snapMsgList) resolveUIDInterval(seqSet []command.SeqRange) ([]UIDInt
// - when used in a range, the order of the indexes in irrelevant.
func (list *snapMsgList) resolveSeq(number command.SeqNum) (imap.SeqID, error) {
if number == command.SeqNumValueAsterisk {
return imap.SeqID(list.len()), nil
return imap.SeqID(uint32(list.len())), nil
}

return imap.SeqID(number), nil
return imap.SeqID(uint32(number)), nil
}

// resolveUID converts a textual message UID into an integer.
Expand All @@ -396,7 +396,7 @@ func (list *snapMsgList) resolveUID(number command.SeqNum) (imap.UID, error) {
return list.last().UID, nil
}

return imap.UID(number), nil
return imap.UID(uint32(number)), nil
}

func (list *snapMsgList) getMessagesInSeqRange(seqSet []command.SeqRange) ([]snapMsgWithSeq, error) {
Expand Down
Loading
Loading