Offer the reference hint only where it would render the same value, and name the guard set in the help
Tests / vet + fmt + tests (pull_request) Successful in 57s
Tests / vet + fmt + tests (push) Successful in 7s

This commit was merged in pull request #4.
This commit is contained in:
2026-09-03 21:12:04 +02:00
parent 8ed8d9bb51
commit 44601c90ab
3 changed files with 8 additions and 5 deletions
+5 -3
View File
@@ -140,7 +140,7 @@ func checkTokens(format string, fields map[string]node) error {
}
continue // its target is checked at New (see linkRefs)
}
if err := checkArm(name, fields); err != nil {
if err := checkArm(name, fields, len(names) == 1); err != nil {
return fmt.Errorf("token {%s}: %w", t.body, err)
}
}
@@ -151,7 +151,9 @@ func checkTokens(format string, fields map[string]node) error {
}
// checkArm validates one sibling name or path against a template's fields.
func checkArm(name string, fields map[string]node) error {
// wholeToken says the name is the token's entire body, so {/name} would render
// the same value and can be offered as the reference spelling.
func checkArm(name string, fields map[string]node, wholeToken bool) error {
a := splitArm(name, nil)
if err := checkSegments(a); err != nil {
return err
@@ -166,7 +168,7 @@ func checkArm(name string, fields map[string]node) error {
}
if len(fields) == 0 {
hint := ""
if hintableRef(name) {
if wholeToken && hintableRef(name) {
hint = fmt.Sprintf(" — write {/%s} to reference the data", name)
}
return fmt.Errorf("no field %q; a token names a sibling field, and this template has none%s", a.key, hint)