Skip to content

Commit d07eb88

Browse files
author
Dean Karn
authored
Pr cleanup (#767)
* cleanup after merging PRs * Add maintainer info +
1 parent a53d64f commit d07eb88

13 files changed

+218
-198
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @go-playground/validator-maintainers

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- [ ] I have looked at the documentation [here](https://pkg.go.dev/github.com/go-playground/validator/v10#section-documentation) first?
2+
- [ ] I have looked at the examples provided that may showcase my question [here](/_examples)?
3+
14
### Package version eg. v9, v10:
25

36

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
**Make sure that you've checked the boxes below before you submit PR:**
55
- [ ] Tests exist or have been written that cover this particular change.
66

7-
@go-playground/admins
7+
@go-playground/validator-maintainers

.github/workflows/workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.14.x, 1.15.x]
11+
go-version: [1.15.x, 1.16.x]
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:
@@ -32,7 +32,7 @@ jobs:
3232
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...
3333

3434
- name: Send Coverage
35-
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.15.x'
35+
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.16.x'
3636
uses: shogo82148/actions-goveralls@v1
3737
with:
3838
path-to-profile: profile.cov
@@ -45,4 +45,4 @@ jobs:
4545
- name: golangci-lint
4646
uses: golangci/golangci-lint-action@v2
4747
with:
48-
version: v1.31
48+
version: v1.39

MAINTAINERS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Maintainers Guide
2+
3+
### Semantic Versioning
4+
Semantic versioning as defined [here](https://semver.org) must be strictly adhered to.
5+
6+
### External Dependencies
7+
Any new external dependencies MUST:
8+
- Have a compatible LICENSE present.
9+
- Be actively maintained.
10+
- Be approved by @go-playground/admins
11+
12+
### PR Merge Requirements
13+
- Up-to-date branch.
14+
- Passing tests and linting.
15+
- CODEOWNERS approval.
16+
- Tests that cover both the Happy and Unhappy paths.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ GOCMD=GO111MODULE=on go
33
linters-install:
44
@golangci-lint --version >/dev/null 2>&1 || { \
55
echo "installing linting tools..."; \
6-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0; \
6+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.39.0; \
77
}
88

99
lint: linters-install
10-
$(PWD)/bin/golangci-lint run
10+
golangci-lint run
1111

1212
test:
1313
$(GOCMD) test -cover -race ./...

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package validator
2-
================
2+
=================
33
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4-
![Project status](https://img.shields.io/badge/version-10.5.0-green.svg)
4+
![Project status](https://img.shields.io/badge/version-10.6.0-green.svg)
55
[![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator)
66
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)
@@ -295,5 +295,10 @@ How to Contribute
295295
Make a pull request...
296296

297297
License
298-
------
298+
-------
299299
Distributed under MIT License, please see license file within the code for more details.
300+
301+
Maintainers
302+
-----------
303+
This project has grown large enough that more than one person is required to properly support the community.
304+
If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn

baked_in.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ var (
192192
"bcp47_language_tag": isBCP47LanguageTag,
193193
"postcode_iso3166_alpha2": isPostcodeByIso3166Alpha2,
194194
"postcode_iso3166_alpha2_field": isPostcodeByIso3166Alpha2Field,
195-
"bic": isIsoBicFormat,
195+
"bic": isIsoBicFormat,
196196
}
197197
)
198198

@@ -552,7 +552,7 @@ func isEthereumAddress(fl FieldLevel) bool {
552552
return false
553553
}
554554

555-
if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
555+
if ethAddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
556556
return true
557557
}
558558

@@ -1225,8 +1225,6 @@ func isPostcodeByIso3166Alpha2(fl FieldLevel) bool {
12251225
// example: `postcode_iso3166_alpha2_field=CountryCode`
12261226
func isPostcodeByIso3166Alpha2Field(fl FieldLevel) bool {
12271227
field := fl.Field()
1228-
kind := field.Kind()
1229-
12301228
params := parseOneOfParam2(fl.Param())
12311229

12321230
if len(params) != 1 {
@@ -1390,7 +1388,7 @@ func isRGB(fl FieldLevel) bool {
13901388

13911389
// IsHEXColor is the validation function for validating if the current field's value is a valid HEX color.
13921390
func isHEXColor(fl FieldLevel) bool {
1393-
return hexcolorRegex.MatchString(fl.Field().String())
1391+
return hexColorRegex.MatchString(fl.Field().String())
13941392
}
13951393

13961394
// IsHexadecimal is the validation function for validating if the current field's value is a valid hexadecimal.
@@ -2363,9 +2361,5 @@ func isBCP47LanguageTag(fl FieldLevel) bool {
23632361
func isIsoBicFormat(fl FieldLevel) bool {
23642362
bicString := fl.Field().String()
23652363

2366-
if !bicRegex.MatchString(bicString) {
2367-
return false
2368-
}
2369-
2370-
return true
2364+
return bicRegex.MatchString(bicString)
23712365
}

errors.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,23 @@ func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslati
8282
// FieldError contains all functions to get error details
8383
type FieldError interface {
8484

85-
// returns the validation tag that failed. if the
85+
// Tag returns the validation tag that failed. if the
8686
// validation was an alias, this will return the
8787
// alias name and not the underlying tag that failed.
8888
//
8989
// eg. alias "iscolor": "hexcolor|rgb|rgba|hsl|hsla"
9090
// will return "iscolor"
9191
Tag() string
9292

93-
// returns the validation tag that failed, even if an
93+
// ActualTag returns the validation tag that failed, even if an
9494
// alias the actual tag within the alias will be returned.
9595
// If an 'or' validation fails the entire or will be returned.
9696
//
9797
// eg. alias "iscolor": "hexcolor|rgb|rgba|hsl|hsla"
9898
// will return "hexcolor|rgb|rgba|hsl|hsla"
9999
ActualTag() string
100100

101-
// returns the namespace for the field error, with the tag
101+
// Namespace returns the namespace for the field error, with the tag
102102
// name taking precedence over the field's actual name.
103103
//
104104
// eg. JSON name "User.fname"
@@ -109,7 +109,7 @@ type FieldError interface {
109109
// using validate.Field(...) as there is no way to extract it's name
110110
Namespace() string
111111

112-
// returns the namespace for the field error, with the field's
112+
// StructNamespace returns the namespace for the field error, with the field's
113113
// actual name.
114114
//
115115
// eq. "User.FirstName" see Namespace for comparison
@@ -118,24 +118,24 @@ type FieldError interface {
118118
// using validate.Field(...) as there is no way to extract its name
119119
StructNamespace() string
120120

121-
// returns the fields name with the tag name taking precedence over the
121+
// Field returns the fields name with the tag name taking precedence over the
122122
// field's actual name.
123123
//
124124
// eq. JSON name "fname"
125125
// see StructField for comparison
126126
Field() string
127127

128-
// returns the field's actual name from the struct, when able to determine.
128+
// StructField returns the field's actual name from the struct, when able to determine.
129129
//
130130
// eq. "FirstName"
131131
// see Field for comparison
132132
StructField() string
133133

134-
// returns the actual field's value in case needed for creating the error
134+
// Value returns the actual field's value in case needed for creating the error
135135
// message
136136
Value() interface{}
137137

138-
// returns the param value, in string form for comparison; this will also
138+
// Param returns the param value, in string form for comparison; this will also
139139
// help with generating an error message
140140
Param() string
141141

@@ -149,7 +149,7 @@ type FieldError interface {
149149
// eg. time.Time's type is time.Time
150150
Type() reflect.Type
151151

152-
// returns the FieldError's translated error
152+
// Translate returns the FieldError's translated error
153153
// from the provided 'ut.Translator' and registered 'TranslationFunc'
154154
//
155155
// NOTE: if no registered translator can be found it returns the same as
@@ -221,7 +221,7 @@ func (fe *fieldError) Field() string {
221221
// return fld
222222
}
223223

224-
// returns the field's actual name from the struct, when able to determine.
224+
// StructField returns the field's actual name from the struct, when able to determine.
225225
func (fe *fieldError) StructField() string {
226226
// return fe.structField
227227
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]

field_level.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ import "reflect"
55
// FieldLevel contains all the information and helper functions
66
// to validate a field
77
type FieldLevel interface {
8-
// returns the top level struct, if any
8+
9+
// Top returns the top level struct, if any
910
Top() reflect.Value
1011

11-
// returns the current fields parent struct, if any or
12+
// Parent returns the current fields parent struct, if any or
1213
// the comparison value if called 'VarWithValue'
1314
Parent() reflect.Value
1415

15-
// returns current field for validation
16+
// Field returns current field for validation
1617
Field() reflect.Value
1718

18-
// returns the field's name with the tag
19+
// FieldName returns the field's name with the tag
1920
// name taking precedence over the fields actual name.
2021
FieldName() string
2122

22-
// returns the struct field's name
23+
// StructFieldName returns the struct field's name
2324
StructFieldName() string
2425

25-
// returns param for validation against current field
26+
// Param returns param for validation against current field
2627
Param() string
2728

2829
// GetTag returns the current validations tag name
@@ -33,7 +34,7 @@ type FieldLevel interface {
3334
// underlying value and it's kind.
3435
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
3536

36-
// traverses the parent struct to retrieve a specific field denoted by the provided namespace
37+
// GetStructFieldOK traverses the parent struct to retrieve a specific field denoted by the provided namespace
3738
// in the param and returns the field, field kind and whether is was successful in retrieving
3839
// the field at all.
3940
//
@@ -49,15 +50,15 @@ type FieldLevel interface {
4950
// Deprecated: Use GetStructFieldOKAdvanced2() instead which also return if the value is nullable.
5051
GetStructFieldOKAdvanced(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool)
5152

52-
// traverses the parent struct to retrieve a specific field denoted by the provided namespace
53+
// GetStructFieldOK2 traverses the parent struct to retrieve a specific field denoted by the provided namespace
5354
// in the param and returns the field, field kind, if it's a nullable type and whether is was successful in retrieving
5455
// the field at all.
5556
//
5657
// NOTE: when not successful ok will be false, this can happen when a nested struct is nil and so the field
5758
// could not be retrieved because it didn't exist.
5859
GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool)
5960

60-
// GetStructFieldOKAdvanced is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
61+
// GetStructFieldOKAdvanced2 is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
6162
// the field and namespace allowing more extensibility for validators.
6263
GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool)
6364
}
@@ -107,12 +108,12 @@ func (v *validate) GetStructFieldOKAdvanced(val reflect.Value, namespace string)
107108
return current, kind, found
108109
}
109110

110-
// GetStructFieldOK returns Param returns param for validation against current field
111+
// GetStructFieldOK2 returns Param returns param for validation against current field
111112
func (v *validate) GetStructFieldOK2() (reflect.Value, reflect.Kind, bool, bool) {
112113
return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
113114
}
114115

115-
// GetStructFieldOKAdvanced is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
116+
// GetStructFieldOKAdvanced2 is the same as GetStructFieldOK except that it accepts the parent struct to start looking for
116117
// the field and namespace allowing more extensibility for validators.
117118
func (v *validate) GetStructFieldOKAdvanced2(val reflect.Value, namespace string) (reflect.Value, reflect.Kind, bool, bool) {
118119
return v.getStructFieldOKInternal(val, namespace)

regexes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const (
1010
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
1111
numberRegexString = "^[0-9]+$"
1212
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
13-
hexcolorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
13+
hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
1414
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
1515
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
1616
hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$"
@@ -60,7 +60,7 @@ var (
6060
numericRegex = regexp.MustCompile(numericRegexString)
6161
numberRegex = regexp.MustCompile(numberRegexString)
6262
hexadecimalRegex = regexp.MustCompile(hexadecimalRegexString)
63-
hexcolorRegex = regexp.MustCompile(hexcolorRegexString)
63+
hexColorRegex = regexp.MustCompile(hexColorRegexString)
6464
rgbRegex = regexp.MustCompile(rgbRegexString)
6565
rgbaRegex = regexp.MustCompile(rgbaRegexString)
6666
hslRegex = regexp.MustCompile(hslRegexString)
@@ -93,7 +93,7 @@ var (
9393
btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32)
9494
btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32)
9595
ethAddressRegex = regexp.MustCompile(ethAddressRegexString)
96-
ethaddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString)
96+
ethAddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString)
9797
ethAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString)
9898
uRLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString)
9999
hTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString)

struct_level.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
2323
// to validate a struct
2424
type StructLevel interface {
2525

26-
// returns the main validation object, in case one wants to call validations internally.
26+
// Validator returns the main validation object, in case one wants to call validations internally.
2727
// this is so you don't have to use anonymous functions to get access to the validate
2828
// instance.
2929
Validator() *Validate
3030

31-
// returns the top level struct, if any
31+
// Top returns the top level struct, if any
3232
Top() reflect.Value
3333

34-
// returns the current fields parent struct, if any
34+
// Parent returns the current fields parent struct, if any
3535
Parent() reflect.Value
3636

37-
// returns the current struct.
37+
// Current returns the current struct.
3838
Current() reflect.Value
3939

4040
// ExtractType gets the actual underlying type of field value.
4141
// It will dive into pointers, customTypes and return you the
4242
// underlying value and its kind.
4343
ExtractType(field reflect.Value) (value reflect.Value, kind reflect.Kind, nullable bool)
4444

45-
// reports an error just by passing the field and tag information
45+
// ReportError reports an error just by passing the field and tag information
4646
//
4747
// NOTES:
4848
//
@@ -54,7 +54,7 @@ type StructLevel interface {
5454
// and process on the flip side it's up to you.
5555
ReportError(field interface{}, fieldName, structFieldName string, tag, param string)
5656

57-
// reports an error just by passing ValidationErrors
57+
// ReportValidationErrors reports an error just by passing ValidationErrors
5858
//
5959
// NOTES:
6060
//

0 commit comments

Comments
 (0)