The V001 analyzer reports when custom SchemaValidateFunc declarations can be replaced with validation.StringMatch() or validation.StringDoesNotMatch().
func validateExampleThing(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^s-([0-9a-f]{17})$`).MatchString(value) {
errors = append(errors, fmt.Errorf("%q must begin with s- and contain 17 lowercase alphanumeric characters: %q", k, value))
}
return
}
// directly in Schema
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters"),
// or saving as a variable
var validateExampleThing = validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters")
// or replacing the function
func validateExampleThing() schema.SchemaValidateFunc {
return validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters")
}
Singular reports can be ignored by adding the a //lintignore:V001
Go code comment at the end of the offending line or on the line immediately proceding, e.g.
//lintignore:V001
func validateExampleThing(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^s-([0-9a-f]{17})$`).MatchString(value) {
errors = append(errors, fmt.Errorf("%q must begin with s- and contain 17 lowercase alphanumeric characters: %q", k, value))
}
return
}