Skip to content

Commit 54da7fa

Browse files
author
Dean Karn
committed
fix linting and spelling errors
1 parent b297167 commit 54da7fa

File tree

13 files changed

+156
-125
lines changed

13 files changed

+156
-125
lines changed

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GOCMD=go
2+
3+
linters-install:
4+
$(GOCMD) get -u github.com/alecthomas/gometalinter
5+
gometalinter --install
6+
7+
lint: linters-install
8+
gometalinter --vendor --disable-all --enable=vet --enable=vetshadow --enable=golint --enable=maligned --enable=megacheck --enable=ineffassign --enable=misspell --enable=errcheck --enable=goconst ./...
9+
10+
test:
11+
$(GOCMD) test -cover -race ./...
12+
13+
bench:
14+
$(GOCMD) test -bench=. -benchmem ./...
15+
16+
.PHONY: test lint linters-install

README.md

Lines changed: 63 additions & 61 deletions
Large diffs are not rendered by default.

baked_in.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ func isBitcoinAddress(fl FieldLevel) bool {
440440
}
441441

442442
h := sha256.New()
443-
h.Write(decode[:21])
443+
_, _ = h.Write(decode[:21])
444444
d := h.Sum([]byte{})
445445
h = sha256.New()
446-
h.Write(d)
446+
_, _ = h.Write(d)
447447

