From 21c1552daafbcedbd2e19b0c155ff8db9cff2be0 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 3 Jun 2023 13:58:57 +0200 Subject: [PATCH] [chore] Update versions, fix lint errors (#1860) --- .drone.yml | 18 ++++---- .golangci.yml | 41 +++++++++++++++++-- .vscode/settings.json | 3 ++ .../action/admin/account/account.go | 6 +-- internal/api/client/accounts/accountcreate.go | 6 +-- internal/api/util/errorhandling.go | 3 +- internal/cache/util.go | 1 + internal/db/bundb/basic.go | 2 +- internal/federation/federatingdb/reject.go | 13 ++---- internal/gotosocial/gotosocial.go | 6 +-- internal/processing/fromcommon.go | 6 +-- internal/processing/fromfederator.go | 18 ++------ 12 files changed, 66 insertions(+), 57 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8f490ba6c..e605902cb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: # We use golangci-lint for linting. # See: https://golangci-lint.run/ - name: lint - image: golangci/golangci-lint:v1.51.2 + image: golangci/golangci-lint:v1.53.1 volumes: - name: go-build-cache path: /root/.cache/go-build @@ -28,7 +28,7 @@ steps: - pull_request - name: test - image: golang:1.20.1-alpine + image: golang:1.20.4-alpine volumes: - name: go-build-cache path: /root/.cache/go-build @@ -44,7 +44,7 @@ steps: - pull_request - name: web-setup - image: node:14-alpine + image: node:18-alpine when: event: include: @@ -57,7 +57,7 @@ steps: - yarn --frozen-lockfile --cache-folder /tmp/cache - name: web-lint - image: node:14-alpine + image: node:18-alpine when: event: include: @@ -69,7 +69,7 @@ steps: - yarn run lint - name: web-build - image: node:14-alpine + image: node:18-alpine when: event: include: @@ -81,7 +81,7 @@ steps: - yarn run build - name: snapshot - image: superseriousbusiness/gotosocial-drone-build:0.1.0 # https://github.com/superseriousbusiness/gotosocial-drone-build + image: superseriousbusiness/gotosocial-drone-build:0.2.0 # https://github.com/superseriousbusiness/gotosocial-drone-build volumes: - name: go-build-cache path: /root/.cache/go-build @@ -110,7 +110,7 @@ steps: - main - name: release - image: superseriousbusiness/gotosocial-drone-build:0.1.0 # https://github.com/superseriousbusiness/gotosocial-drone-build + image: superseriousbusiness/gotosocial-drone-build:0.2.0 # https://github.com/superseriousbusiness/gotosocial-drone-build volumes: - name: go-build-cache path: /root/.cache/go-build @@ -169,7 +169,7 @@ clone: steps: - name: mirror - image: superseriousbusiness/gotosocial-drone-build:0.1.0 + image: superseriousbusiness/gotosocial-drone-build:0.2.0 environment: ORIGIN_REPO: https://github.com/superseriousbusiness/gotosocial TARGET_REPO: https://codeberg.org/superseriousbusiness/gotosocial @@ -182,6 +182,6 @@ steps: --- kind: signature -hmac: b894a72d5912045f74b9c046c7ecd49f2d36bead2a139d85af66a441aa2bc435 +hmac: 946c2ffd4e79de07a767ec06ebac0a8ca70a03ce5666aae093c9b0af455041d1 ... diff --git a/.golangci.yml b/.golangci.yml index c69ef9889..786cf3a40 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,7 +23,9 @@ linters: - nilerr - revive +# https://golangci-lint.run/usage/linters/#linters-configuration linters-settings: + # https://golangci-lint.run/usage/linters/#goheader goheader: template: |- GoToSocial @@ -42,11 +44,44 @@ linters-settings: You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + # https://golangci-lint.run/usage/linters/#govet govet: disable: - composites + # https://golangci-lint.run/usage/linters/#revive + revive: + rules: + # Enable most default rules. + # See: https://github.com/mgechev/revive/blob/master/defaults.toml + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-naming + - name: error-return + - name: error-strings + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unreachable-code + # Disable below rules. + - name: redefines-builtin-id + disabled: true # This one is just annoying. + - name: unused-parameter + disabled: true # We often pass parameters to fulfil interfaces. + # https://golangci-lint.run/usage/linters/#staticcheck staticcheck: - # Enable all checks - # Disable: - # - SA1012: nil context passing + # Enable all checks, but disable SA1012: nil context passing. + # See: https://staticcheck.io/docs/configuration/options/#checks checks: ["all", "-SA1012"] diff --git a/.vscode/settings.json b/.vscode/settings.json index 3cbd1993a..fa26c263e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,9 @@ "go.lintFlags": [ "--fast" ], + "go.vetFlags": [ + "-composites=false ." + ], "eslint.workingDirectories": ["web/source"], "eslint.lintTask.enable": true, "eslint.lintTask.options": "${workspaceFolder}/web/source" diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go index 4f45fd1b2..3941769ec 100644 --- a/cmd/gotosocial/action/admin/account/account.go +++ b/cmd/gotosocial/action/admin/account/account.go @@ -353,9 +353,5 @@ } u.EncryptedPassword = string(pw) - if err := dbConn.UpdateUser(ctx, u, "encrypted_password"); err != nil { - return err - } - - return nil + return dbConn.UpdateUser(ctx, u, "encrypted_password") } diff --git a/internal/api/client/accounts/accountcreate.go b/internal/api/client/accounts/accountcreate.go index 6af3b41e5..5999c46c1 100644 --- a/internal/api/client/accounts/accountcreate.go +++ b/internal/api/client/accounts/accountcreate.go @@ -141,9 +141,5 @@ func validateCreateAccount(form *apimodel.AccountCreateRequest) error { return err } - if err := validate.SignUpReason(form.Reason, config.GetAccountsReasonRequired()); err != nil { - return err - } - - return nil + return validate.SignUpReason(form.Reason, config.GetAccountsReasonRequired()) } diff --git a/internal/api/util/errorhandling.go b/internal/api/util/errorhandling.go index 8c0251e57..9128ce499 100644 --- a/internal/api/util/errorhandling.go +++ b/internal/api/util/errorhandling.go @@ -117,7 +117,8 @@ func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet fun // or if we should just use a json. Normally we would want to // check for a returned error, but if an error occurs here we // can just fall back to default behavior (serve json error). - accept, _ := NegotiateAccept(c, JSONOrHTMLAcceptHeaders...) + // Prefer provided offers, fall back to JSON or HTML. + accept, _ := NegotiateAccept(c, append(offers, JSONOrHTMLAcceptHeaders...)...) if errWithCode.Code() == http.StatusNotFound { // Use our special not found handler with useful status text. diff --git a/internal/cache/util.go b/internal/cache/util.go index 2d7badf68..a0adfd366 100644 --- a/internal/cache/util.go +++ b/internal/cache/util.go @@ -36,6 +36,7 @@ // caches, which specifically catches and ignores our sentinel error type. func ignoreErrors(err error) bool { return errorsv2.Comparable( + err, SentinelError, context.DeadlineExceeded, context.Canceled, diff --git a/internal/db/bundb/basic.go b/internal/db/bundb/basic.go index c7bcf4b71..6406ede35 100644 --- a/internal/db/bundb/basic.go +++ b/internal/db/bundb/basic.go @@ -160,7 +160,7 @@ func (b *basicDB) DropTable(ctx context.Context, i interface{}) db.Error { } func (b *basicDB) IsHealthy(ctx context.Context) db.Error { - return b.conn.Ping() + return b.conn.PingContext(ctx) } func (b *basicDB) Stop(ctx context.Context) db.Error { diff --git a/internal/federation/federatingdb/reject.go b/internal/federation/federatingdb/reject.go index ceaee83ef..17f0f84d0 100644 --- a/internal/federation/federatingdb/reject.go +++ b/internal/federation/federatingdb/reject.go @@ -70,11 +70,7 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR return errors.New("Reject: follow object account and inbox account were not the same") } - if err := f.state.DB.RejectFollowRequest(ctx, followReq.AccountID, followReq.TargetAccountID); err != nil { - return err - } - - return nil + return f.state.DB.RejectFollowRequest(ctx, followReq.AccountID, followReq.TargetAccountID) } } @@ -90,20 +86,19 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR if !ok { return errors.New("Reject: couldn't parse follow into vocab.ActivityStreamsFollow") } + // convert the follow to something we can understand gtsFollow, err := f.typeConverter.ASFollowToFollow(ctx, asFollow) if err != nil { return fmt.Errorf("Reject: error converting asfollow to gtsfollow: %s", err) } + // make sure the addressee of the original follow is the same as whatever inbox this landed in if gtsFollow.AccountID != receivingAccount.ID { return errors.New("Reject: follow object account and inbox account were not the same") } - if err := f.state.DB.RejectFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID); err != nil { - return err - } - return nil + return f.state.DB.RejectFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID) } } diff --git a/internal/gotosocial/gotosocial.go b/internal/gotosocial/gotosocial.go index 7ce70980d..4c6846ff9 100644 --- a/internal/gotosocial/gotosocial.go +++ b/internal/gotosocial/gotosocial.go @@ -72,8 +72,6 @@ func (gts *gotosocial) Stop(ctx context.Context) error { if err := gts.apiRouter.Stop(ctx); err != nil { return err } - if err := gts.db.Stop(ctx); err != nil { - return err - } - return nil + + return gts.db.Stop(ctx) } diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go index 0adb576bc..03ebb1f1a 100644 --- a/internal/processing/fromcommon.go +++ b/internal/processing/fromcommon.go @@ -434,11 +434,7 @@ func (p *Processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Sta } // delete the status itself - if err := p.state.DB.DeleteStatusByID(ctx, statusToDelete.ID); err != nil { - return err - } - - return nil + return p.state.DB.DeleteStatusByID(ctx, statusToDelete.ID) } // deleteStatusFromTimelines completely removes the given status from all timelines. diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go index f91f5ae8b..17d60c77f 100644 --- a/internal/processing/fromfederator.go +++ b/internal/processing/fromfederator.go @@ -167,11 +167,7 @@ func (p *Processor) processCreateStatusFromFederator(ctx context.Context, federa } } - if err := p.timelineAndNotifyStatus(ctx, status); err != nil { - return err - } - - return nil + return p.timelineAndNotifyStatus(ctx, status) } // processCreateFaveFromFederator handles Activity Create and Object Like @@ -208,11 +204,7 @@ func (p *Processor) processCreateFaveFromFederator(ctx context.Context, federato incomingFave.Account = a } - if err := p.notifyFave(ctx, incomingFave); err != nil { - return err - } - - return nil + return p.notifyFave(ctx, incomingFave) } // processCreateFollowRequestFromFederator handles Activity Create and Object Follow @@ -327,11 +319,7 @@ func (p *Processor) processCreateAnnounceFromFederator(ctx context.Context, fede return err } - if err := p.notifyAnnounce(ctx, incomingAnnounce); err != nil { - return err - } - - return nil + return p.notifyAnnounce(ctx, incomingAnnounce) } // processCreateBlockFromFederator handles Activity Create and Object Block