Enable stricter linting with golangci-lint (#316)

* update golangci-lint

* add golangci config file w/ more linters

* correct issues flagged by stricter linters

* add more generous timeout for golangci-lint

* add some style + formatting guidelines

* move timeout to config file

* go fmt
This commit is contained in:
tobi 2021-11-22 08:46:19 +01:00 committed by GitHub
commit f8630348b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 227 additions and 163 deletions

View file

@ -137,8 +137,7 @@ func (a *accountDB) GetInstanceAccount(ctx context.Context, domain string) (*gts
WhereGroup(" AND ", whereEmptyOrNull("domain"))
}
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, a.conn.ProcessError(err)
}
return account, nil
@ -155,8 +154,7 @@ func (a *accountDB) GetAccountLastPosted(ctx context.Context, accountID string)
Where("account_id = ?", accountID).
Column("created_at")
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return time.Time{}, a.conn.ProcessError(err)
}
return status.CreatedAt, nil
@ -168,11 +166,12 @@ func (a *accountDB) SetAccountHeaderOrAvatar(ctx context.Context, mediaAttachmen
}
var headerOrAVI string
if mediaAttachment.Avatar {
switch {
case mediaAttachment.Avatar:
headerOrAVI = "avatar"
} else if mediaAttachment.Header {
case mediaAttachment.Header:
headerOrAVI = "header"
} else {
default:
return errors.New("given media attachment was neither a header nor an avatar")
}
@ -202,8 +201,7 @@ func (a *accountDB) GetLocalAccountByUsername(ctx context.Context, username stri
Where("username = ?", username).
WhereGroup(" AND ", whereEmptyOrNull("domain"))
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, a.conn.ProcessError(err)
}
return account, nil
@ -308,8 +306,7 @@ func (a *accountDB) GetAccountBlocks(ctx context.Context, accountID string, maxI
fq = fq.Limit(limit)
}
err := fq.Scan(ctx)
if err != nil {
if err := fq.Scan(ctx); err != nil {
return nil, "", "", a.conn.ProcessError(err)
}

View file

@ -54,7 +54,7 @@ const (
dbTypeSqlite = "sqlite"
)
var registerTables []interface{} = []interface{}{
var registerTables = []interface{}{
&gtsmodel.StatusToEmoji{},
&gtsmodel.StatusToTag{},
}
@ -220,7 +220,7 @@ func sqliteConn(ctx context.Context, c *config.Config) (*DBConn, error) {
}
tweakConnectionValues(sqldb)
if c.DBConfig.Address == "file::memory:?cache=shared" {
logrus.Warn("sqlite in-memory database should only be used for debugging")
// don't close connections on disconnect -- otherwise
@ -248,11 +248,11 @@ func pgConn(ctx context.Context, c *config.Config) (*DBConn, error) {
if err != nil {
return nil, fmt.Errorf("could not create bundb postgres options: %s", err)
}
sqldb := stdlib.OpenDB(*opts)
tweakConnectionValues(sqldb)
conn := WrapDBConn(bun.NewDB(sqldb, pgdialect.New()))
// ping to check the db is there and listening
@ -305,6 +305,7 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
case config.DBTLSModeDisable, config.DBTLSModeUnset:
break // nothing to do
case config.DBTLSModeEnable:
/* #nosec G402 */
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
@ -312,6 +313,7 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) {
tlsConfig = &tls.Config{
InsecureSkipVerify: false,
ServerName: c.DBConfig.Address,
MinVersion: tls.VersionTLS12,
}
}

View file

@ -116,8 +116,7 @@ func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, max
q = q.Limit(limit)
}
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, i.conn.ProcessError(err)
}
return accounts, nil

View file

@ -45,8 +45,7 @@ func (m *mediaDB) GetAttachmentByID(ctx context.Context, id string) (*gtsmodel.M
q := m.newMediaQ(attachment).
Where("media_attachment.id = ?", id)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, m.conn.ProcessError(err)
}
return attachment, nil

View file

@ -61,8 +61,7 @@ func (m *mentionDB) getMentionDB(ctx context.Context, id string) (*gtsmodel.Ment
q := m.newMentionQ(mention).
Where("mention.id = ?", id)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, m.conn.ProcessError(err)
}

View file

@ -125,8 +125,7 @@ func (n *notificationDB) getNotificationDB(ctx context.Context, id string, dst *
q := n.newNotificationQ(dst).
Where("notification.id = ?", id)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return n.conn.ProcessError(err)
}

View file

@ -74,8 +74,7 @@ func (r *relationshipDB) GetBlock(ctx context.Context, account1 string, account2
Where("block.account_id = ?", account1).
Where("block.target_account_id = ?", account2)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return block, nil
@ -286,8 +285,7 @@ func (r *relationshipDB) GetAccountFollowRequests(ctx context.Context, accountID
q := r.newFollowQ(&followRequests).
Where("target_account_id = ?", accountID)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return followRequests, nil
@ -299,8 +297,7 @@ func (r *relationshipDB) GetAccountFollows(ctx context.Context, accountID string
q := r.newFollowQ(&follows).
Where("account_id = ?", accountID)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, r.conn.ProcessError(err)
}
return follows, nil

View file

@ -47,7 +47,7 @@ func (s *sessionDB) GetSession(ctx context.Context) (*gtsmodel.RouterSession, db
return nil, s.conn.ProcessError(err)
}
if len(rss) <= 0 {
if len(rss) == 0 {
// no session created yet, so make one
return s.createSession(ctx)
}

View file

@ -23,6 +23,7 @@ import (
"context"
"time"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cache"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -206,7 +207,11 @@ func (s *statusDB) GetStatusChildren(ctx context.Context, status *gtsmodel.Statu
children := []*gtsmodel.Status{}
for e := foundStatuses.Front(); e != nil; e = e.Next() {
// only append children, not the overall parent status
entry := e.Value.(*gtsmodel.Status)
entry, ok := e.Value.(*gtsmodel.Status)
if !ok {
logrus.Panic("GetStatusChildren: found status could not be asserted to *gtsmodel.Status")
}
if entry.ID != status.ID {
children = append(children, entry)
}
@ -233,7 +238,11 @@ func (s *statusDB) statusChildren(ctx context.Context, status *gtsmodel.Status,
for _, child := range immediateChildren {
insertLoop:
for e := foundStatuses.Front(); e != nil; e = e.Next() {
entry := e.Value.(*gtsmodel.Status)
entry, ok := e.Value.(*gtsmodel.Status)
if !ok {
logrus.Panic("statusChildren: found status could not be asserted to *gtsmodel.Status")
}
if child.InReplyToAccountID != "" && entry.ID == child.InReplyToID {
foundStatuses.InsertAfter(child, e)
break insertLoop
@ -306,8 +315,7 @@ func (s *statusDB) GetStatusFaves(ctx context.Context, status *gtsmodel.Status)
q := s.newFaveQ(&faves).
Where("status_id = ?", status.ID)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, s.conn.ProcessError(err)
}
return faves, nil
@ -319,8 +327,7 @@ func (s *statusDB) GetStatusReblogs(ctx context.Context, status *gtsmodel.Status
q := s.newStatusQ(&reblogs).
Where("boost_of_id = ?", status.ID)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, s.conn.ProcessError(err)
}
return reblogs, nil

View file

@ -91,8 +91,7 @@ func (t *timelineDB) GetHomeTimeline(ctx context.Context, accountID string, maxI
q = q.WhereGroup(" AND ", whereGroup)
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, t.conn.ProcessError(err)
}
return statuses, nil
@ -136,8 +135,7 @@ func (t *timelineDB) GetPublicTimeline(ctx context.Context, accountID string, ma
q = q.Limit(limit)
}
err := q.Scan(ctx)
if err != nil {
if err := q.Scan(ctx); err != nil {
return nil, t.conn.ProcessError(err)
}
return statuses, nil