Skip to content

Removing trailing whitespace - #2725

Closed
Staffan Gustafsson (powercode) wants to merge 1 commit into
PowerShell:masterfrom
powercode:trailing-whitespace
Closed

Removing trailing whitespace #2725
Staffan Gustafsson (powercode) wants to merge 1 commit into
PowerShell:masterfrom
powercode:trailing-whitespace

Conversation

@powercode

Copy link
Copy Markdown
Collaborator

Trailing whitespace removed from cs,json,xml,xaml,ps1,psm1,ps1xml, psd1 files.

The followning command was used:

using namespace System.Text.RegularExpressions

function Remove-TrailingWhitespace {
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [Alias('PSPath')]
        [string] $LiteralPath
    )
    begin {
        $trailingWhiteSpace  = [Regex]::new('(?m)[ \t]+\r?$', [RegexOptions]::Compiled)
    }

    process {
        try {
            $LiteralPath = (Resolve-Path $LiteralPath).ProviderPath
            if (Test-path -PathType Leaf $LiteralPath) {
                $content = Get-Content -Raw -LiteralPath $LiteralPath
                if ($null -ne $content) {
                    $trimmedContent = $trailingWhiteSpace.Replace($content, "`r")
                    if ($trimmedContent -ne $content) {
                        # Set-Content fails for some reason with 'Set-Content : Stream was not readable.'
                        [io.file]::WriteAllText($LiteralPath, $trimmedContent, [Text.Encoding]::ASCII)
                        Get-Item $LiteralPath
                    }
                }
            }
        }
        catch {
            Write-Error -Message $_.Exception.Message -TargetObject $LiteralPath
        }
    }
}

@msftclas

Hi Staffan Gustafsson (@powercode), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

@vors

Copy link
Copy Markdown
Collaborator

Can you, please, resolve the conflicts?

@vors

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) sorry there are conflicts again :(
I know it's pretty annoying.

@powercode
Staffan Gustafsson (powercode) force-pushed the trailing-whitespace branch 2 times, most recently from 6e7233d to a931612 Compare November 23, 2016 23:58
@powercode

Copy link
Copy Markdown
Collaborator Author

Just pushed a resolved version

@powercode

Copy link
Copy Markdown
Collaborator Author
Unhandled Exception: System.IO.IOException: Broken pipe
   at System.IO.UnixFileStream.CheckFileCall(Int64 result, Boolean ignoreNotSupported)
   at System.IO.UnixFileStream.WriteNative(Byte[] array, Int32 offset, Int32 count)
   at System.IO.UnixFileStream.FlushWriteBuffer()
   at System.IO.UnixFileStream.Dispose(Boolean disposing)
   at System.IO.UnixFileStream.Finalize()
Test result file 'pester-tests.xml' not found for test/powershell.
At /home/travis/build/PowerShell/PowerShell/build.psm1:814 char:9
+         throw "Test result file '$testResultsFile' not found for $Tes ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Test result fil...est/powersh 
   ell.:String) [], RuntimeException
    + FullyQualifiedErrorId : Test result file 'pester-tests.xml' not found fo 
   r test/powershell.

Don't think I'm responsible for that.

@PowerShellTeam PowerShellTeam added the Review - Needed The PR is being reviewed label Nov 24, 2016
@powercode
Staffan Gustafsson (powercode) force-pushed the trailing-whitespace branch 3 times, most recently from 36fdb8c to 48627ce Compare December 7, 2016 01:12
…sd1 files

The followning command was used:
```
using namespace System.Text.RegularExpressions

function Remove-TrailingWhitespace {
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [Alias('PSPath')]
        [string] $LiteralPath
    )
    begin {
        $trailingWhiteSpace  = [Regex]::new('(?m)[ \t]+\r?$', [RegexOptions]::Compiled)
    }

    process {
        try {
            $LiteralPath = (Resolve-Path $LiteralPath).ProviderPath
            if (Test-path -PathType Leaf $LiteralPath) {
                $content = Get-Content -Raw -LiteralPath $LiteralPath
                if ($null -ne $content) {
                    $trimmedContent = $trailingWhiteSpace.Replace($content, "`r")
                    if ($trimmedContent -ne $content) {
                        # Set-Content fails for some reason with 'Set-Content : Stream was not readable.'
                        [io.file]::WriteAllText($LiteralPath, $trimmedContent, [Text.Encoding]::ASCII)
                        Get-Item $LiteralPath
                    }
                }
            }
        }
        catch {
            Write-Error -Message $_.Exception.Message -TargetObject $LiteralPath
        }
    }
}
```
@lzybkr

Copy link
Copy Markdown
Contributor

There are way too many changes to review and I'm concerned about the potential for problems due to changing the file encoding.

For example, if we test data that used a specific encoding, we would lose the coverage due to a PR like this.

@lzybkr

Copy link
Copy Markdown
Contributor

Closing this in favor of #3001.

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.

6 participants