★ wanayoo — archive 1999 https://github.com/PowerShell/PowerShell/pull/8247Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra newlines from formatting which resulted in necessary double newlines #8247

Merged
merged 1 commit into from Nov 14, 2018

Conversation

Projects
None yet
4 participants
@SteveL-MSFT
Copy link
Member

commented Nov 13, 2018 •

PR Summary

When formatting, the Group start and end added unnecessary newlines which resulted in double newlines in many cases. Formatting changes are not considered breaking.

(get-module | out-string).replace("`n","\n`n")

Before:

\n
ModuleType Version    Name                                ExportedCommands\n
---------- -------    ----                                ----------------\n
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}\n
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}\n
Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}\n
\n
\n

After:

\n             
ModuleType Version    Name                                ExportedCommands\n
---------- -------    ----                                ----------------\n
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}\n
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}\n
Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}\n
\n

There are still a few cases where the final output has two newlines (but not three anymore!). This is a bit more complicated to fix and would need to track state that either a newline was the last thing output or the item is the last in a collection and doesn't need a separator.

Fix #7186

PR Checklist

[feature]
remove extra whitespace that is unnecessary and results in double newlines

@SteveL-MSFT SteveL-MSFT force-pushed the SteveL-MSFT:format-whitespace branch to 49f7c17 Nov 13, 2018

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Nov 13, 2018

What we get with:

dir | Format-Table -GroupBy Name
@SteveL-MSFT

This comment has been minimized.

Copy link
Member Author

commented Nov 13, 2018 •

(get-process pwsh | format-list | Out-String).Replace("`n","\n`n")

Before:

\n
\n
Id      : 1626\n
Handles : 0\n
CPU     : 5697.7865177\n
SI      : 422\n
Name    : pwsh\n
\n
Id      : 18927\n
Handles : 0\n
CPU     : 480.0566228\n
SI      : 18920\n
Name    : pwsh\n
\n
Id      : 18928\n
Handles : 0\n
CPU     : 771.2722798\n
SI      : 422\n
Name    : pwsh\n
\n
\n
\n

After:

\n
Id      : 1626\n
Handles : 0\n
CPU     : 5696.2817117\n
SI      : 422\n
Name    : pwsh\n
\n
Id      : 18927\n
Handles : 0\n
CPU     : 474.75417\n
SI      : 18920\n
Name    : pwsh\n
\n
Id      : 18928\n
Handles : 0\n
CPU     : 769.8305049\n
SI      : 422\n
Name    : pwsh\n
\n
\n

@SteveL-MSFT

This comment has been minimized.

Copy link
Member Author

commented Nov 13, 2018 •

(dir | select -first 3 |Format-Table -GroupBy Name | out-string).replace("`n","\n`n")

Before:

\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----           11/4/18  7:47 AM                assets\n
\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----          10/26/18 10:24 AM                demos\n
\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----          10/26/18 10:24 AM                docker\n
\n
\n

After:

\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----           11/4/18  7:47 AM                assets\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----          10/26/18 10:24 AM                demos\n
\n
    Directory: /Users/steve/repos/PowerShell\n
\n
Mode                LastWriteTime         Length Name\n
----                -------------         ------ ----\n
d-----          10/26/18 10:24 AM                docker\n
\n

@iSazonov

This comment has been minimized.

Copy link
Collaborator

commented Nov 13, 2018

Is it ok to have one '\n' before "Directory ..."?

@SteveL-MSFT

This comment has been minimized.

Copy link
Member Author

commented Nov 13, 2018

@iSazonov you are asking if it's ok to separate the groups with just a single newline vs two? Seems fine to me and just as readable visually. In the future, we should leverage vt100 as a way to provide visual indicators rather than rely on whitespace only.

@@ -401,7 +401,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
Import-Module -Name $moduleFile -Force
Test-ValidateSet 'Hello' | Should -BeExactly 'Hello'
} finally {
Remove-Module -Name $moduleFile -Force
Remove-Module -Name $moduleFile -Force -ErrorAction SilentlyContinue

This comment has been minimized.

Copy link
@anmenaga

anmenaga Nov 13, 2018

Contributor

This is not related to this formatting code change, right?

This comment has been minimized.

Copy link
@SteveL-MSFT

SteveL-MSFT Nov 13, 2018

Author Member

Correct. Was running the tests locally and this line was outputting unncessarily

@iSazonov iSazonov merged commit 43e0394 into PowerShell:master Nov 14, 2018

6 checks passed

CodeFactor No issues found.
Details
PowerShell-CI-linux #PR-8247-20181113.02 succeeded
Details
PowerShell-CI-macos #PR-8247-20181113.02 succeeded
Details
PowerShell-CI-windows #PR-8247-20181113.02 succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
license/cla All CLA requirements met.
Details

@SteveL-MSFT SteveL-MSFT deleted the SteveL-MSFT:format-whitespace branch Nov 14, 2018

@adityapatwardhan

This comment has been minimized.

Copy link
Member

commented Nov 15, 2018

@iSazonov Reminder to add CL-XXX labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.