From bc382bba4623a1c7ae16535541f2f4b23708999c Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 19 Jun 2019 14:05:03 +0100 Subject: [PATCH] Fix pipeline, emoji and syntax (#713) Fixes #697 Switched to golangci-lint, fixes issues with buildkite and does some linting fixes to appease the new linters. --- .buildkite/pipeline.yaml | 61 ++-- .golangci.yml | 280 +++++++++++++++++++ README.md | 2 +- clientapi/auth/auth.go | 2 +- clientapi/auth/storage/accounts/storage.go | 1 + clientapi/jsonerror/jsonerror.go | 2 +- clientapi/routing/login.go | 1 + cmd/client-api-proxy/main.go | 3 +- cmd/federation-api-proxy/main.go | 3 +- cmd/kafka-producer/main.go | 3 +- common/config/config.go | 2 +- common/log.go | 4 +- common/partition_offset_table.go | 1 - common/test/client.go | 2 +- common/types.go | 2 +- federationapi/routing/state.go | 3 +- linter-fast.json | 16 -- linter.json | 20 -- mediaapi/thumbnailer/thumbnailer_nfnt.go | 5 +- publicroomsapi/storage/public_rooms_table.go | 1 - roomserver/storage/prepare.go | 1 - scripts/find-lint.sh | 36 +-- syncapi/consumers/roomserver.go | 4 - syncapi/storage/syncserver.go | 1 + typingserver/cache/cache.go | 2 +- typingserver/cache/cache_test.go | 2 +- 26 files changed, 342 insertions(+), 118 deletions(-) create mode 100644 .golangci.yml delete mode 100644 linter-fast.json delete mode 100644 linter.json diff --git a/.buildkite/pipeline.yaml b/.buildkite/pipeline.yaml index 9f44877fe..9d755a244 100644 --- a/.buildkite/pipeline.yaml +++ b/.buildkite/pipeline.yaml @@ -1,50 +1,49 @@ steps: - command: - - "go build ./cmd/..." - label: ":hammer-and-wrench: Build / :go: 1.11" - env: - GOGC: "400" - DENDRITE_LINT_DISABLE_GC: "1" + # https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint + - "GOGC=20 ./scripts/find-lint.sh" + label: "\U0001F9F9 Lint / :go: 1.12" + agents: + # Use a larger instance as linting takes a looot of memory + queue: "medium" plugins: - docker#v3.0.1: - image: "golang:1.11-alpine" + image: "golang:1.12" - - command: - - "go test ./..." - label: ":female-scientist: Unit tests / :go: 1.11" - env: - GOGC: "400" - DENDRITE_LINT_DISABLE_GC: "1" - plugins: - - docker#v3.0.1: - image: "golang:1.11-alpine" + - wait - command: - "go build ./cmd/..." - label: ":hammer-and-wrench: Build / :go: 1.12" - env: - GOGC: "400" - DENDRITE_LINT_DISABLE_GC: "1" + label: "\U0001F528 Build / :go: 1.11" plugins: - docker#v3.0.1: - image: "golang:1.12-alpine" + image: "golang:1.11" + retry: + automatic: + - exit_status: 128 + limit: 3 + + - command: + - "go build ./cmd/..." + label: "\U0001F528 Build / :go: 1.12" + plugins: + - docker#v3.0.1: + image: "golang:1.12" + retry: + automatic: + - exit_status: 128 + limit: 3 - command: - "go test ./..." - label: ":female-scientist: Unit tests / :go: 1.12" - env: - GOGC: "400" - DENDRITE_LINT_DISABLE_GC: "1" + label: "\U0001F9EA Unit tests / :go: 1.11" plugins: - docker#v3.0.1: - image: "golang:1.12-alpine" + image: "golang:1.11" - command: - - "./scripts/find-lint.sh" - label: ":lower_left_crayon: Lint / :go: 1.12" - env: - GOGC: "400" - DENDRITE_LINT_DISABLE_GC: "1" + - "go test ./..." + label: "\U0001F9EA Unit tests / :go: 1.12" plugins: - docker#v3.0.1: - image: "golang:1.12-alpine" + image: "golang:1.12" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..0d0f51bd2 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,280 @@ +# Config file for golangci-lint + +# options for analysis running +run: + # default concurrency is a available CPU number + concurrency: 4 + + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 30m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + + # list of build tags, all linters use it. Default is empty list. + #build-tags: + # - mytag + + # which dirs to skip: they won't be analyzed; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but next dirs are always skipped independently + # from this option's value: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs: + - bin + - docs + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. + skip-files: + - ".*\\.md$" + - ".*\\.sh$" + - "^cmd/syncserver-integration-tests/testdata.go$" + + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + #modules-download-mode: (release|readonly|vendor) + + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: colored-line-number + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + + +# all available settings of specific linters +linters-settings: + errcheck: + # report about not checking of errors in type assertions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: false + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: false + + # [deprecated] comma-separated list of pairs of the form pkg:regex + # the regex is used to ignore names within pkg. (default "fmt:.*"). + # see https://github.com/kisielk/errcheck#the-deprecated-method for details + #ignore: fmt:.*,io/ioutil:^Read.* + + # path to a file containing a list of functions to exclude from checking + # see https://github.com/kisielk/errcheck#excluding-functions for details + #exclude: /path/to/file.txt + govet: + # report about shadowed variables + check-shadowing: true + + # settings per analyzer + settings: + printf: # analyzer name, run `go tool vet help` to see all analyzers + funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.8 + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + #local-prefixes: github.com/org/project + gocyclo: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 12 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + goconst: + # minimal length of string constant, 3 by default + min-len: 3 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 3 + depguard: + list-type: blacklist + include-go-root: false + packages: + # - github.com/davecgh/go-spew/spew + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: UK + ignore-words: + # - someword + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 96 + # tab width in spaces. Default to 1. + tab-width: 1 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + unparam: + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 60 + prealloc: + # XXX: we don't recommend using this linter before doing performance profiling. + # For most programs usage of prealloc will be a premature optimization. + + # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. + # True by default. + simple: true + range-loops: true # Report preallocation suggestions on range loops, true by default + for-loops: false # Report preallocation suggestions on for loops, false by default + gocritic: + # Which checks should be enabled; can't be combined with 'disabled-checks'; + # See https://go-critic.github.io/overview#checks-overview + # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` + # By default list of stable checks is used. + #enabled-checks: + + # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + #disabled-checks: + + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + #enabled-tags: + # - performance + + settings: # settings passed to gocritic + captLocal: # must be valid enabled check name + paramsOnly: true + #rangeValCopy: + # sizeThreshold: 32 + +linters: + enable: + - deadcode + - errcheck + - goconst + - gocyclo + - goimports # Does everything gofmt does + - gosimple + - ineffassign + - megacheck + - misspell # Check code comments, whereas misspell in CI checks *.md files + - nakedret + - staticcheck + - structcheck + - unparam + - unused + - varcheck + enable-all: false + disable: + - bodyclose + - depguard + - dupl + - gochecknoglobals + - gochecknoinits + - gocritic + - gofmt + - golint + - gosec # Should turn back on soon + - interfacer + - lll + - maligned + - prealloc # Should turn back on soon + - scopelint + - stylecheck + - typecheck # Should turn back on soon + - unconvert # Should turn back on soon + disable-all: false + presets: + fast: false + + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + exclude: + # - abcdef + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via "nolint" comments. + - path: internal/hmac/ + text: "weak cryptographic primitive" + linters: + - gosec + + # Exclude some staticcheck messages + - linters: + - staticcheck + text: "SA9003:" + + # Exclude lll issues for long lines with go:generate + - linters: + - lll + source: "^//go:generate " + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: false + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing + # large codebase. It's not practical to fix all existing issues at the moment + # of integration: much better don't allow issues in new code. + # Default is false. + new: false + + # Show only new issues created after git revision `REV` + #new-from-rev: REV + + # Show only new issues created in git patch with set file path. + #new-from-patch: path/to/patch/file diff --git a/README.md b/README.md index 7ba64490f..8eadaf431 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Dendrite [![Build Status](https://travis-ci.org/matrix-org/dendrite.svg?branch=master)](https://travis-ci.org/matrix-org/dendrite) [![CircleCI](https://circleci.com/gh/matrix-org/dendrite.svg?style=svg)](https://circleci.com/gh/matrix-org/dendrite) [![Dendrite Dev on Matrix](https://img.shields.io/matrix/dendrite-dev:matrix.org.svg?label=%23dendrite-dev%3Amatrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#dendrite-dev:matrix.org) [![Dendrite on Matrix](https://img.shields.io/matrix/dendrite:matrix.org.svg?label=%23dendrite%3Amatrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#dendrite:matrix.org) +# Dendrite [![Build Status](https://badge.buildkite.com/4be40938ab19f2bbc4a6c6724517353ee3ec1422e279faf374.svg)](https://buildkite.com/matrix-dot-org/dendrite) [![CircleCI](https://circleci.com/gh/matrix-org/dendrite.svg?style=svg)](https://circleci.com/gh/matrix-org/dendrite) [![Dendrite Dev on Matrix](https://img.shields.io/matrix/dendrite-dev:matrix.org.svg?label=%23dendrite-dev%3Amatrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#dendrite-dev:matrix.org) [![Dendrite on Matrix](https://img.shields.io/matrix/dendrite:matrix.org.svg?label=%23dendrite%3Amatrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#dendrite:matrix.org) Dendrite will be a matrix homeserver written in go. diff --git a/clientapi/auth/auth.go b/clientapi/auth/auth.go index 00943fb83..f51cfea26 100644 --- a/clientapi/auth/auth.go +++ b/clientapi/auth/auth.go @@ -130,7 +130,7 @@ func VerifyUserFromRequest( return nil, &util.JSONResponse{ Code: http.StatusUnauthorized, - JSON: jsonerror.UnknownToken("Unrecognized access token"), + JSON: jsonerror.UnknownToken("Unrecognized access token"), // nolint: misspell } } diff --git a/clientapi/auth/storage/accounts/storage.go b/clientapi/auth/storage/accounts/storage.go index 2650470b8..27c0a176a 100644 --- a/clientapi/auth/storage/accounts/storage.go +++ b/clientapi/auth/storage/accounts/storage.go @@ -23,6 +23,7 @@ import ( "github.com/matrix-org/dendrite/common" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/bcrypt" + // Import the postgres database driver. _ "github.com/lib/pq" ) diff --git a/clientapi/jsonerror/jsonerror.go b/clientapi/jsonerror/jsonerror.go index fa15d9d8e..8df1fead2 100644 --- a/clientapi/jsonerror/jsonerror.go +++ b/clientapi/jsonerror/jsonerror.go @@ -87,7 +87,7 @@ func MissingToken(msg string) *MatrixError { } // UnknownToken is an error when the client tries to access a resource which -// requires authentication and supplies an unrecognized token +// requires authentication and supplies an unrecognised token func UnknownToken(msg string) *MatrixError { return &MatrixError{"M_UNKNOWN_TOKEN", msg} } diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index cb2218805..abcf7f569 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -19,6 +19,7 @@ import ( "context" "database/sql" + "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" diff --git a/cmd/client-api-proxy/main.go b/cmd/client-api-proxy/main.go index b602016d5..27991c109 100644 --- a/cmd/client-api-proxy/main.go +++ b/cmd/client-api-proxy/main.go @@ -17,13 +17,14 @@ package main import ( "flag" "fmt" - log "github.com/sirupsen/logrus" "net/http" "net/http/httputil" "net/url" "os" "strings" "time" + + log "github.com/sirupsen/logrus" ) const usage = `Usage: %s diff --git a/cmd/federation-api-proxy/main.go b/cmd/federation-api-proxy/main.go index fc7a9e57a..fa90482d5 100644 --- a/cmd/federation-api-proxy/main.go +++ b/cmd/federation-api-proxy/main.go @@ -17,13 +17,14 @@ package main import ( "flag" "fmt" - log "github.com/sirupsen/logrus" "net/http" "net/http/httputil" "net/url" "os" "strings" "time" + + log "github.com/sirupsen/logrus" ) const usage = `Usage: %s diff --git a/cmd/kafka-producer/main.go b/cmd/kafka-producer/main.go index c35c587d8..8a4340f21 100644 --- a/cmd/kafka-producer/main.go +++ b/cmd/kafka-producer/main.go @@ -18,9 +18,10 @@ import ( "bufio" "flag" "fmt" - "github.com/Shopify/sarama" "os" "strings" + + "github.com/Shopify/sarama" ) const usage = `Usage: %s diff --git a/common/config/config.go b/common/config/config.go index 16e50aead..9fcab8cf9 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -585,7 +585,7 @@ func (config *Dendrite) check(monolithic bool) error { } // Due to how Golang manages its interface types, this condition is not redundant. - // In order to get the proper behavior, it is necessary to return an explicit nil + // In order to get the proper behaviour, it is necessary to return an explicit nil // and not a nil configErrors. // This is because the following equalities hold: // error(nil) == nil diff --git a/common/log.go b/common/log.go index 7daa069c4..89a705822 100644 --- a/common/log.go +++ b/common/log.go @@ -76,7 +76,7 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) { // Check we received a proper logging level level, err := logrus.ParseLevel(hook.Level) if err != nil { - logrus.Fatalf("Unrecognized logging level %s: %q", hook.Level, err) + logrus.Fatalf("Unrecognised logging level %s: %q", hook.Level, err) } // Perform a first filter on the logs according to the lowest level of all @@ -90,7 +90,7 @@ func SetupHookLogging(hooks []config.LogrusHook, componentName string) { checkFileHookParams(hook.Params) setupFileHook(hook, level, componentName) default: - logrus.Fatalf("Unrecognized logging hook type: %s", hook.Type) + logrus.Fatalf("Unrecognised logging hook type: %s", hook.Type) } } } diff --git a/common/partition_offset_table.go b/common/partition_offset_table.go index bb23755c7..bf37e2ed5 100644 --- a/common/partition_offset_table.go +++ b/common/partition_offset_table.go @@ -50,7 +50,6 @@ type PartitionOffsetStatements struct { // Prepare converts the raw SQL statements into prepared statements. // Takes a prefix to prepend to the table name used to store the partition offsets. // This allows multiple components to share the same database schema. -// nolint: safesql func (s *PartitionOffsetStatements) Prepare(db *sql.DB, prefix string) (err error) { _, err = db.Exec(strings.Replace(partitionOffsetsSchema, "${prefix}", prefix, -1)) if err != nil { diff --git a/common/test/client.go b/common/test/client.go index d1c40e53f..a38540ac9 100644 --- a/common/test/client.go +++ b/common/test/client.go @@ -34,7 +34,7 @@ type Request struct { LastErr *LastRequestErr } -// LastRequestErr is a synchronized error wrapper +// LastRequestErr is a synchronised error wrapper // Useful for obtaining the last error from a set of requests type LastRequestErr struct { sync.Mutex diff --git a/common/types.go b/common/types.go index e539774e2..6888d3806 100644 --- a/common/types.go +++ b/common/types.go @@ -43,7 +43,7 @@ type DisplayName struct { // WeakBoolean is a type that will Unmarshal to true or false even if the encoded // representation is "true"/1 or "false"/0, as well as whatever other forms are -// recognized by strconv.ParseBool +// recognised by strconv.ParseBool type WeakBoolean bool // UnmarshalJSON is overridden here to allow strings vaguely representing a true diff --git a/federationapi/routing/state.go b/federationapi/routing/state.go index 130f8a4f7..58398bde9 100644 --- a/federationapi/routing/state.go +++ b/federationapi/routing/state.go @@ -75,7 +75,8 @@ func parseEventIDParam( ) (eventID string, resErr *util.JSONResponse) { URL, err := url.Parse(request.RequestURI()) if err != nil { - *resErr = util.ErrorResponse(err) + response := util.ErrorResponse(err) + resErr = &response return } diff --git a/linter-fast.json b/linter-fast.json deleted file mode 100644 index 68d518444..000000000 --- a/linter-fast.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Vendor": true, - "Cyclo": 12, - "Deadline": "5m", - "Enable": [ - "vetshadow", - "deadcode", - "gocyclo", - "ineffassign", - "misspell", - "errcheck", - "vet", - "gofmt", - "goconst" - ] -} diff --git a/linter.json b/linter.json deleted file mode 100644 index 1f0550aaf..000000000 --- a/linter.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Vendor": true, - "Cyclo": 12, - "Deadline": "5m", - "Enable": [ - "vetshadow", - "deadcode", - "gocyclo", - "golint", - "varcheck", - "structcheck", - "ineffassign", - "misspell", - "unparam", - "errcheck", - "vet", - "gofmt", - "goconst" - ] -} diff --git a/mediaapi/thumbnailer/thumbnailer_nfnt.go b/mediaapi/thumbnailer/thumbnailer_nfnt.go index 43bf8efba..5df6ce4be 100644 --- a/mediaapi/thumbnailer/thumbnailer_nfnt.go +++ b/mediaapi/thumbnailer/thumbnailer_nfnt.go @@ -20,9 +20,11 @@ import ( "context" "image" "image/draw" + // Imported for gif codec _ "image/gif" "image/jpeg" + // Imported for png codec _ "image/png" "os" @@ -258,9 +260,6 @@ func adjustSize(dst types.Path, img image.Image, w, h int, crop bool, logger *lo out = target } else { out = resize.Thumbnail(uint(w), uint(h), img, resize.Lanczos3) - if err != nil { - return -1, -1, err - } } if err = writeFile(out, string(dst)); err != nil { diff --git a/publicroomsapi/storage/public_rooms_table.go b/publicroomsapi/storage/public_rooms_table.go index 85d65c2cc..5e1eb3e12 100644 --- a/publicroomsapi/storage/public_rooms_table.go +++ b/publicroomsapi/storage/public_rooms_table.go @@ -134,7 +134,6 @@ type publicRoomsStatements struct { updateRoomAttributeStmts map[string]*sql.Stmt } -// nolint: safesql func (s *publicRoomsStatements) prepare(db *sql.DB) (err error) { _, err = db.Exec(publicRoomsSchema) if err != nil { diff --git a/roomserver/storage/prepare.go b/roomserver/storage/prepare.go index 61c49a3c1..b19765992 100644 --- a/roomserver/storage/prepare.go +++ b/roomserver/storage/prepare.go @@ -25,7 +25,6 @@ type statementList []struct { } // prepare the SQL for each statement in the list and assign the result to the prepared statement. -// nolint: safesql func (s statementList) prepare(db *sql.DB) (err error) { for _, statement := range s { if *statement.statement, err = db.Prepare(statement.sql); err != nil { diff --git a/scripts/find-lint.sh b/scripts/find-lint.sh index a8201072b..6511272b2 100755 --- a/scripts/find-lint.sh +++ b/scripts/find-lint.sh @@ -3,44 +3,26 @@ # Runs the linters against dendrite # The linters can take a lot of resources and are slow, so they can be -# configured using two environment variables: +# configured using the following environment variables: # # - `DENDRITE_LINT_CONCURRENCY` - number of concurrent linters to run, -# gometalinter defaults this to 8 -# - `DENDRITE_LINT_DISABLE_GC` - if set then the the go gc will be disabled -# when running the linters, speeding them up but using much more memory. +# golangci-lint defaults this to NumCPU +# - `GOGC` - how often to perform garbage collection during golangci-lint runs. +# Essentially a ratio of memory/speed. See https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint +# for more info. set -eux cd `dirname $0`/.. -# gometalinter doesn't seem to work without this. -# We should move from gometalinter asap as per https://github.com/matrix-org/dendrite/issues/697 so this is a temporary -# fix. -export GO111MODULE=off - args="" if [ ${1:-""} = "fast" ] -then args="--config=linter-fast.json" -else args="--config=linter.json" +then args="--fast" fi -if [ -n "${DENDRITE_LINT_CONCURRENCY:-}" ] -then args="$args --concurrency=$DENDRITE_LINT_CONCURRENCY" -fi - -if [ -z "${DENDRITE_LINT_DISABLE_GC:-}" ] -then args="$args --enable-gc" -fi - -echo "Installing lint search engine..." -go get github.com/alecthomas/gometalinter/ - -gometalinter --config=linter.json ./... --install +echo "Installing golangci-lint..." +go get github.com/golangci/golangci-lint/cmd/golangci-lint echo "Looking for lint..." -gometalinter ./... $args - -echo "Double checking spelling..." -misspell -error src *.md +golangci-lint run $args diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go index 273b6aea1..1866a9667 100644 --- a/syncapi/consumers/roomserver.go +++ b/syncapi/consumers/roomserver.go @@ -134,10 +134,6 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent( msg.RemovesStateEventIDs, msg.TransactionID, ) - if err != nil { - return err - } - if err != nil { // panic rather than continue with an inconsistent database log.WithFields(log.Fields{ diff --git a/syncapi/storage/syncserver.go b/syncapi/storage/syncserver.go index ec973e2c1..b0655a0a8 100644 --- a/syncapi/storage/syncserver.go +++ b/syncapi/storage/syncserver.go @@ -23,6 +23,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/roomserver/api" + // Import the postgres database driver. _ "github.com/lib/pq" "github.com/matrix-org/dendrite/common" diff --git a/typingserver/cache/cache.go b/typingserver/cache/cache.go index 739f60a24..85d74cd19 100644 --- a/typingserver/cache/cache.go +++ b/typingserver/cache/cache.go @@ -28,7 +28,7 @@ type TypingCache struct { data map[string]userSet } -// NewTypingCache returns a new TypingCache initialized for use. +// NewTypingCache returns a new TypingCache initialised for use. func NewTypingCache() *TypingCache { return &TypingCache{data: make(map[string]userSet)} } diff --git a/typingserver/cache/cache_test.go b/typingserver/cache/cache_test.go index 7aa73e922..2a6ffa50e 100644 --- a/typingserver/cache/cache_test.go +++ b/typingserver/cache/cache_test.go @@ -38,7 +38,7 @@ func TestTypingCache(t *testing.T) { }) } -func testAddTypingUser(t *testing.T, tCache *TypingCache) { +func testAddTypingUser(t *testing.T, tCache *TypingCache) { // nolint: unparam present := time.Now() tests := []struct { userID string