1
0

Add Golangci Lint (#676)

Increase golangci timeout

Fix installing golangci-lint in ci

Remove mage targets replaced by golangci

Run golint in ci

Add goheader linter

Enable & fix more linters

Fix lint issues

Add mage target to automagically fix issues found by golangci

golangci-lint run --fix

Add golangci config

Add golangci mage target

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/676
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2020-10-11 20:10:03 +00:00
parent d56a611be7
commit 699d3d6060
143 changed files with 630 additions and 426 deletions

View File

@ -1,9 +1,10 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"testing"
)
func TestBulkTask_Update(t *testing.T) {

View File

@ -17,10 +17,11 @@
package models
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/web"
"fmt"
"net/http"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/web"
)
// Generic

View File

@ -17,10 +17,11 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/xorm"
)

View File

@ -17,10 +17,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestBucket_ReadAll(t *testing.T) {

View File

@ -17,9 +17,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// Label represents a label

View File

@ -17,9 +17,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/builder"
)

View File

@ -1,14 +1,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"code.vikunja.io/web"
)

View File

@ -17,14 +17,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"code.vikunja.io/web"
)

View File

@ -18,11 +18,12 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
"github.com/dgrijalva/jwt-go"
"time"
)
// SharingType holds the sharing type

View File

@ -17,12 +17,13 @@
package models
import (
"strings"
"time"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"strings"
"time"
"xorm.io/builder"
"xorm.io/xorm"
)
@ -450,7 +451,7 @@ func GenerateListIdentifier(l *List, sess *xorm.Engine) (err error) {
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
var exists = true
titleSlug := []rune(strings.Replace(strings.ToUpper(l.Title), " ", "", -1))
titleSlug := []rune(strings.ReplaceAll(strings.ToUpper(l.Title), " ", ""))
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
if len(titleSlug) > 10 {

View File

@ -65,6 +65,7 @@ func (ld *ListDuplicate) CanCreate(a web.Auth) (canCreate bool, err error) {
// @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(a web.Auth) (err error) {
log.Debugf("Duplicating list %d", ld.ListID)

View File

@ -17,11 +17,12 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestListDuplicate(t *testing.T) {

View File

@ -17,8 +17,9 @@
package models
import (
"code.vikunja.io/web"
"time"
"code.vikunja.io/web"
)
// TeamList defines the relation between a team and a list

View File

@ -17,14 +17,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
)
func TestTeamList_ReadAll(t *testing.T) {

View File

@ -17,11 +17,12 @@
package models
import (
"reflect"
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestList_CreateOrUpdate(t *testing.T) {

View File

@ -17,9 +17,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// ListUser represents a list <-> user relation

View File

@ -17,11 +17,12 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
)

View File

@ -17,14 +17,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"code.vikunja.io/web"
)

View File

@ -17,13 +17,14 @@
package models
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
"fmt"
"os"
"testing"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
)
func setupTime() {

View File

@ -17,12 +17,13 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
_ "github.com/go-sql-driver/mysql" // Because.
_ "github.com/lib/pq" // Because.
"time"
"xorm.io/xorm"
_ "github.com/mattn/go-sqlite3" // Because.

View File

@ -17,12 +17,13 @@
package models
import (
"sort"
"time"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/imdario/mergo"
"sort"
"time"
"xorm.io/builder"
)

View File

@ -17,8 +17,9 @@
package models
import (
"code.vikunja.io/web"
"time"
"code.vikunja.io/web"
)
// TeamNamespace defines the relationship between a Team and a Namespace

View File

@ -17,11 +17,12 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
)

View File

@ -17,14 +17,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
)
func TestTeamNamespace_ReadAll(t *testing.T) {

View File

@ -17,10 +17,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestNamespace_Create(t *testing.T) {

View File

@ -17,9 +17,10 @@
package models
import (
"time"
user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// NamespaceUser represents a namespace <-> user relation

View File

@ -17,11 +17,12 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
)

View File

@ -17,14 +17,15 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
"runtime"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"gopkg.in/d4l3k/messagediff.v1"
)
func TestNamespaceUser_Create(t *testing.T) {

View File

@ -17,9 +17,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// SavedFilter represents a saved bunch of filters

View File

@ -17,10 +17,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
"xorm.io/xorm/schemas"
)

View File

@ -17,9 +17,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/xorm"
)

View File

@ -17,11 +17,12 @@
package models
import (
"io"
"time"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"io"
"time"
)
// TaskAttachment is the definition of a task attachment

View File

@ -18,15 +18,16 @@
package models
import (
"io"
"os"
"strconv"
"testing"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"io"
"os"
"strconv"
"testing"
)
func TestTaskAttachment_ReadOne(t *testing.T) {

View File

@ -18,12 +18,13 @@
package models
import (
"code.vikunja.io/api/pkg/config"
"fmt"
"github.com/iancoleman/strcase"
"reflect"
"strconv"
"time"
"code.vikunja.io/api/pkg/config"
"github.com/iancoleman/strcase"
"xorm.io/xorm/schemas"
)
@ -112,6 +113,8 @@ func validateTaskFieldComparator(comparator taskFilterComparator) error {
taskFilterComparatorLessEquals,
taskFilterComparatorNotEquals:
return nil
case taskFilterComparatorInvalid:
fallthrough
default:
return ErrInvalidTaskFilterComparator{Comparator: comparator}
}

View File

@ -17,8 +17,9 @@
package models
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSortParamValidation(t *testing.T) {

View File

@ -17,14 +17,15 @@
package models
import (
"testing"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"gopkg.in/d4l3k/messagediff.v1"
"testing"
"time"
)
func TestTaskCollection_ReadAll(t *testing.T) {

View File

@ -18,9 +18,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// TaskComment represents a task comment

View File

@ -17,10 +17,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTaskComment_Create(t *testing.T) {

View File

@ -18,9 +18,10 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// RelationKind represents a kind of relation between to tasks
@ -174,6 +175,8 @@ func (rel *TaskRelation) Create(a web.Auth) error {
otherRelation.RelationKind = RelationKindCopiedTo
case RelationKindCopiedTo:
otherRelation.RelationKind = RelationKindCopiedFrom
case RelationKindUnknown:
// Nothing to do
}
// Finally insert everything

View File

@ -18,10 +18,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTaskRelation_Create(t *testing.T) {

View File

@ -17,16 +17,17 @@
package models
import (
"math"
"sort"
"strconv"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
"github.com/imdario/mergo"
"math"
"sort"
"strconv"
"time"
"xorm.io/builder"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
@ -168,6 +169,7 @@ func (t *Task) ReadAll(a web.Auth, search string, page int, perPage int) (result
return nil, 0, 0, nil
}
//nolint:gocyclo
func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []*Task, resultCount int, totalItems int64, err error) {
// If the user does not have any lists, don't try to get any tasks
@ -258,6 +260,8 @@ func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []
} else {
filters = append(filters, &builder.Lte{f.field: f.value})
}
case taskFilterComparatorInvalid:
// Nothing to do
}
}
@ -728,6 +732,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() (err error) {
s := x.NewSession()
@ -836,12 +841,12 @@ func (t *Task) Update() (err error) {
// a lot of existing code which we'll then need to refactor.
// This is why.
//
//if err := ot.updateTaskLabels(t.Labels); err != nil {
// return err
//}
// if err := ot.updateTaskLabels(t.Labels); err != nil {
// return err
// }
// set the labels to ot.Labels because our updateTaskLabels function puts the full label objects in it pretty nicely
// We also set this here to prevent it being overwritten later on.
//t.Labels = ot.Labels
// t.Labels = ot.Labels
// For whatever reason, xorm dont detect if done is updated, so we need to update this every time by hand
// Which is why we merge the actual task struct with the one we got from the db

View File

@ -39,7 +39,6 @@ func (t *Task) CanCreate(a web.Auth) (bool, error) {
// CanRead determines if a user can read a task
func (t *Task) CanRead(a web.Auth) (canRead bool, maxRight int, err error) {
//return t.canDoTask(a)
// Get the task, error out if it doesn't exist
*t, err = GetTaskByIDSimple(t.ID)
if err != nil {

View File

@ -17,11 +17,12 @@
package models
import (
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestTask_Create(t *testing.T) {

View File

@ -17,10 +17,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTeamMember_Create(t *testing.T) {

View File

@ -17,10 +17,11 @@
package models
import (
"time"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/builder"
)

View File

@ -17,11 +17,12 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
)

View File

@ -17,11 +17,12 @@
package models
import (
"reflect"
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestTeam_Create(t *testing.T) {

View File

@ -18,10 +18,11 @@
package models
import (
"testing"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"testing"
)
func TestListUsersFromList(t *testing.T) {