diff --git a/.golangci.yml b/.golangci.yml index 986396748..ffd332dcc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,10 +3,23 @@ run: timeout: 3m modules-download-mode: vendor -issues: - # Rev at which the linter was introduced. Older bugs are still - # present, but should not be considered validation errors for now - new-from-rev: b14d5c56504dfcea2f5a7b86706b0ecdafd0b68c +linters: + disable-all: true + enable: + # Default set of linters from golangci-lint + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + # Linters added by the stash project + - gofmt + - revive linters-settings: gofmt: @@ -52,21 +65,3 @@ linters-settings: - name: unreachable-code - name: redefines-builtin-id -linters: - disable-all: true - enable: - # Default set of linters from golangci-lint - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - # Linters added by the stash project - - gofmt - - revive - diff --git a/pkg/api/routes_image.go b/pkg/api/routes_image.go index 97c7c7524..9cdaa6653 100644 --- a/pkg/api/routes_image.go +++ b/pkg/api/routes_image.go @@ -59,7 +59,9 @@ func (rs imageRoutes) Thumbnail(w http.ResponseWriter, r *http.Request) { logger.Errorf("error writing thumbnail for image %s: %s", img.Path, err) } } - w.Write(data) + if n, err := w.Write(data); err != nil { + logger.Errorf("error writing thumbnail response. Wrote %v bytes: %v", n, err) + } } } diff --git a/pkg/gallery/export_test.go b/pkg/gallery/export_test.go index 2cd04fa17..ac46871fa 100644 --- a/pkg/gallery/export_test.go +++ b/pkg/gallery/export_test.go @@ -39,8 +39,10 @@ const ( studioName = "studioName" ) -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +) func createFullGallery(id int) models.Gallery { return models.Gallery{ diff --git a/pkg/gallery/import_test.go b/pkg/gallery/import_test.go index 176c80810..962bd18d7 100644 --- a/pkg/gallery/import_test.go +++ b/pkg/gallery/import_test.go @@ -39,8 +39,10 @@ const ( errChecksum = "errChecksum" ) -var createdAt time.Time = time.Date(2001, time.January, 2, 1, 2, 3, 4, time.Local) -var updatedAt time.Time = time.Date(2002, time.January, 2, 1, 2, 3, 4, time.Local) +var ( + createdAt = time.Date(2001, time.January, 2, 1, 2, 3, 4, time.Local) + updatedAt = time.Date(2002, time.January, 2, 1, 2, 3, 4, time.Local) +) func TestImporterName(t *testing.T) { i := Importer{ diff --git a/pkg/image/export_test.go b/pkg/image/export_test.go index 25959aab0..1e0a7d411 100644 --- a/pkg/image/export_test.go +++ b/pkg/image/export_test.go @@ -53,8 +53,10 @@ const ( //galleryChecksum = "galleryChecksum" ) -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +) func createFullImage(id int) models.Image { return models.Image{ diff --git a/pkg/image/thumbnail.go b/pkg/image/thumbnail.go index 841b53fec..bb4cac743 100644 --- a/pkg/image/thumbnail.go +++ b/pkg/image/thumbnail.go @@ -46,7 +46,9 @@ func (e *ThumbnailEncoder) GetThumbnail(img *models.Image, maxSize int) ([]byte, } buf := new(bytes.Buffer) - buf.ReadFrom(reader) + if _, err := buf.ReadFrom(reader); err != nil { + return nil, err + } _, format, err := DecodeSourceImage(img) if err != nil { diff --git a/pkg/movie/export_test.go b/pkg/movie/export_test.go index b889a0428..12023bb52 100644 --- a/pkg/movie/export_test.go +++ b/pkg/movie/export_test.go @@ -44,18 +44,24 @@ const url = "url" const studioName = "studio" -const frontImage = "ZnJvbnRJbWFnZUJ5dGVz" -const backImage = "YmFja0ltYWdlQnl0ZXM=" +const ( + frontImage = "ZnJvbnRJbWFnZUJ5dGVz" + backImage = "YmFja0ltYWdlQnl0ZXM=" +) -var frontImageBytes = []byte("frontImageBytes") -var backImageBytes = []byte("backImageBytes") +var ( + frontImageBytes = []byte("frontImageBytes") + backImageBytes = []byte("backImageBytes") +) var studio models.Studio = models.Studio{ Name: models.NullString(studioName), } -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +) func createFullMovie(id int, studioID int) models.Movie { return models.Movie{ diff --git a/pkg/performer/export_test.go b/pkg/performer/export_test.go index 0d143b2d5..f8fe706bb 100644 --- a/pkg/performer/export_test.go +++ b/pkg/performer/export_test.go @@ -54,8 +54,11 @@ var deathDate = models.SQLiteDate{ String: "2021-02-02", Valid: true, } -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.Local) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.Local) + +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.Local) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.Local) +) func createFullPerformer(id int, name string) *models.Performer { return &models.Performer{ diff --git a/pkg/scene/export_test.go b/pkg/scene/export_test.go index 422008fa2..b0b4f7834 100644 --- a/pkg/scene/export_test.go +++ b/pkg/scene/export_test.go @@ -87,8 +87,10 @@ var imageBytes = []byte("imageBytes") const image = "aW1hZ2VCeXRlcw==" -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +) func createFullScene(id int) models.Scene { return models.Scene{ diff --git a/pkg/sqlite/filter.go b/pkg/sqlite/filter.go index 40cf98857..2649c8175 100644 --- a/pkg/sqlite/filter.go +++ b/pkg/sqlite/filter.go @@ -105,7 +105,7 @@ type filterBuilder struct { err error } -var errSubFilterAlreadySet error = errors.New(`sub-filter already set`) +var errSubFilterAlreadySet = errors.New(`sub-filter already set`) // sub-filter operator values var ( diff --git a/pkg/studio/export_test.go b/pkg/studio/export_test.go index 9361a28c6..1e8b2e88b 100644 --- a/pkg/studio/export_test.go +++ b/pkg/studio/export_test.go @@ -41,8 +41,10 @@ var imageBytes = []byte("imageBytes") const image = "aW1hZ2VCeXRlcw==" -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.Local) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.Local) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.Local) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.Local) +) func createFullStudio(id int, parentID int) models.Studio { ret := models.Studio{ diff --git a/pkg/tag/export_test.go b/pkg/tag/export_test.go index 36b7a0855..2057ccad3 100644 --- a/pkg/tag/export_test.go +++ b/pkg/tag/export_test.go @@ -23,8 +23,10 @@ const ( const tagName = "testTag" -var createTime time.Time = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) -var updateTime time.Time = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +var ( + createTime = time.Date(2001, 01, 01, 0, 0, 0, 0, time.UTC) + updateTime = time.Date(2002, 01, 01, 0, 0, 0, 0, time.UTC) +) func createTag(id int) models.Tag { return models.Tag{