fix incorrect and vague doc comments

Audit ahead of the README/doc.go work (issue #3):

- number.go: Min, MinFloat32, MinFloat64 all said "less than or equal to a
  given maximum" -- copy-pasted from the Max family. They check the
  minimum. Fixed.
- chars_test.go: ExampleExceptChars called Chars, not ExceptChars, so it
  never exercised the function it documents.
- chars.go: "does not contain disallowed characters" was circular.
- in.go: NotIn's parameter was named "allow"; renamed to "disallow".
- length.go: note that length is bytes (len), not runes -- the "%d
  characters" messages imply otherwise.
- url.go: spell out that ParseRequestURI wants an absolute URL or path.
- uuid.go: note lowercase-hex only, version/variant not checked.
- error.go: explain Err (the match-anything sentinel), how Error() formats
  with Data, and what With does. all.go: point at Collect.

Comments only; no behaviour change. go vet + go test ./... pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-07 13:59:59 +01:00
co-authored by Claude Sonnet 5
parent 7ea26f9c88
commit da971f4df5
9 changed files with 38 additions and 28 deletions
+10 -6
View File
@@ -2,10 +2,9 @@ package validate
import "fmt"
// Validation error.
var (
Err = Error{}
)
// Err is the zero Error. It carries no message, so errors.Is(x, Err) is
// true for any error produced by this package.
var Err = Error{}
// Error represents a validation error.
type Error struct {
@@ -13,8 +12,9 @@ type Error struct {
Data []any
}
// Error retrieves the message of a validation Error.
// If it has Data, the message will be formatted.
// Error returns the error message. If Data is non-empty, Message is used
// as an fmt.Sprintf format string and Data as its arguments (this is how
// the sentinels with %d/%q verbs are filled in, e.g. via With).
func (e Error) Error() string {
if len(e.Data) > 0 {
return fmt.Sprintf(e.Message, e.Data...)
@@ -34,6 +34,10 @@ func (e Error) Is(target error) bool {
return false
}
// With returns a copy of the Error with value appended to Data, so it
// lands in the message when Message contains a formatting verb:
//
// ErrMustBeLonger.With(4) // "must contain at least 4 characters"
func (e Error) With(value any) Error {
if e.Data == nil {
e.Data = []any{}