Skip to content

fix(cli): clean up orphan whitespace and over-indent in generated models - #2335

Merged
bpamiri merged 1 commit into
developfrom
claude/fix-2329-model-template
Apr 27, 2026
Merged

bpamiri merged 1 commit into
developfrom
claude/fix-2329-model-template

Conversation

@bpamiri

@bpamiri bpamiri commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

`wheels generate model Foo bar:string` produced template-fill leftovers:

```cfm
component extends="Model" {

function config() {
	
	
	
	
			validatesPresenceOf("bar");
}

}
```

— 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:

  1. 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.

  2. 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" {

function config() {

	validatesPresenceOf("bar");
}

}
```

For multi-property models with email validation:

```cfm
component extends="Model" {

function config() {

	validatesPresenceOf("name,email");
	validatesFormatOf(property="email", type="email");
}

}
```

Both validation lines correctly aligned at 2-tab indent.

Test plan

Closes #2329

`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.
@bpamiri
bpamiri merged commit ca5b3da into develop Apr 27, 2026
3 checks passed
@bpamiri
bpamiri deleted the claude/fix-2329-model-template branch April 27, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): wheels generate model writes misformatted CFC with orphan blank lines

1 participant