Fixed linter errors

This commit is contained in:
Eduard Urbach 2019-10-21 14:02:09 +09:00
parent 1819367160
commit 506fd3c0a7
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 45 additions and 43 deletions

View File

@ -11,6 +11,9 @@ linters:
- gochecknoglobals - gochecknoglobals
- gochecknoinits - gochecknoinits
- gocyclo - gocyclo
- gocognit
- gosec
- maligned - maligned
- stylecheck - stylecheck
- funlen - funlen
- wsl

View File

@ -22,6 +22,7 @@ const (
var ( var (
discordNickRegex = regexp.MustCompile(`^([^#]{2,32})#(\d{4})$`) discordNickRegex = regexp.MustCompile(`^([^#]{2,32})#(\d{4})$`)
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
) )
// Nick tests if the given nickname is valid. // Nick tests if the given nickname is valid.
@ -70,8 +71,7 @@ func YearMonth(date string) bool {
// Email tests if the given email address is valid. // Email tests if the given email address is valid.
func Email(email string) bool { func Email(email string) bool {
// TODO: Add email check return emailRegex.MatchString(email)
return email != ""
} }
// URI validates a URI. // URI validates a URI.

View File

@ -28,6 +28,9 @@ func TestIsValidNick(t *testing.T) {
func TestIsValidEmail(t *testing.T) { func TestIsValidEmail(t *testing.T) {
assert.False(t, validate.Email("")) assert.False(t, validate.Email(""))
assert.False(t, validate.Email("ç$€§/az@gmail.com"))
assert.False(t, validate.Email("abc@gmail_yahoo.com"))
assert.True(t, validate.Email("abc@gmail-yahoo.com"))
assert.True(t, validate.Email("support@notify.moe")) assert.True(t, validate.Email("support@notify.moe"))
} }

View File

@ -164,8 +164,6 @@ func InstallTwitterAuth(app *aero.Application) {
user.Nick = "tw" + twUser.ID user.Nick = "tw" + twUser.ID
user.Email = twUser.Email user.Email = twUser.Email
user.LastLogin = arn.DateTimeUTC() user.LastLogin = arn.DateTimeUTC()
// TODO: The full name is in the Name field
user.FirstName = twUser.Name user.FirstName = twUser.Name
// Save basic user info already to avoid data inconsistency problems // Save basic user info already to avoid data inconsistency problems

View File

@ -1,9 +1,7 @@
package graphql package graphql
import ( import (
"errors"
"fmt" "fmt"
"reflect"
"strings" "strings"
"github.com/aerogo/aero" "github.com/aerogo/aero"
@ -39,55 +37,55 @@ func Install(app *aero.Application) {
}) })
// Like objects // Like objects
api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) { // api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
if !strings.HasPrefix(name, "like") { // if !strings.HasPrefix(name, "like") {
return nil, nil, false // return nil, nil, false
} // }
id, ok := arguments["ID"].(string) // id, ok := arguments["ID"].(string)
if !ok { // if !ok {
return nil, fmt.Errorf("'%s' needs to specify an ID", name), true // return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
} // }
typeName := strings.TrimPrefix(name, "like") // typeName := strings.TrimPrefix(name, "like")
obj, err := arn.DB.Get(typeName, id) // obj, err := arn.DB.Get(typeName, id)
if err != nil { // if err != nil {
return nil, err, true // return nil, err, true
} // }
field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft") // field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft")
if field.IsValid() && field.Bool() { // if field.IsValid() && field.Bool() {
return nil, errors.New("Drafts need to be published before they can be liked"), true // return nil, errors.New("Drafts need to be published before they can be liked"), true
} // }
likeable, ok := obj.(arn.Likeable) // likeable, ok := obj.(arn.Likeable)
if !ok { // if !ok {
return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true // return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true
} // }
// TODO: Authentication // // TODO: Authentication
// user := GetUserFromContext(ctx) // // user := GetUserFromContext(ctx)
// if user == nil { // // if user == nil {
// return errors.New("Not logged in") // // return errors.New("Not logged in")
// } // // }
// likeable.Like(user.ID) // // likeable.Like(user.ID)
// Call OnLike if the object implements it // // Call OnLike if the object implements it
// receiver, ok := likeable.(LikeEventReceiver) // // receiver, ok := likeable.(LikeEventReceiver)
// if ok { // // if ok {
// receiver.OnLike(user) // // receiver.OnLike(user)
// } // // }
likeable.Save() // likeable.Save()
return obj, nil, true // return obj, nil, true
}) // })
app.Post("/graphql", api.Handler()) app.Post("/graphql", api.Handler())
} }

View File

@ -16,7 +16,7 @@ func main() {
if anime == nil { if anime == nil {
color.Yellow(episode.AnimeID) color.Yellow(episode.AnimeID)
episode.Delete() _ = episode.Delete()
count++ count++
} }
} }