V009

ValidationStandard

check for validation.StringMatch() call with empty message argument

The V009 analyzer reports when the second argument for a validation.StringMatch() call is an empty string. It is preferred to provide a friendly validation message, rather than allowing the function to return the raw regular expression as the message, since not all practitioners may be familiar with regular expression syntax.

Examples

validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "")
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "must contain only alphanumeric characters, periods, or hyphens")

Ignoring reports

Singular reports can be ignored by adding a //lintignore:V009 Go code comment at the end of the offending line or on the line immediately preceding, e.g.

validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9.-]+$`), "") //lintignore:V009

This page is generated from passes/V009/README.md, which lives beside the analyzer.