diff --git a/.golangci.yml b/.golangci.yml index 8293b695..544409d0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,18 @@ run: skip-dirs: - components \ No newline at end of file + components + +linters: + enable-all: true + disable: + - dupl + - errcheck + - lll + - goconst + - gochecknoglobals + - gochecknoinits + - gocyclo + - maligned + - scopelint + - stylecheck + - unparam \ No newline at end of file diff --git a/arn/PostAPI.go b/arn/PostAPI.go index 8e394d52..21ace424 100644 --- a/arn/PostAPI.go +++ b/arn/PostAPI.go @@ -189,7 +189,8 @@ func (post *Post) Edit(ctx aero.Context, key string, value reflect.Value, newVal consumed := false user := GetUserFromContext(ctx) - // nolint:gocritic (because this should stay a switch statement) + // This should stay a switch statement. + // nolint:gocritic switch key { case "ParentID": var newParent PostParent diff --git a/arn/SettingsAPI.go b/arn/SettingsAPI.go index b916dccc..039ebe9f 100644 --- a/arn/SettingsAPI.go +++ b/arn/SettingsAPI.go @@ -21,7 +21,8 @@ func (settings *Settings) Authorize(ctx aero.Context, action string) error { // Edit updates the settings object. func (settings *Settings) Edit(ctx aero.Context, key string, value reflect.Value, newValue reflect.Value) (bool, error) { - // nolint:gocritic (because this should stay as a switch statement) + // This should stay as a switch statement. + // nolint:gocritic switch key { case "Theme": if settings.User().IsPro() { diff --git a/jobs/kitsu-import-anime/kitsu-import-anime.go b/jobs/kitsu-import-anime/kitsu-import-anime.go index 16d5e1b1..8c417293 100644 --- a/jobs/kitsu-import-anime/kitsu-import-anime.go +++ b/jobs/kitsu-import-anime/kitsu-import-anime.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/kitsu" + "github.com/animenotifier/notify.moe/arn" ) func main() { diff --git a/jobs/kitsu-import-anime/shell.go b/jobs/kitsu-import-anime/shell.go index 36935e12..0011e545 100644 --- a/jobs/kitsu-import-anime/shell.go +++ b/jobs/kitsu-import-anime/shell.go @@ -4,8 +4,8 @@ import ( "errors" "flag" - "github.com/animenotifier/notify.moe/arn/stringutils" "github.com/animenotifier/kitsu" + "github.com/animenotifier/notify.moe/arn/stringutils" ) // Shell parameters diff --git a/jobs/kitsu-import-mappings/kitsu-import-mappings.go b/jobs/kitsu-import-mappings/kitsu-import-mappings.go index 231537a5..e6e1e348 100644 --- a/jobs/kitsu-import-mappings/kitsu-import-mappings.go +++ b/jobs/kitsu-import-mappings/kitsu-import-mappings.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/kitsu" + "github.com/animenotifier/notify.moe/arn" ) func main() { diff --git a/jobs/mal-parse/anime.go b/jobs/mal-parse/anime.go index f163e1de..19b864af 100644 --- a/jobs/mal-parse/anime.go +++ b/jobs/mal-parse/anime.go @@ -6,9 +6,9 @@ import ( "os" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" malparser "github.com/animenotifier/mal/parser" + "github.com/animenotifier/notify.moe/arn" ) // Read anime file diff --git a/jobs/mal-parse/character.go b/jobs/mal-parse/character.go index 30fa4d27..a19c3c4f 100644 --- a/jobs/mal-parse/character.go +++ b/jobs/mal-parse/character.go @@ -6,8 +6,8 @@ import ( "os" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" malparser "github.com/animenotifier/mal/parser" + "github.com/animenotifier/notify.moe/arn" ) // Read character file diff --git a/jobs/mal-sync/mal-sync.go b/jobs/mal-sync/mal-sync.go index 1c79b09a..720fdca4 100644 --- a/jobs/mal-sync/mal-sync.go +++ b/jobs/mal-sync/mal-sync.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" ) const imageWidthThreshold = 225 diff --git a/jobs/mal-sync/sync.go b/jobs/mal-sync/sync.go index 66696e46..4b7a5506 100644 --- a/jobs/mal-sync/sync.go +++ b/jobs/mal-sync/sync.go @@ -5,8 +5,8 @@ import ( "github.com/aerogo/http/client" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" ) // Sync titles diff --git a/main_test.go b/main_test.go index 25273baa..bdd33cce 100644 --- a/main_test.go +++ b/main_test.go @@ -110,7 +110,7 @@ func TestQuotePages(t *testing.T) { // } // } -func testRoute(t *testing.T, app *aero.Application, route string) { +func testRoute(t *testing.T, app http.Handler, route string) { request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil) response := httptest.NewRecorder() app.ServeHTTP(response, request) diff --git a/pages/animelist/redirect.go b/pages/animelist/redirect.go index 3c1cc377..f4765d0e 100644 --- a/pages/animelist/redirect.go +++ b/pages/animelist/redirect.go @@ -15,5 +15,5 @@ func Redirect(ctx aero.Context) error { return ctx.Error(http.StatusUnauthorized, "Not logged in") } - return ctx.Redirect(http.StatusTemporaryRedirect, "/+" + user.Nick + ctx.Path()) + return ctx.Redirect(http.StatusTemporaryRedirect, "/+"+user.Nick+ctx.Path()) } diff --git a/pages/editor/diffs.go b/pages/editor/diffs.go index bb759b99..764d3306 100644 --- a/pages/editor/diffs.go +++ b/pages/editor/diffs.go @@ -2,8 +2,8 @@ package editor import ( "github.com/akyoto/hash" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils/animediff" ) diff --git a/pages/editor/kitsu.go b/pages/editor/kitsu.go index 4549fbbc..d9b2b341 100644 --- a/pages/editor/kitsu.go +++ b/pages/editor/kitsu.go @@ -4,8 +4,8 @@ import ( "sort" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/kitsu" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) diff --git a/pages/editor/mal.go b/pages/editor/mal.go index dcac9e8a..09387297 100644 --- a/pages/editor/mal.go +++ b/pages/editor/mal.go @@ -6,8 +6,8 @@ import ( "github.com/animenotifier/notify.moe/utils/animediff" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) @@ -122,7 +122,8 @@ func compare(animes []*arn.Anime) []*utils.MALComparison { // diff returns all the differences between an anime and its MAL counterpart. func diff(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference { - // nolint (prealloc linter would complain, but this is best left as nil by default) + // Prealloc linter would complain, but this is best left as nil by default. + // nolint:prealloc var differences []animediff.Difference // We'll use the following diffs diff --git a/pages/listimport/listimportkitsu/kitsu.go b/pages/listimport/listimportkitsu/kitsu.go index 472b34fb..e594039e 100644 --- a/pages/listimport/listimportkitsu/kitsu.go +++ b/pages/listimport/listimportkitsu/kitsu.go @@ -6,8 +6,8 @@ import ( "net/http" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/kitsu" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) diff --git a/pages/listimport/listimportmyanimelist/myanimelist.go b/pages/listimport/listimportmyanimelist/myanimelist.go index e540365d..3c0f0448 100644 --- a/pages/listimport/listimportmyanimelist/myanimelist.go +++ b/pages/listimport/listimportmyanimelist/myanimelist.go @@ -7,8 +7,8 @@ import ( "strconv" "github.com/aerogo/aero" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) diff --git a/pages/recommended/anime.go b/pages/recommended/anime.go index 244fdfea..b753adee 100644 --- a/pages/recommended/anime.go +++ b/pages/recommended/anime.go @@ -47,11 +47,12 @@ func Anime(ctx aero.Context) error { continue } - if anime.Type == "tv" { + switch anime.Type { + case "tv": tv = append(tv, anime) - } else if anime.Type == "movie" { + case "movie": movies = append(movies, anime) - } else { + default: continue } diff --git a/pages/upload/formats.go b/pages/upload/formats.go index 5f296831..b0acc5b5 100644 --- a/pages/upload/formats.go +++ b/pages/upload/formats.go @@ -1,7 +1,7 @@ package upload -// We need these to decode uploaded images. import ( + // We need these to decode uploaded images. _ "image/gif" _ "image/jpeg" _ "image/png" diff --git a/patches/import-mal-companies/import-mal-companies.go b/patches/import-mal-companies/import-mal-companies.go index 5c6e8c74..dff67677 100644 --- a/patches/import-mal-companies/import-mal-companies.go +++ b/patches/import-mal-companies/import-mal-companies.go @@ -5,8 +5,8 @@ import ( "time" "github.com/akyoto/color" - "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/mal" + "github.com/animenotifier/notify.moe/arn" ) var malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil)) diff --git a/utils/editform/editform.go b/utils/editform/editform.go index 6c7ac375..d2864a3b 100644 --- a/utils/editform/editform.go +++ b/utils/editform/editform.go @@ -2,6 +2,7 @@ package editform import ( "fmt" + "io" "reflect" "strconv" "strings" @@ -185,7 +186,7 @@ func RenderField(b *strings.Builder, v *reflect.Value, field reflect.StructField } // String field -func renderStringField(b *strings.Builder, v *reflect.Value, field reflect.StructField, idPrefix string, fieldValue reflect.Value) { +func renderStringField(b io.StringWriter, v *reflect.Value, field reflect.StructField, idPrefix string, fieldValue reflect.Value) { idType := field.Tag.Get("idType") // Try to infer the ID type by the field name @@ -205,20 +206,23 @@ func renderStringField(b *strings.Builder, v *reflect.Value, field reflect.Struc b.WriteString("
") } - // Input field - if field.Tag.Get("datalist") != "" { + switch { + case field.Tag.Get("datalist") != "": dataList := field.Tag.Get("datalist") values := arn.DataLists[dataList] b.WriteString(components.InputSelection(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip"), values)) - } else if field.Tag.Get("type") == "textarea" { + + case field.Tag.Get("type") == "textarea": b.WriteString(components.InputTextArea(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip"))) - } else if field.Tag.Get("type") == "upload" { + + case field.Tag.Get("type") == "upload": endpoint := field.Tag.Get("endpoint") id := v.FieldByName("ID").String() endpoint = strings.Replace(endpoint, ":id", id, 1) b.WriteString(components.InputFileUpload(idPrefix+field.Name, field.Name, field.Tag.Get("filetype"), endpoint)) - } else { + + default: b.WriteString(components.InputText(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip"))) }