mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
feature: add support for TOML struct tags in struct-tag rule (#1255)
This commit is contained in:
@@ -106,6 +106,7 @@ const (
|
||||
keyMapstructure = "mapstructure"
|
||||
keyProtobuf = "protobuf"
|
||||
keyRequired = "required"
|
||||
keyTOML = "toml"
|
||||
keyURL = "url"
|
||||
keyValidate = "validate"
|
||||
keyXML = "xml"
|
||||
@@ -212,6 +213,11 @@ func (w lintStructTagRule) checkTaggedField(f *ast.Field) {
|
||||
if tag.Name != "true" && tag.Name != "false" {
|
||||
w.addFailure(f.Tag, "required should be 'true' or 'false'")
|
||||
}
|
||||
case keyTOML:
|
||||
msg, ok := w.checkTOMLTag(tag.Options)
|
||||
if !ok {
|
||||
w.addFailure(f.Tag, msg)
|
||||
}
|
||||
case keyURL:
|
||||
msg, ok := w.checkURLTag(tag.Options)
|
||||
if !ok {
|
||||
@@ -435,6 +441,21 @@ func (w lintStructTagRule) checkValidateTag(options []string) (string, bool) {
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkTOMLTag(options []string) (string, bool) {
|
||||
for _, opt := range options {
|
||||
switch opt {
|
||||
case "omitempty":
|
||||
default:
|
||||
if w.isUserDefined(keyTOML, opt) {
|
||||
continue
|
||||
}
|
||||
return fmt.Sprintf("unknown option '%s' in TOML tag", opt), false
|
||||
}
|
||||
}
|
||||
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkValidateOptionsAlternatives(alternatives []string) (string, bool) {
|
||||
for _, alternative := range alternatives {
|
||||
alternative := strings.TrimSpace(alternative)
|
||||
|
||||
Reference in New Issue
Block a user