Repository navigation
fix(cli): clean up orphan whitespace and over-indent in generated models - #2335
Merged
Merged
Conversation
`wheels generate model Foo bar:string` produced template-fill leftovers:
4 consecutive blank-with-tabs lines inside config(), and validation lines
indented at 4 tabs instead of 2. Two coordinated fixes:
1. Strip the leading 2-tab prefix from `buildModelValidations` content
(CodeGen.cfc) and `generateRelationshipCode` (Templates.cfc). The
template's `\t\t{{validations}}` placeholder already provides the
first line's indent; subsequent lines join with `\n\t\t` so multi-line
content stays aligned.
2. Add a `collapseEmptyLines` post-processing pass to processTemplate.
Whitespace-only lines (left behind by empty placeholders like
`\t\t{{hasManyRelationships}}` when no hasMany exists) become
genuinely empty, then runs of 2+ consecutive blank lines collapse to
one. Doesn't affect intentional single-blank separators between
blocks.
Fixes #2329.
Tests added to CodeGenSpec covering: no orphan whitespace-only lines,
no 2+ consecutive blank lines, validations indented at 2 tabs not 4,
and multi-line validations stay aligned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`wheels generate model Foo bar:string` produced template-fill leftovers:
```cfm
component extends="Model" {
}
```
— four consecutive blank-with-tabs lines inside `config()` (orphan placeholders for `|TableName|`, `{{belongsToRelationships}}`, `{{hasManyRelationships}}`, `{{hasOneRelationships}}`), and `validatesPresenceOf` indented at 4 tabs instead of 2 (the generator added its own `\t\t` prefix on top of the template's `\t\t{{validations}}` indent).
Fix
Two coordinated changes:
Strip the leading 2-tab prefix from `buildModelValidations` (CodeGen.cfc) and `generateRelationshipCode` (Templates.cfc). The template's placeholder line already provides the first line's indent. Subsequent lines join with `\n\t\t` so multi-line content stays aligned at the correct depth.
Add a `collapseEmptyLines` post-processing pass to `processTemplate`. Whitespace-only lines (left behind by unused optional placeholders) become genuinely empty, then runs of 2+ consecutive blank lines collapse to one. Doesn't affect intentional single-blank separators between blocks.
Result
```cfm
component extends="Model" {
}
```
For multi-property models with email validation:
```cfm
component extends="Model" {
}
```
Both validation lines correctly aligned at 2-tab indent.
Test plan
Closes #2329