Normalize whitespace in rendered template output#195
Merged
dcarbone merged 1 commit intoJun 6, 2026
Conversation
Templates are PHP files rendered via output buffering, so indented inline control structures (e.g. " <?php endif; ?>") emit their leading indentation as whitespace-only or trailing-whitespace lines in the generated code, and rendered files do not consistently end in a newline. Normalize at the single render chokepoint in Templates so every generated file (core, version core, type classes, and tests) is free of trailing whitespace and ends in exactly one newline, without having to edit each template individually.
dcarbone
approved these changes
Jun 6, 2026
Owner
dcarbone
left a comment
There was a problem hiding this comment.
This looks good to me! I am all for sensible code quality improvements!
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.
What
Generated code currently carries per-line trailing whitespace, and rendered files don't consistently end in a newline. This normalizes both at the single render chokepoint in
Templates, so every generated file (core, version core, type classes, and tests) comes out free of trailing whitespace and ending in exactly one newline.Why
Templates are PHP files rendered via output buffering. Indented inline control structures — e.g.
<?php endif; ?>— emit their leading indentation as whitespace-only or trailing-whitespace lines in the output. Because every template returns throughTemplates::render*, a singlenormalize()step there cleans every generated file at once, with no need to touch the individual templates.How it was verified
phpunit -c phpunit/Builder.xml— all 70 tests pass.Is there appetite for more of this?
This is deliberately a small, self-contained first step. While digging in, I noticed a few other places where the generator could emit higher-quality code straight out of the box, and I'd be happy to send follow-up PRs if you're open to it:
useimports — some imports (Constants,FHIRVersion, container interfaces) are added speculatively per type-category even when a given type's body never references them, so they show up as unused.__CLASS__andget_class($x)in the templates could becomeself::class/$x::class.Totally understand if some or all of that is out of scope or not the direction you want — happy to take your lead. Mainly wanted to ask before investing further. Thanks for maintaining php-fhir!