Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Removing trailing whitespace #2725

Closed
powercode wants to merge 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:trailing-whitespacepowercode/PowerShell:trailing-whitespaceCopy head branch name to clipboard
Closed

Removing trailing whitespace #2725
powercode wants to merge 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
powercode:trailing-whitespacepowercode/PowerShell:trailing-whitespaceCopy head branch name to clipboard

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

Copy link
Copy Markdown

Hi @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

vors commented Nov 20, 2016

Copy link
Copy Markdown
Collaborator

Can you, please, resolve the conflicts?

@powercode powercode force-pushed the trailing-whitespace branch 5 times, most recently from cb155ef to 5054a40 Compare November 22, 2016 01:33
@vors

vors commented Nov 23, 2016

Copy link
Copy Markdown
Collaborator

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

@powercode 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 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
        }
    }
}
```
@powercode powercode force-pushed the trailing-whitespace branch from 48627ce to eb9cb54 Compare December 7, 2016 01:17
@lzybkr

lzybkr commented Jan 6, 2017

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

lzybkr commented Jan 13, 2017

Copy link
Copy Markdown
Contributor

Closing this in favor of #3001.

@lzybkr lzybkr closed this Jan 13, 2017
@powercode powercode deleted the trailing-whitespace branch April 19, 2017 17:28
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.