Skip to content

Commit

Permalink
fix ci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tanqiangyes committed Oct 11, 2023
1 parent 5e6ecaf commit 4281d50
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/tanqiangyes/govalidator

go 1.20

require golang.org/x/exp v0.0.0-20231006140011-7918f672742d
require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/text v0.13.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
2 changes: 1 addition & 1 deletion patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const (
var (
userRegexp = regexp.MustCompile("^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+$")
hostRegexp = regexp.MustCompile(`^[^\\s]+\\.[^\\s]+$`)
userDotRegexp = regexp.MustCompile("(^[.]{1})|([.]{1}$)|([.]{2,})")
userDotRegexp = regexp.MustCompile(`(^[.]{1})|([.]{1}$)|([.]{2,})`)
rxEmail = regexp.MustCompile(Email)
rxCreditCard = regexp.MustCompile(CreditCard)
rxISBN10 = regexp.MustCompile(ISBN10)
Expand Down
10 changes: 5 additions & 5 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ var ParamTagMap = map[string]ParamValidator[string]{
var ParamTagRegexMap = map[string]*regexp.Regexp{
"range": regexp.MustCompile(`^range\\((\\d+(?:.\\d+)?)\\|(\\d+(?:.\\d+)?)\\)$`),
"length": regexp.MustCompile(`^length\\((\\d+)\\|(\\d+)\\)$`),
"runelength": regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
"stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
"runelength": regexp.MustCompile(`^runelength\\((\\d+)\\|(\\d+)\\)$`),
"stringlength": regexp.MustCompile(`^stringlength\\((\\d+)\\|(\\d+)\\)$`),
"in": regexp.MustCompile(`^in\((.*)\)`),
"matches": regexp.MustCompile(`^matches\((.+)\)$`),
"rsapub": regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
"minstringlength": regexp.MustCompile("^minstringlength\\((\\d+)\\)$"),
"maxstringlength": regexp.MustCompile("^maxstringlength\\((\\d+)\\)$"),
"rsapub": regexp.MustCompile(`^rsapub\\((\\d+)\\)$`),
"minstringlength": regexp.MustCompile(`^minstringlength\\((\\d+)\\)$`),
"maxstringlength": regexp.MustCompile(`^maxstringlength\\((\\d+)\\)$`),
}

type customTypeTagMap[T any] struct {
Expand Down
6 changes: 5 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"strings"
"unicode"
"unicode/utf8"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// Contains checks if the string contains the substring.
Expand Down Expand Up @@ -99,7 +102,8 @@ func addSegment(inrune, segment []rune) []rune {
// UnderscoreToCamelCase converts from underscore separated form to camel case form.
// Ex.: my_func => MyFunc
func UnderscoreToCamelCase[T ~string](s T) string {
return strings.Replace(strings.Title(strings.Replace(strings.ToLower(string(s)), "_", " ", -1)), " ", "", -1)
caser := cases.Title(language.English)
return strings.Replace(caser.String(strings.Replace(strings.ToLower(string(s)), "_", " ", -1)), " ", "", -1)
}

// CamelCaseToUnderscore converts from camel case form to underscore separated form.
Expand Down
2 changes: 1 addition & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestUnderscoreToCamelCase(t *testing.T) {
}{
{"a_b_c", "ABC"},
{"my_func", "MyFunc"},
{"1ab_cd", "1abCd"},
{"1ab_cd", "1AbCd"},
}
for _, test := range tests {
actual := UnderscoreToCamelCase(test.param)
Expand Down
1 change: 1 addition & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ func (sv stringValues) Less(i, j int) bool { return sv.get(i) < sv.get(j) }

func (sv stringValues) get(i int) string { return sv[i].String() }

// IsE164 returns true if is E164
func IsE164[T ~string](str T) bool {
return rxE164.MatchString(string(str))
}
2 changes: 1 addition & 1 deletion validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ type FieldRequiredByDefault struct {
}

type MultipleFieldsRequiredByDefault struct {
Url string `valid:"url"`
URL string `valid:"url"`
Email string `valid:"email"`
}

Expand Down

0 comments on commit 4281d50

Please sign in to comment.