448448
validchecksum := [4]byte{}
449449
computedchecksum := [4]byte{}
@@ -458,13 +458,13 @@ func isBitcoinAddress(fl FieldLevel) bool {
458458
func isBitcoinBech32Address(fl FieldLevel) bool {
459459
address := fl.Field().String()
460460

461-
if !btcLowerAddressRegexBech32.MatchString(address) && !btcUpperAddressRegexBech32.MatchString(address){
461+
if !btcLowerAddressRegexBech32.MatchString(address) && !btcUpperAddressRegexBech32.MatchString(address) {
462462
return false
463463
}
464464

465465
am := len(address) % 8
466466

467-
if am == 0 || am == 3 || am == 5{
467+
if am == 0 || am == 3 || am == 5 {
468468
return false
469469
}
470470

@@ -473,15 +473,16 @@ func isBitcoinBech32Address(fl FieldLevel) bool {
473473
alphabet := "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
474474

475475
hr := []int{3, 3, 0, 2, 3} // the human readable part will always be bc
476-
dp := []int{}
476+
addr := address[3:]
477+
dp := make([]int, 0, len(addr))
477478

478-
for _, c := range []rune(address[3:]) {
479+
for _, c := range addr {
479480
dp = append(dp, strings.IndexRune(alphabet, c))
480481
}
481482

482483
ver := dp[0]
483484

484-
if ver < 0 || ver > 16{
485+
if ver < 0 || ver > 16 {
485486
return false
486487
}
487488

@@ -493,16 +494,16 @@ func isBitcoinBech32Address(fl FieldLevel) bool {
493494

494495
values := append(hr, dp...)
495496

496-
GEN := []int{ 0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3 }
497+
GEN := []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3}
497498

498499
p := 1
499500

500501
for _, v := range values {
501502
b := p >> 25
502-
p = (p & 0x1ffffff) << 5 ^ v
503+
p = (p&0x1ffffff)<<5 ^ v
503504

504505
for i := 0; i < 5; i++ {
505-
if (b >> uint(i)) & 1 == 1 {
506+
if (b>>uint(i))&1 == 1 {
506507
p ^= GEN[i]
507508
}
508509
}
@@ -515,18 +516,18 @@ func isBitcoinBech32Address(fl FieldLevel) bool {
515516
b := uint(0)
516517
acc := 0
517518
mv := (1 << 5) - 1
518-
sw := []int{}
519+
var sw []int
519520

520-
for _, v := range dp[1:len(dp) - 6]{
521+
for _, v := range dp[1 : len(dp)-6] {
521522
acc = (acc << 5) | v
522523
b += 5
523-
for b >= 8{
524+
for b >= 8 {
524525
b -= 8
525526
sw = append(sw, (acc>>b)&mv)
526527
}
527528
}
528529

529-
if len(sw) < 2 || len(sw) > 40{
530+
if len(sw) < 2 || len(sw) > 40 {
530531
return false
531532
}
532533

cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias s
223223
current.typeof = typeKeys
224224

225225
if i == 0 || prevTag != typeDive {
226-
panic(fmt.Sprintf("'%s' tag must be immediately preceeded by the '%s' tag", keysTag, diveTag))
226+
panic(fmt.Sprintf("'%s' tag must be immediately preceded by the '%s' tag", keysTag, diveTag))
227227
}
228228

229229
current.typeof = typeKeys

doc.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ StructOnly
168168
169169
When a field that is a nested struct is encountered, and contains this flag
170170
any validation on the nested struct will be run, but none of the nested
171-
struct fields will be validated. This is usefull if inside of you program
171+
struct fields will be validated. This is useful if inside of you program
172172
you know the struct will be valid, but need to verify it has been assigned.
173173
NOTE: only "required" and "omitempty" can be used on a struct itself.
174174
@@ -772,103 +772,103 @@ This validates that a string value contains a valid U.S. Social Security Number.
772772
773773
Internet Protocol Address IP
774774
775-
This validates that a string value contains a valid IP Adress.
775+
This validates that a string value contains a valid IP Address.
776776
777777
Usage: ip
778778
779779
Internet Protocol Address IPv4
780780
781-
This validates that a string value contains a valid v4 IP Adress.
781+
This validates that a string value contains a valid v4 IP Address.
782782
783783
Usage: ipv4
784784
785785
Internet Protocol Address IPv6
786786
787-
This validates that a string value contains a valid v6 IP Adress.
787+
This validates that a string value contains a valid v6 IP Address.
788788
789789
Usage: ipv6
790790
791791
Classless Inter-Domain Routing CIDR
792792
793-
This validates that a string value contains a valid CIDR Adress.
793+
This validates that a string value contains a valid CIDR Address.
794794
795795
Usage: cidr
796796
797797
Classless Inter-Domain Routing CIDRv4
798798
799-
This validates that a string value contains a valid v4 CIDR Adress.
799+
This validates that a string value contains a valid v4 CIDR Address.
800800
801801
Usage: cidrv4
802802
803803
Classless Inter-Domain Routing CIDRv6
804804
805-
This validates that a string value contains a valid v6 CIDR Adress.
805+
This validates that a string value contains a valid v6 CIDR Address.
806806
807807
Usage: cidrv6
808808
809809
Transmission Control Protocol Address TCP
810810
811-
This validates that a string value contains a valid resolvable TCP Adress.
811+
This validates that a string value contains a valid resolvable TCP Address.
812812
813813
Usage: tcp_addr
814814
815815
Transmission Control Protocol Address TCPv4
816816
817-
This validates that a string value contains a valid resolvable v4 TCP Adress.
817+
This validates that a string value contains a valid resolvable v4 TCP Address.
818818
819819
Usage: tcp4_addr
820820
821821
Transmission Control Protocol Address TCPv6
822822
823-
This validates that a string value contains a valid resolvable v6 TCP Adress.
823+
This validates that a string value contains a valid resolvable v6 TCP Address.
824824
825825
Usage: tcp6_addr
826826
827827
User Datagram Protocol Address UDP
828828
829-
This validates that a string value contains a valid resolvable UDP Adress.
829+
This validates that a string value contains a valid resolvable UDP Address.
830830
831831
Usage: udp_addr
832832
833833
User Datagram Protocol Address UDPv4
834834
835-
This validates that a string value contains a valid resolvable v4 UDP Adress.
835+
This validates that a string value contains a valid resolvable v4 UDP Address.
836836
837837
Usage: udp4_addr
838838
839839
User Datagram Protocol Address UDPv6
840840
841-
This validates that a string value contains a valid resolvable v6 UDP Adress.
841+
This validates that a string value contains a valid resolvable v6 UDP Address.
842842
843843
Usage: udp6_addr
844844
845845
Internet Protocol Address IP
846846
847-
This validates that a string value contains a valid resolvable IP Adress.
847+
This validates that a string value contains a valid resolvable IP Address.
848848
849849
Usage: ip_addr
850850
851851
Internet Protocol Address IPv4
852852
853-
This validates that a string value contains a valid resolvable v4 IP Adress.
853+
This validates that a string value contains a valid resolvable v4 IP Address.
854854
855855
Usage: ip4_addr
856856
857857
Internet Protocol Address IPv6
858858
859-
This validates that a string value contains a valid resolvable v6 IP Adress.
859+
This validates that a string value contains a valid resolvable v6 IP Address.
860860
861861
Usage: ip6_addr
862862
863863
Unix domain socket end point Address
864864
865-
This validates that a string value contains a valid Unix Adress.
865+
This validates that a string value contains a valid Unix Address.
866866
867867
Usage: unix_addr
868868
869869
Media Access Control Address MAC
870870
871-
This validates that a string value contains a valid MAC Adress.
871+
This validates that a string value contains a valid MAC Address.
872872
873873
Usage: mac
874874
@@ -913,7 +913,7 @@ Validator notes:
913913
of a regex which conflict with the validation definitions. Although
914914
workarounds can be made, they take away from using pure regex's.
915915
Furthermore it's quick and dirty but the regex's become harder to
916-
maintain and are not reusable, so it's as much a programming philosiphy
916+
maintain and are not reusable, so it's as much a programming philosophy
917917
as anything.
918918
919919
In place of this new validator functions should be created; a regex can

field_level.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type FieldLevel interface {
1717
Field() reflect.Value
1818

1919
// returns the field's name with the tag
20-
// name takeing precedence over the fields actual name.
20+
// name taking precedence over the fields actual name.
2121
FieldName() string
2222

2323
// returns the struct field's name

translations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import ut "github.com/go-playground/universal-translator"
77
type TranslationFunc func(ut ut.Translator, fe FieldError) string
88

99
// RegisterTranslationsFunc allows for registering of translations
10-
// for a 'ut.Translator' for use withing the 'TranslationFunc'
10+
// for a 'ut.Translator' for use within the 'TranslationFunc'
1111
type RegisterTranslationsFunc func(ut ut.Translator) error

translations/en/en.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
429429

430430
case reflect.Struct:
431431
if fe.Type() != reflect.TypeOf(time.Time{}) {
432-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
432+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
433+
goto END
433434
}
434435

435436
t, err = ut.T("lt-datetime", fe.Field())
@@ -548,7 +549,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
548549

549550
case reflect.Struct:
550551
if fe.Type() != reflect.TypeOf(time.Time{}) {
551-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
552+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
553+
goto END
552554
}
553555

554556
t, err = ut.T("lte-datetime", fe.Field())
@@ -667,7 +669,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
667669

668670
case reflect.Struct:
669671
if fe.Type() != reflect.TypeOf(time.Time{}) {
670-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
672+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
673+
goto END
671674
}
672675

673676
t, err = ut.T("gt-datetime", fe.Field())
@@ -786,7 +789,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
786789

787790
case reflect.Struct:
788791
if fe.Type() != reflect.TypeOf(time.Time{}) {
789-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
792+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
793+
goto END
790794
}
791795

792796
t, err = ut.T("gte-datetime", fe.Field())

translations/fr/fr.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
429429

430430
case reflect.Struct:
431431
if fe.Type() != reflect.TypeOf(time.Time{}) {
432-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
432+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
433+
goto END
433434
}
434435

435436
t, err = ut.T("lt-datetime", fe.Field())
@@ -548,7 +549,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
548549

549550
case reflect.Struct:
550551
if fe.Type() != reflect.TypeOf(time.Time{}) {
551-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
552+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
553+
goto END
552554
}
553555

554556
t, err = ut.T("lte-datetime", fe.Field())
@@ -667,7 +669,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
667669

668670
case reflect.Struct:
669671
if fe.Type() != reflect.TypeOf(time.Time{}) {
670-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
672+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
673+
goto END
671674
}
672675

673676
t, err = ut.T("gt-datetime", fe.Field())
@@ -786,7 +789,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
786789

787790
case reflect.Struct:
788791
if fe.Type() != reflect.TypeOf(time.Time{}) {
789-
err = fmt.Errorf("tag '%s' cannot be used on a struct type.", fe.Tag())
792+
err = fmt.Errorf("tag '%s' cannot be used on a struct type", fe.Tag())
793+
goto END
790794
}
791795

792796
t, err = ut.T("gte-datetime", fe.Field())

translations/pt_BR/pt_BR.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
429429

430430
case reflect.Struct:
431431
if fe.Type() != reflect.TypeOf(time.Time{}) {
432-
err = fmt.Errorf("a tag '%s' não pode ser usada em uma struct type.", fe.Tag())
432+
err = fmt.Errorf("a tag '%s' não pode ser usada em uma struct type", fe.Tag())
433+
goto END
433434
}
434435

435436
t, err = ut.T("lt-datetime", fe.Field())
@@ -548,7 +549,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
548549

549550
case reflect.Struct:
550551
if fe.Type() != reflect.TypeOf(time.Time{}) {
551-
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type.", fe.Tag())
552+
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type", fe.Tag())
553+
goto END
552554
}
553555

554556
t, err = ut.T("lte-datetime", fe.Field())
@@ -667,7 +669,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
667669

668670
case reflect.Struct:
669671
if fe.Type() != reflect.TypeOf(time.Time{}) {
670-
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type.", fe.Tag())
672+
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type", fe.Tag())
673+
goto END
671674
}
672675

673676
t, err = ut.T("gt-datetime", fe.Field())
@@ -786,7 +789,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
786789

787790
case reflect.Struct:
788791
if fe.Type() != reflect.TypeOf(time.Time{}) {
789-
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type.", fe.Tag())
792+
err = fmt.Errorf("a tag '%s' não pode ser usado em uma struct type", fe.Tag())
793+
goto END
790794
}
791795

792796
t, err = ut.T("gte-datetime", fe.Field())

0 commit comments

Comments
 (0)