Fixed a few linter hints

This commit is contained in:
Eduard Urbach 2019-06-07 10:03:16 +09:00
parent 0e4f7fe6ec
commit f464e830bf
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
21 changed files with 52 additions and 29 deletions

View File

@ -1,3 +1,18 @@
run: run:
skip-dirs: skip-dirs:
components components
linters:
enable-all: true
disable:
- dupl
- errcheck
- lll
- goconst
- gochecknoglobals
- gochecknoinits
- gocyclo
- maligned
- scopelint
- stylecheck
- unparam

View File

@ -189,7 +189,8 @@ func (post *Post) Edit(ctx aero.Context, key string, value reflect.Value, newVal
consumed := false consumed := false
user := GetUserFromContext(ctx) user := GetUserFromContext(ctx)
// nolint:gocritic (because this should stay a switch statement) // This should stay a switch statement.
// nolint:gocritic
switch key { switch key {
case "ParentID": case "ParentID":
var newParent PostParent var newParent PostParent

View File

@ -21,7 +21,8 @@ func (settings *Settings) Authorize(ctx aero.Context, action string) error {
// Edit updates the settings object. // Edit updates the settings object.
func (settings *Settings) Edit(ctx aero.Context, key string, value reflect.Value, newValue reflect.Value) (bool, error) { 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 { switch key {
case "Theme": case "Theme":
if settings.User().IsPro() { if settings.User().IsPro() {

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/animenotifier/notify.moe/arn"
) )
func main() { func main() {

View File

@ -4,8 +4,8 @@ import (
"errors" "errors"
"flag" "flag"
"github.com/animenotifier/notify.moe/arn/stringutils"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/animenotifier/notify.moe/arn/stringutils"
) )
// Shell parameters // Shell parameters

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/animenotifier/notify.moe/arn"
) )
func main() { func main() {

View File

@ -6,9 +6,9 @@ import (
"os" "os"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
malparser "github.com/animenotifier/mal/parser" malparser "github.com/animenotifier/mal/parser"
"github.com/animenotifier/notify.moe/arn"
) )
// Read anime file // Read anime file

View File

@ -6,8 +6,8 @@ import (
"os" "os"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
malparser "github.com/animenotifier/mal/parser" malparser "github.com/animenotifier/mal/parser"
"github.com/animenotifier/notify.moe/arn"
) )
// Read character file // Read character file

View File

@ -5,8 +5,8 @@ import (
"strings" "strings"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
) )
const imageWidthThreshold = 225 const imageWidthThreshold = 225

View File

@ -5,8 +5,8 @@ import (
"github.com/aerogo/http/client" "github.com/aerogo/http/client"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
) )
// Sync titles // Sync titles

View File

@ -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) request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil)
response := httptest.NewRecorder() response := httptest.NewRecorder()
app.ServeHTTP(response, request) app.ServeHTTP(response, request)

View File

@ -15,5 +15,5 @@ func Redirect(ctx aero.Context) error {
return ctx.Error(http.StatusUnauthorized, "Not logged in") 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())
} }

View File

@ -2,8 +2,8 @@ package editor
import ( import (
"github.com/akyoto/hash" "github.com/akyoto/hash"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/animediff" "github.com/animenotifier/notify.moe/utils/animediff"
) )

View File

@ -4,8 +4,8 @@ import (
"sort" "sort"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )

View File

@ -6,8 +6,8 @@ import (
"github.com/animenotifier/notify.moe/utils/animediff" "github.com/animenotifier/notify.moe/utils/animediff"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "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. // diff returns all the differences between an anime and its MAL counterpart.
func diff(anime *arn.Anime, malAnime *mal.Anime) []animediff.Difference { 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 var differences []animediff.Difference
// We'll use the following diffs // We'll use the following diffs

View File

@ -6,8 +6,8 @@ import (
"net/http" "net/http"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )

View File

@ -7,8 +7,8 @@ import (
"strconv" "strconv"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )

View File

@ -47,11 +47,12 @@ func Anime(ctx aero.Context) error {
continue continue
} }
if anime.Type == "tv" { switch anime.Type {
case "tv":
tv = append(tv, anime) tv = append(tv, anime)
} else if anime.Type == "movie" { case "movie":
movies = append(movies, anime) movies = append(movies, anime)
} else { default:
continue continue
} }

View File

@ -1,7 +1,7 @@
package upload package upload
// We need these to decode uploaded images.
import ( import (
// We need these to decode uploaded images.
_ "image/gif" _ "image/gif"
_ "image/jpeg" _ "image/jpeg"
_ "image/png" _ "image/png"

View File

@ -5,8 +5,8 @@ import (
"time" "time"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
"github.com/animenotifier/notify.moe/arn"
) )
var malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil)) var malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil))

View File

@ -2,6 +2,7 @@ package editform
import ( import (
"fmt" "fmt"
"io"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -185,7 +186,7 @@ func RenderField(b *strings.Builder, v *reflect.Value, field reflect.StructField
} }
// String field // 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") idType := field.Tag.Get("idType")
// Try to infer the ID type by the field name // 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("<div class='widget-section-with-preview'>") b.WriteString("<div class='widget-section-with-preview'>")
} }
// Input field switch {
if field.Tag.Get("datalist") != "" { case field.Tag.Get("datalist") != "":
dataList := field.Tag.Get("datalist") dataList := field.Tag.Get("datalist")
values := arn.DataLists[dataList] values := arn.DataLists[dataList]
b.WriteString(components.InputSelection(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip"), values)) 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"))) 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") endpoint := field.Tag.Get("endpoint")
id := v.FieldByName("ID").String() id := v.FieldByName("ID").String()
endpoint = strings.Replace(endpoint, ":id", id, 1) endpoint = strings.Replace(endpoint, ":id", id, 1)
b.WriteString(components.InputFileUpload(idPrefix+field.Name, field.Name, field.Tag.Get("filetype"), endpoint)) 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"))) b.WriteString(components.InputText(idPrefix+field.Name, fieldValue.String(), field.Name, field.Tag.Get("tooltip")))
} }