Address reviewer findings: reference hint, consumer-terms type errors, misuse exit code, immutability and parity docs
Tests / vet + fmt + tests (pull_request) Successful in 57s
Tests / vet + fmt + tests (pull_request) Successful in 57s
This commit is contained in:
@@ -32,6 +32,9 @@ func (f *Generator) Fake(path string) (string, error) {
|
||||
|
||||
// Template is an inline template compiled, referenced and validated against a
|
||||
// generator's loaded data once, ready to render many times with [Template.Fake].
|
||||
// It is safe for concurrent use: Fake serializes on its generator's lock, so a
|
||||
// seeded sequence is reproducible only when a generator — and its templates — are
|
||||
// drawn from one goroutine.
|
||||
type Template struct {
|
||||
g *Generator
|
||||
n node
|
||||
@@ -48,6 +51,10 @@ func (t *Template) Fake() string {
|
||||
// binds its references against the loaded tree, so repeated renders pay the
|
||||
// compile and validation once. It shares [New]'s guarantees: a bad template errors
|
||||
// here, and rendering cannot fail.
|
||||
// NewTemplate runs the same fences loadData does for a category, scoped to one
|
||||
// inline node with everything but checkNoCycles: a reference binds only into the
|
||||
// loaded tree, which has no path into this node, so rendering it cannot reach
|
||||
// itself. A new fence belongs in both places (loadData and here).
|
||||
func (f *Generator) NewTemplate(input string) (*Template, error) {
|
||||
n, err := compileInput(input)
|
||||
if err != nil {
|
||||
@@ -56,8 +63,6 @@ func (f *Generator) NewTemplate(input string) (*Template, error) {
|
||||
if err := linkNodeRefs(n, f.categories); err != nil {
|
||||
return nil, fmt.Errorf("fejkdata: %w", err)
|
||||
}
|
||||
// No cycle is possible: a reference binds only into the loaded tree, which has
|
||||
// no path into this node, so rendering it cannot reach itself.
|
||||
if err := checkNodeRepeatReach(n); err != nil {
|
||||
return nil, fmt.Errorf("fejkdata: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user