-
Notifications
You must be signed in to change notification settings - Fork 1
feat(generate): make --use-templates-var variadic #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4a1a469 to
64c1520
Compare
a623026 to
5353c83
Compare
5353c83 to
9c76e37
Compare
Code Review: feat(generate): make --use-templates-var variadicSummaryThis PR successfully implements support for multiple template variables via the ✅ Strengths
🔍 Issues & Concerns1. Breaking API Change (internal/muxt/definition.go:109)-func (def Definition) Pattern() string { return def.pattern }
+func (def Definition) RawPattern() string { return def.pattern }
+func (def Definition) Pattern() string { /* normalized version */ }The
Recommendation: Document this breaking change or ensure all callers are updated to use 2. Potential Inefficiency in Pattern Normalization (internal/muxt/definition.go:112-126)The Recommendation: Consider caching the normalized pattern: type Definition struct {
pattern string // raw pattern
normalizedPattern string // cached normalized pattern
// ... other fields
}Pre-compute during 3. Empty Host Handling (internal/muxt/definition.go:120-122)if h := def.Host(); h != "" {
sb.WriteString(h)
}
sb.WriteString(def.Path())When a host is present, there's no separator between host and path. For pattern Question: Should there be explicit validation that paths start with 4. Inconsistent Error Messages (internal/cli/commands.go:704, 720)return fmt.Errorf("deprecated flag %s not permitted along with %s", ...)
return fmt.Errorf("duplicate template variable: %s", tv)vs. return fmt.Errorf("variable %s%s", tv, errIdentSuffix) // line 815Recommendation: Standardize error message format for consistency. 5. Missing Validation (internal/cli/commands.go:713)
Recommendation: Add validation: for _, tv := range in {
if tv == "" {
return fmt.Errorf("template variable cannot be empty")
}
if _, ok := seen[tv]; ok {
return fmt.Errorf("duplicate template variable: %s", tv)
}
seen[tv] = struct{}{}
}6. Code Duplication in Analysis FunctionsThe changes to Recommendation: Consider extracting a higher-order function to reduce duplication: func forEachTemplateVariable(
config Config,
wd string,
pkg *packages.Package,
fn func(tv string, ts *template.Template, ...) error,
) error {
for _, tv := range config.TemplatesVariables {
ts, fm, err := asteval.Templates(wd, tv, pkg)
if err != nil {
return err
}
if err := fn(tv, ts, fm); err != nil {
return err
}
}
return nil
}7. Regex Pattern Cleanup (internal/muxt/definition.go:235)-templateNameMux = regexp.MustCompile(`^(?P<pattern>(((?P<METHOD>[A-Z]+)\s+)?)...)`)
+templateNameMux = regexp.MustCompile(`^(?P<pattern>((?P<METHOD>[A-Z]+)\s+)?...)`)The removal of the extra grouping Question: Was this intentional? Does it affect capture groups? 8. Comment Typo (docs/links_test.go:354)-// Pattern matches markdown links: [text](path)
+// RawPattern matches markdown links: [text](path)This seems like an unintentional rename. The variable is still Recommendation: Revert this change or update the variable name to 🔒 Security ConsiderationsNo significant security concerns identified. The changes:
🎯 Performance Considerations
patterns := make(map[string]Definition, len(templates))
📝 Documentation & TestingStrengths:
Suggestions:
🎓 Best Practices AlignmentThe PR follows the project's TDD workflow well:
However, per CLAUDE.md, consider whether the regex change deserves its own test case. ✅ Recommendations SummaryHigh Priority:
Medium Priority: Low Priority: 🎉 ConclusionThis is a solid implementation that maintains backward compatibility while adding useful functionality. The test coverage is exemplary. With the minor issues addressed, this PR will be production-ready. Overall Assessment: ✅ Approve with minor revisions suggested Review conducted following CLAUDE.md guidelines with focus on TDD workflow, deterministic generation, and type safety. |
resolves: #67