diff --git a/.drone.yml b/.drone.yml index d4ac92c460..6680a09fdf 100644 --- a/.drone.yml +++ b/.drone.yml @@ -132,14 +132,15 @@ steps: event: [ push, tag, pull_request ] - name: lint - image: golang:1.17-alpine + image: golang:1.19-alpine pull: true environment: GOPROXY: 'https://goproxy.kolaente.de' depends_on: [ build ] commands: + - export "GOROOT=$(go env GOROOT)" - apk --no-cache add build-base git - - wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.3 + - wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0 - ./mage-static check:all when: event: [ push, tag, pull_request ] @@ -878,6 +879,6 @@ steps: - failure --- kind: signature -hmac: d95e5d4b31e22079ce6360f31ec9257b26cd206b614cb1ec660290c061eced8f +hmac: 9ca8948161dc6ac167aa3f01d2798745f58550b24c6ced4a81bf64b5b129f172 ... diff --git a/Dockerfile b/Dockerfile index 729120ff9c..3c1bfd10fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ############## # Build stage -FROM golang:1.18-alpine AS build-env +FROM golang:1.19-alpine AS build-env RUN apk --no-cache add build-base git && \ go install github.com/magefile/mage@latest && \ diff --git a/Dockerfile.arm32 b/Dockerfile.arm32 index ce51c958f2..005799aa87 100644 --- a/Dockerfile.arm32 +++ b/Dockerfile.arm32 @@ -1,7 +1,7 @@ ############## # Build stage -FROM golang:1.18-buster AS build-env +FROM golang:1.19-buster AS build-env RUN go install github.com/magefile/mage@latest && \ mv /go/bin/mage /usr/local/go/bin diff --git a/magefile.go b/magefile.go index cd2fa82d77..a2a14487e1 100644 --- a/magefile.go +++ b/magefile.go @@ -27,7 +27,6 @@ import ( "fmt" "github.com/iancoleman/strcase" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -701,14 +700,14 @@ func (Release) Packages() error { // Because nfpm does not support templating, we replace the values in the config file and restore it after running nfpmConfigPath := RootPath + "/nfpm.yaml" - nfpmconfig, err := ioutil.ReadFile(nfpmConfigPath) + nfpmconfig, err := os.ReadFile(nfpmConfigPath) if err != nil { return err } fixedConfig := strings.ReplaceAll(string(nfpmconfig), "", VersionNumber) fixedConfig = strings.ReplaceAll(fixedConfig, "", BinLocation) - if err := ioutil.WriteFile(nfpmConfigPath, []byte(fixedConfig), 0); err != nil { + if err := os.WriteFile(nfpmConfigPath, []byte(fixedConfig), 0); err != nil { return err } @@ -721,7 +720,7 @@ func (Release) Packages() error { runAndStreamOutput(binpath, "pkg", "--packager", "rpm", "--target", releasePath) runAndStreamOutput(binpath, "pkg", "--packager", "apk", "--target", releasePath) - return ioutil.WriteFile(nfpmConfigPath, nfpmconfig, 0) + return os.WriteFile(nfpmConfigPath, nfpmconfig, 0) } type Dev mg.Namespace @@ -885,7 +884,7 @@ func (s *` + name + `) Handle(msg *message.Message) (err error) { if _, err := f.Seek(idx, 0); err != nil { return err } - remainder, err := ioutil.ReadAll(f) + remainder, err := io.ReadAll(f) if err != nil { return err } @@ -1074,7 +1073,7 @@ const ( // Generates the config docs from a commented config.yml.sample file in the repo root. func GenerateDocs() error { - config, err := ioutil.ReadFile("config.yml.sample") + config, err := os.ReadFile("config.yml.sample") if err != nil { return err } @@ -1124,7 +1123,7 @@ func GenerateDocs() error { // We write the full file to prevent old content leftovers at the end // I know, there are probably better ways to do this. - if err := ioutil.WriteFile(configDocPath, []byte(fullConfig), 0); err != nil { + if err := os.WriteFile(configDocPath, []byte(fullConfig), 0); err != nil { return err } diff --git a/pkg/models/list_duplicate.go b/pkg/models/list_duplicate.go index 5b1e51acb8..d5c75325ab 100644 --- a/pkg/models/list_duplicate.go +++ b/pkg/models/list_duplicate.go @@ -66,6 +66,7 @@ func (ld *ListDuplicate) CanCreate(s *xorm.Session, a web.Auth) (canCreate bool, // @Failure 403 {object} web.HTTPError "The user does not have access to the list or namespace" // @Failure 500 {object} models.Message "Internal error" // @Router /lists/{listID}/duplicate [put] +// //nolint:gocyclo func (ld *ListDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) { diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 14466c655f..3da5f70385 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -480,6 +480,7 @@ func getSavedFilters(s *xorm.Session, doer *user.User) (savedFiltersNamespace *N // @Success 200 {array} models.NamespaceWithLists "The Namespaces." // @Failure 500 {object} models.Message "Internal error" // @Router /namespaces [get] +// //nolint:gocyclo func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) { if _, is := a.(*LinkSharing); is { diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index c73e8bb227..ea24d85e10 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -979,6 +979,7 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err // @Failure 403 {object} web.HTTPError "The user does not have access to the task (aka its list)" // @Failure 500 {object} models.Message "Internal error" // @Router /tasks/{id} [post] +// //nolint:gocyclo func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) { @@ -1331,8 +1332,8 @@ func setTaskDatesFromCurrentDateRepeat(oldTask, newTask *Task) { // This helper function updates the reminders, doneAt, start and end dates of the *old* task // and saves the new values in the newTask object. // We make a few assumtions here: -// 1. Everything in oldTask is the truth - we figure out if we update anything at all if oldTask.RepeatAfter has a value > 0 -// 2. Because of 1., this functions should not be used to update values other than Done in the same go +// 1. Everything in oldTask is the truth - we figure out if we update anything at all if oldTask.RepeatAfter has a value > 0 +// 2. Because of 1., this functions should not be used to update values other than Done in the same go func updateDone(oldTask *Task, newTask *Task) { if !oldTask.Done && newTask.Done { switch oldTask.RepeatMode { diff --git a/pkg/modules/avatar/gravatar/gravatar.go b/pkg/modules/avatar/gravatar/gravatar.go index 35157d48d9..99faddd170 100644 --- a/pkg/modules/avatar/gravatar/gravatar.go +++ b/pkg/modules/avatar/gravatar/gravatar.go @@ -18,7 +18,7 @@ package gravatar import ( "context" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -74,7 +74,7 @@ func (g *Provider) GetAvatar(user *user.User, size int64) ([]byte, string, error return nil, "", err } defer resp.Body.Close() - avatarContent, err := ioutil.ReadAll(resp.Body) + avatarContent, err := io.ReadAll(resp.Body) if err != nil { return nil, "", err } diff --git a/pkg/modules/avatar/upload/upload.go b/pkg/modules/avatar/upload/upload.go index e75f2ba66a..311d96975e 100644 --- a/pkg/modules/avatar/upload/upload.go +++ b/pkg/modules/avatar/upload/upload.go @@ -20,13 +20,14 @@ import ( "bytes" "image" "image/png" - "io/ioutil" + "io" "strconv" "code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/modules/keyvalue" "code.vikunja.io/api/pkg/user" + "github.com/disintegration/imaging" ) @@ -82,7 +83,7 @@ func (p *Provider) GetAvatar(u *user.User, size int64) (avatar []byte, mimeType return nil, "", err } - avatar, err = ioutil.ReadAll(buf) + avatar, err = io.ReadAll(buf) if err != nil { return nil, "", err } diff --git a/pkg/modules/migration/create_from_structure.go b/pkg/modules/migration/create_from_structure.go index e45224612f..1f33f53a99 100644 --- a/pkg/modules/migration/create_from_structure.go +++ b/pkg/modules/migration/create_from_structure.go @@ -18,15 +18,14 @@ package migration import ( "bytes" - "io/ioutil" - - "code.vikunja.io/api/pkg/modules/background/handler" + "io" "xorm.io/xorm" "code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/models" + "code.vikunja.io/api/pkg/modules/background/handler" "code.vikunja.io/api/pkg/user" ) @@ -212,7 +211,7 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithListsAndTas // Check if we have a file to create if len(a.File.FileContent) > 0 { a.TaskID = t.ID - fr := ioutil.NopCloser(bytes.NewReader(a.File.FileContent)) + fr := io.NopCloser(bytes.NewReader(a.File.FileContent)) err = a.NewAttachment(s, fr, a.File.Name, a.File.Size, user) if err != nil { return diff --git a/pkg/modules/migration/todoist/todoist_test.go b/pkg/modules/migration/todoist/todoist_test.go index 3b815280ac..1c6b383cd2 100644 --- a/pkg/modules/migration/todoist/todoist_test.go +++ b/pkg/modules/migration/todoist/todoist_test.go @@ -17,7 +17,7 @@ package todoist import ( - "io/ioutil" + "os" "strconv" "testing" "time" @@ -47,7 +47,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { dueTimeWithTime = dueTimeWithTime.In(config.GetTimeZone()) nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z") assert.NoError(t, err) - exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") + exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") assert.NoError(t, err) makeTestItem := func(id, projectId int64, hasDueDate, hasLabels, done bool) *item { diff --git a/pkg/modules/migration/trello/trello_test.go b/pkg/modules/migration/trello/trello_test.go index efb02bcfc1..e34b5de7ec 100644 --- a/pkg/modules/migration/trello/trello_test.go +++ b/pkg/modules/migration/trello/trello_test.go @@ -18,7 +18,7 @@ package trello import ( "bytes" - "io/ioutil" + "os" "testing" "time" @@ -36,7 +36,7 @@ func TestConvertTrelloToVikunja(t *testing.T) { time1, err := time.Parse(time.RFC3339Nano, "2014-09-26T08:25:05Z") assert.NoError(t, err) - exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") + exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") assert.NoError(t, err) trelloData := []*trello.Board{ diff --git a/pkg/modules/migration/wunderlist/wunderlist_test.go b/pkg/modules/migration/wunderlist/wunderlist_test.go index 3385ac7944..2b27260d01 100644 --- a/pkg/modules/migration/wunderlist/wunderlist_test.go +++ b/pkg/modules/migration/wunderlist/wunderlist_test.go @@ -17,7 +17,7 @@ package wunderlist import ( - "io/ioutil" + "os" "strconv" "testing" "time" @@ -46,7 +46,7 @@ func TestWunderlistParsing(t *testing.T) { assert.NoError(t, err) time4 = time4.In(config.GetTimeZone()) - exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") + exampleFile, err := os.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") assert.NoError(t, err) createTestTask := func(id, listID int, done bool) *task { diff --git a/pkg/routes/caldav/handler.go b/pkg/routes/caldav/handler.go index 8d748130ae..a800343fce 100644 --- a/pkg/routes/caldav/handler.go +++ b/pkg/routes/caldav/handler.go @@ -19,7 +19,7 @@ package caldav import ( "bytes" "fmt" - "io/ioutil" + "io" "reflect" "strconv" "strings" @@ -61,9 +61,9 @@ func ListHandler(c echo.Context) error { } // Try to parse a task from the request payload - body, _ := ioutil.ReadAll(c.Request().Body) + body, _ := io.ReadAll(c.Request().Body) // Restore the io.ReadCloser to its original state - c.Request().Body = ioutil.NopCloser(bytes.NewBuffer(body)) + c.Request().Body = io.NopCloser(bytes.NewBuffer(body)) // Parse it vtodo := string(body) if vtodo != "" && strings.HasPrefix(vtodo, `BEGIN:VCALENDAR`) { @@ -127,9 +127,9 @@ func PrincipalHandler(c echo.Context) error { } // Try to parse a task from the request payload - body, _ := ioutil.ReadAll(c.Request().Body) + body, _ := io.ReadAll(c.Request().Body) // Restore the io.ReadCloser to its original state - c.Request().Body = ioutil.NopCloser(bytes.NewBuffer(body)) + c.Request().Body = io.NopCloser(bytes.NewBuffer(body)) log.Debugf("[CALDAV] Request Body: %v\n", string(body)) log.Debugf("[CALDAV] Request Headers: %v\n", c.Request().Header) @@ -157,9 +157,9 @@ func EntryHandler(c echo.Context) error { } // Try to parse a task from the request payload - body, _ := ioutil.ReadAll(c.Request().Body) + body, _ := io.ReadAll(c.Request().Body) // Restore the io.ReadCloser to its original state - c.Request().Body = ioutil.NopCloser(bytes.NewBuffer(body)) + c.Request().Body = io.NopCloser(bytes.NewBuffer(body)) log.Debugf("[CALDAV] Request Body: %v\n", string(body)) log.Debugf("[CALDAV] Request Headers: %v\n", c.Request().Header)