mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
fix(#1367): struct-tag with validate is missing built-in rules
This commit is contained in:
@@ -637,101 +637,127 @@ const (
|
||||
)
|
||||
|
||||
var validateSingleOptions = map[string]struct{}{
|
||||
"alpha": {},
|
||||
"alphanum": {},
|
||||
"alphanumunicode": {},
|
||||
"alphaunicode": {},
|
||||
"ascii": {},
|
||||
"base32": {},
|
||||
"base64": {},
|
||||
"base64url": {},
|
||||
"bcp47_language_tag": {},
|
||||
"boolean": {},
|
||||
"bic": {},
|
||||
"btc_addr": {},
|
||||
"btc_addr_bech32": {},
|
||||
"cidr": {},
|
||||
"cidrv4": {},
|
||||
"cidrv6": {},
|
||||
"country_code": {},
|
||||
"credit_card": {},
|
||||
"cron": {},
|
||||
"cve": {},
|
||||
"datauri": {},
|
||||
"dir": {},
|
||||
"dirpath": {},
|
||||
"dive": {},
|
||||
"dns_rfc1035_label": {},
|
||||
"e164": {},
|
||||
"email": {},
|
||||
"eth_addr": {},
|
||||
"file": {},
|
||||
"filepath": {},
|
||||
"fqdn": {},
|
||||
"hexadecimal": {},
|
||||
"hexcolor": {},
|
||||
"hostname": {},
|
||||
"hostname_port": {},
|
||||
"hostname_rfc1123": {},
|
||||
"hsl": {},
|
||||
"hsla": {},
|
||||
"html": {},
|
||||
"html_encoded": {},
|
||||
"image": {},
|
||||
"ip": {},
|
||||
"ip4_addr": {},
|
||||
"ip6_addr": {},
|
||||
"ip_addr": {},
|
||||
"ipv4": {},
|
||||
"ipv6": {},
|
||||
"isbn": {},
|
||||
"isbn10": {},
|
||||
"isbn13": {},
|
||||
"isdefault": {},
|
||||
"iso3166_1_alpha2": {},
|
||||
"iso3166_1_alpha3": {},
|
||||
"iscolor": {},
|
||||
"json": {},
|
||||
"jwt": {},
|
||||
"latitude": {},
|
||||
"longitude": {},
|
||||
"lowercase": {},
|
||||
"luhn_checksum": {},
|
||||
"mac": {},
|
||||
"mongodb": {},
|
||||
"mongodb_connection_string": {},
|
||||
"multibyte": {},
|
||||
"nostructlevel": {},
|
||||
"number": {},
|
||||
"numeric": {},
|
||||
"omitempty": {},
|
||||
"printascii": {},
|
||||
"required": {},
|
||||
"rgb": {},
|
||||
"rgba": {},
|
||||
"semver": {},
|
||||
"ssn": {},
|
||||
"structonly": {},
|
||||
"tcp_addr": {},
|
||||
"tcp4_addr": {},
|
||||
"tcp6_addr": {},
|
||||
"timezone": {},
|
||||
"udp4_addr": {},
|
||||
"udp6_addr": {},
|
||||
"ulid": {},
|
||||
"unique": {},
|
||||
"unix_addr": {},
|
||||
"uppercase": {},
|
||||
"uri": {},
|
||||
"url": {},
|
||||
"url_encoded": {},
|
||||
"urn_rfc2141": {},
|
||||
"uuid": {},
|
||||
"uuid3": {},
|
||||
"uuid4": {},
|
||||
"uuid5": {},
|
||||
"alpha": {},
|
||||
"alphanum": {},
|
||||
"alphanumunicode": {},
|
||||
"alphaunicode": {},
|
||||
"ascii": {},
|
||||
"base32": {},
|
||||
"base64": {},
|
||||
"base64rawurl": {},
|
||||
"base64url": {},
|
||||
"bcp47_language_tag": {},
|
||||
"bic": {},
|
||||
"boolean": {},
|
||||
"btc_addr": {},
|
||||
"btc_addr_bech32": {},
|
||||
"cidr": {},
|
||||
"cidrv4": {},
|
||||
"cidrv6": {},
|
||||
"credit_card": {},
|
||||
"cron": {},
|
||||
"cve": {},
|
||||
"datauri": {},
|
||||
"dir": {},
|
||||
"dirpath": {},
|
||||
"dive": {},
|
||||
"dns_rfc1035_label": {},
|
||||
"e164": {},
|
||||
"ein": {},
|
||||
"email": {},
|
||||
"eth_addr": {},
|
||||
"eth_addr_checksum": {},
|
||||
"file": {},
|
||||
"filepath": {},
|
||||
"fqdn": {},
|
||||
"hexadecimal": {},
|
||||
"hexcolor": {},
|
||||
"hostname": {},
|
||||
"hostname_port": {},
|
||||
"hostname_rfc1123": {},
|
||||
"hsl": {},
|
||||
"hsla": {},
|
||||
"html": {},
|
||||
"html_encoded": {},
|
||||
"http_url": {},
|
||||
"image": {},
|
||||
"ip": {},
|
||||
"ip_addr": {},
|
||||
"ip4_addr": {},
|
||||
"ip6_addr": {},
|
||||
"ipv4": {},
|
||||
"ipv6": {},
|
||||
"isbn": {},
|
||||
"isbn10": {},
|
||||
"isbn13": {},
|
||||
"isdefault": {},
|
||||
"iso3166_1_alpha_numeric": {},
|
||||
"iso3166_1_alpha_numeric_eu": {},
|
||||
"iso3166_1_alpha2": {},
|
||||
"iso3166_1_alpha2_eu": {},
|
||||
"iso3166_1_alpha3": {},
|
||||
"iso3166_1_alpha3_eu": {},
|
||||
"iso3166_2": {},
|
||||
"iso4217": {},
|
||||
"iso4217_numeric": {},
|
||||
"issn": {},
|
||||
"json": {},
|
||||
"jwt": {},
|
||||
"latitude": {},
|
||||
"longitude": {},
|
||||
"lowercase": {},
|
||||
"luhn_checksum": {},
|
||||
"mac": {},
|
||||
"md4": {},
|
||||
"md5": {},
|
||||
"mongodb": {},
|
||||
"mongodb_connection_string": {},
|
||||
"multibyte": {},
|
||||
"number": {},
|
||||
"numeric": {},
|
||||
"port": {},
|
||||
"postcode_iso3166_alpha2": {},
|
||||
"postcode_iso3166_alpha2_field": {},
|
||||
"printascii": {},
|
||||
"required": {},
|
||||
"rgb": {},
|
||||
"rgba": {},
|
||||
"ripemd128": {},
|
||||
"ripemd160": {},
|
||||
"semver": {},
|
||||
"sha256": {},
|
||||
"sha384": {},
|
||||
"sha512": {},
|
||||
"ssn": {},
|
||||
"tcp_addr": {},
|
||||
"tcp4_addr": {},
|
||||
"tcp6_addr": {},
|
||||
"tiger128": {},
|
||||
"tiger160": {},
|
||||
"tiger192": {},
|
||||
"timezone": {},
|
||||
"udp_addr": {},
|
||||
"udp4_addr": {},
|
||||
"udp6_addr": {},
|
||||
"ulid": {},
|
||||
"unix_addr": {},
|
||||
"uppercase": {},
|
||||
"uri": {},
|
||||
"url": {},
|
||||
"url_encoded": {},
|
||||
"urn_rfc2141": {},
|
||||
"uuid": {},
|
||||
"uuid_rfc4122": {},
|
||||
"uuid3": {},
|
||||
"uuid3_rfc4122": {},
|
||||
"uuid4": {},
|
||||
"uuid4_rfc4122": {},
|
||||
"uuid5": {},
|
||||
"uuid5_rfc4122": {},
|
||||
}
|
||||
|
||||
// These are options that are used in expressions of the form
|
||||
// <option> = <RHS>
|
||||
var validateLHS = map[string]struct{}{
|
||||
"contains": {},
|
||||
"containsany": {},
|
||||
@@ -741,26 +767,40 @@ var validateLHS = map[string]struct{}{
|
||||
"endsnotwith": {},
|
||||
"endswith": {},
|
||||
"eq": {},
|
||||
"eqfield": {},
|
||||
"eq_ignore_case": {},
|
||||
"eqcsfield": {},
|
||||
"eqfield": {},
|
||||
"excluded_if": {},
|
||||
"excluded_unless": {},
|
||||
"excluded_with": {},
|
||||
"excluded_with_all": {},
|
||||
"excluded_without": {},
|
||||
"excluded_without_all": {},
|
||||
"excludes": {},
|
||||
"excludesall": {},
|
||||
"excludesfield": {},
|
||||
"excludesrune": {},
|
||||
"fieldcontains": {},
|
||||
"fieldexcludes": {},
|
||||
"gt": {},
|
||||
"gtcsfield": {},
|
||||
"gte": {},
|
||||
"gtecsfield": {},
|
||||
"gtefield": {},
|
||||
"gtfield": {},
|
||||
"len": {},
|
||||
"lt": {},
|
||||
"lte": {},
|
||||
"ltcsfield": {},
|
||||
"lte": {},
|
||||
"ltecsfield": {},
|
||||
"ltefield": {},
|
||||
"ltfield": {},
|
||||
"max": {},
|
||||
"min": {},
|
||||
"ne": {},
|
||||
"ne_ignore_case": {},
|
||||
"necsfield": {},
|
||||
"nefield": {},
|
||||
"oneof": {},
|
||||
"oneofci": {},
|
||||
"required_if": {},
|
||||
@@ -769,8 +809,10 @@ var validateLHS = map[string]struct{}{
|
||||
"required_with_all": {},
|
||||
"required_without": {},
|
||||
"required_without_all": {},
|
||||
"skip_unless": {},
|
||||
"spicedb": {},
|
||||
"startsnotwith": {},
|
||||
"startswith": {},
|
||||
"unique": {},
|
||||
"validateFn": {},
|
||||
}
|
||||
|
||||
1
testdata/struct_tag.go
vendored
1
testdata/struct_tag.go
vendored
@@ -159,6 +159,7 @@ type ValidateUser struct {
|
||||
BadComplex string `validate:"gt=0,keys,eq=1|eq=2,endkeys,required"` // MATCH /option "keys" must follow a "dive" option in validate tag/
|
||||
BadComplex2 string `validate:"gt=0,dive,eq=1|eq=2,endkeys,required"` // MATCH /option "endkeys" without a previous "keys" option in validate tag/
|
||||
BadComplex3 string `validate:"gt=0,dive,keys,eq=1|eq=2,endkeys,endkeys,required"` // MATCH /option "endkeys" without a previous "keys" option in validate tag/
|
||||
Issue1367 string `validate:"required_without=ExternalValue,excluded_with=ExternalValue"`
|
||||
}
|
||||
|
||||
type TomlUser struct {
|
||||
|
||||
Reference in New Issue
Block a user