From 506fd3c0a79c3a0f00bc1e2e96e45241fbd0029e Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 21 Oct 2019 14:02:09 +0900 Subject: [PATCH] Fixed linter errors --- .golangci.yml | 5 +- arn/validate/Validate.go | 4 +- arn/validate/Validate_test.go | 3 + auth/twitter.go | 2 - graphql/graphql.go | 72 +++++++++---------- .../delete-broken-episodes.go | 2 +- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4d72eb1f..b1567073 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,9 @@ linters: - gochecknoglobals - gochecknoinits - gocyclo + - gocognit + - gosec - maligned - stylecheck - - funlen \ No newline at end of file + - funlen + - wsl \ No newline at end of file diff --git a/arn/validate/Validate.go b/arn/validate/Validate.go index 6148d32f..08492a88 100644 --- a/arn/validate/Validate.go +++ b/arn/validate/Validate.go @@ -22,6 +22,7 @@ const ( var ( 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. @@ -70,8 +71,7 @@ func YearMonth(date string) bool { // Email tests if the given email address is valid. func Email(email string) bool { - // TODO: Add email check - return email != "" + return emailRegex.MatchString(email) } // URI validates a URI. diff --git a/arn/validate/Validate_test.go b/arn/validate/Validate_test.go index 4832be69..33031f6b 100644 --- a/arn/validate/Validate_test.go +++ b/arn/validate/Validate_test.go @@ -28,6 +28,9 @@ func TestIsValidNick(t *testing.T) { func TestIsValidEmail(t *testing.T) { 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")) } diff --git a/auth/twitter.go b/auth/twitter.go index e23dac88..6a28fa2a 100644 --- a/auth/twitter.go +++ b/auth/twitter.go @@ -164,8 +164,6 @@ func InstallTwitterAuth(app *aero.Application) { user.Nick = "tw" + twUser.ID user.Email = twUser.Email user.LastLogin = arn.DateTimeUTC() - - // TODO: The full name is in the Name field user.FirstName = twUser.Name // Save basic user info already to avoid data inconsistency problems diff --git a/graphql/graphql.go b/graphql/graphql.go index 4e79fbd1..7456fbe1 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -1,9 +1,7 @@ package graphql import ( - "errors" "fmt" - "reflect" "strings" "github.com/aerogo/aero" @@ -39,55 +37,55 @@ func Install(app *aero.Application) { }) // Like objects - api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) { - if !strings.HasPrefix(name, "like") { - return nil, nil, false - } + // api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) { + // if !strings.HasPrefix(name, "like") { + // return nil, nil, false + // } - id, ok := arguments["ID"].(string) + // id, ok := arguments["ID"].(string) - if !ok { - return nil, fmt.Errorf("'%s' needs to specify an ID", name), true - } + // if !ok { + // return nil, fmt.Errorf("'%s' needs to specify an ID", name), true + // } - typeName := strings.TrimPrefix(name, "like") - obj, err := arn.DB.Get(typeName, id) + // typeName := strings.TrimPrefix(name, "like") + // obj, err := arn.DB.Get(typeName, id) - if err != nil { - return nil, err, true - } + // if err != nil { + // return nil, err, true + // } - field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft") + // field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft") - if field.IsValid() && field.Bool() { - return nil, errors.New("Drafts need to be published before they can be liked"), true - } + // if field.IsValid() && field.Bool() { + // 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 { - return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true - } + // if !ok { + // return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true + // } - // TODO: Authentication - // user := GetUserFromContext(ctx) + // // TODO: Authentication + // // user := GetUserFromContext(ctx) - // if user == nil { - // return errors.New("Not logged in") - // } + // // if user == nil { + // // return errors.New("Not logged in") + // // } - // likeable.Like(user.ID) + // // likeable.Like(user.ID) - // Call OnLike if the object implements it - // receiver, ok := likeable.(LikeEventReceiver) + // // Call OnLike if the object implements it + // // receiver, ok := likeable.(LikeEventReceiver) - // if ok { - // receiver.OnLike(user) - // } + // // if ok { + // // receiver.OnLike(user) + // // } - likeable.Save() - return obj, nil, true - }) + // likeable.Save() + // return obj, nil, true + // }) app.Post("/graphql", api.Handler()) } diff --git a/patches/delete-broken-episodes/delete-broken-episodes.go b/patches/delete-broken-episodes/delete-broken-episodes.go index b9062cd1..86a07f88 100644 --- a/patches/delete-broken-episodes/delete-broken-episodes.go +++ b/patches/delete-broken-episodes/delete-broken-episodes.go @@ -16,7 +16,7 @@ func main() { if anime == nil { color.Yellow(episode.AnimeID) - episode.Delete() + _ = episode.Delete() count++ } }