Skip to content

Update formatter to not write newlines if content is empty - #11193

Merged
Andrew (anmenaga) merged 8 commits into
PowerShell:masterfrom
SteveL-MSFT:empty-formatting
Dec 2, 2019
Merged

Andrew (anmenaga) merged 8 commits into
PowerShell:masterfrom
SteveL-MSFT:empty-formatting

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Nov 25, 2019 •

Copy link
Copy Markdown
Member

PR Summary

Currently, the formatter uses WriteLine() on the content expecting it to be not empty. If the custom format explicitly doesn't write anything, it ends up as a newline. Fix is to check that there is something to write, otherwise bail out early. With this change, an empty string still results in a newline, but $null skips writing the newline.

PR Context

Affects a custom formatter I'm writing that requires output to not have trailing newlines.

PR Checklist

@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title Update formatter to not write newlines if content is empty WIP: Update formatter to not write newlines if content is empty Nov 26, 2019
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

This turned out to be a bit more complex than I thought. An empty string represents a newline.

@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title WIP: Update formatter to not write newlines if content is empty Update formatter to not write newlines if content is empty Nov 26, 2019
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 27, 2019
@iSazonov Ilya (iSazonov) added this to the 7.1.0-preview.1 milestone Nov 27, 2019
@ghost

Copy link
Copy Markdown

🎉v7.1.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants