♻️ Convert Enumeration generator to Stencil template#181
Conversation
| {%- endif %} | ||
| {%- else -%} | ||
| {{ enumBody }} | ||
| {%- endif %} |
There was a problem hiding this comment.
Embedded enum output gains spurious trailing newline
Medium Severity
When embedded is true, the old code returned modelDefinition(...) directly with no trailing newline. The new Stencil template's final {%- endif %} on line 19 uses %} (no trailing trim), so the file's trailing newline is always appended to the output. This means embedded enums now return enumBody\n instead of enumBody. In Model.modelDefinition, embedded definitions are .joined(separator: "\n\n") then .indentLines(1) — the extra \n produces an unwanted blank line before the enclosing struct's closing brace. The test spec has no inline enum definitions, so this isn't caught by golden file tests.
Additional Locations (1)
9bf4669 to
ce10ed2
Compare
ea90dad to
ba38e2b
Compare
[IOS-431](https://linear.app/lunar/issue/IOS-431) - Create Enumeration.stencil template for file wrapper (imports, extension, description) - Update Enumeration.toSwift() to use templateRenderer - Thread templateRenderer through ModelDefinition.toSwift() to Enumeration - Keep modelDefinition() for enum body generation (complex logic) Amp-Thread-ID: https://ampcode.com/threads/T-019ce770-c162-72fe-8004-8407716bb370 Co-authored-by: Amp <amp@ampcode.com>
ce10ed2 to
9684aff
Compare
ba38e2b to
33955f7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| {% endfor %} | ||
| {%- if serviceName %} | ||
|
|
||
| extension {{ serviceName }} { |
There was a problem hiding this comment.
Extra blank line between imports and extension declaration
Low Severity
When packagesToImport is non-empty, the template produces an extra blank line between the import statements and the extension declaration compared to the old inline code. The for loop emits a trailing newline after the last import, and the text after {%- if serviceName %} contributes two more newlines (end-of-line 5 plus the empty line 6), yielding two blank lines total instead of the original one. Golden file tests don't catch this because they always pass an empty packagesToImport.


Problem
Enumeration.toSwift() uses inline string interpolation for the file wrapper.
Solution
Extract file wrapper to Enumeration.stencil, keep complex body logic in Swift.
Testing
All 70 tests pass including golden file tests.
Stack
#169 → #179 → #180 → this PR → …
IOS-431
Note
Medium Risk
Moderate risk because enum code generation now depends on a new
Enumeration.stenciltemplate and a forcedtry!render call, which could change output formatting or crash if template/context mismatches.Overview
Moves
Enumeration.toSwift()from manual string concatenation to Stencil-based rendering, passingembedded,serviceName, imports, description, and the precomputed enum body into a newEnumeration.stenciltemplate.Updates
ModelDefinition.toSwift()to thread aTemplateRendererthrough the enumeration generation path so enums and other models share the same templating infrastructure.Written by Cursor Bugbot for commit 33955f7. This will update automatically on new commits. Configure here.