Skip to content

Cleanup: sort usings - #9490

Merged
Ilya (iSazonov) merged 12 commits into
PowerShell:masterfrom
iSazonov:cleanup-sort-usings-1
Apr 30, 2019
Merged

Ilya (iSazonov) merged 12 commits into
PowerShell:masterfrom
iSazonov:cleanup-sort-usings-1

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Apr 27, 2019 •

Copy link
Copy Markdown
Collaborator

PR Summary

Sort using-s with the script. Please review commit by commit.

function UsingSort {
    param($file, $out_file)

    $all = Get-Content -Path $file -Encoding Utf8NoBom

    Set-Content -Path $out_file -Value $all[0..2] -Encoding Utf8NoBom

    $i = 3 # Skip license header
    $usingSystem = @()
    $usingAlias = @()
    $using = @()

    # Process usings
    while ($all[$i] -like "using *") {
        if ($all[$i] -like "using System*") {
            $usingSystem += $all[$i]
        } elseif ($all[$i] -like "using *=*") {
            $usingAlias += $all[$i]
        } else {
            $using += $all[$i]
        }

        if ($i++ -ge $all.Length) {
            break
        }
    }

    # Sort and output
    if ($usingSystem) {
        # Length-2 - remove last dot or semi to move `using System;` on top.
        $usingSystem | Sort-Object -Property @{e={$_[0..($_.Length-2)]}} | Add-Content -Path $out_file -Encoding Utf8NoBom
    }

    if ($using) {
        Add-Content -Path $out_file -Value "" -Encoding Utf8NoBom
        $using | Sort-Object -Property @{e={$_[0..($_.Length-2)]}} | Add-Content -Path $out_file -Encoding Utf8NoBom
    }

    if ($usingAlias) {
        Add-Content -Path $out_file -Value "" -Encoding Utf8NoBom
        $usingAlias | Sort-Object -Property @{e={$_[0..($_.Length-2)]}} | Add-Content -Path $out_file -Encoding Utf8NoBom
    }

    Add-Content -Path $out_file -Value $all[$i..($all.length-1)] -Encoding Utf8NoBom

}
$list = Get-ChildItem -Recurse src\*.cs
$list | ForEach-Object { Write-Host -NoNewline ">$_ :"; UsingSort $_ $_; "<" }

PR Context

PR Checklist

@PoshChan

Copy link
Copy Markdown
Collaborator

Ilya (@iSazonov), your last commit had 1 failures in PowerShell-CI-linux
Validate 'Save-Help -DestinationPath for all PowerShell Core modules..Validate Save-Help for the 'Microsoft.PowerShell.Management' module

Expected 'Microsoft.PowerShell.Management_eefcb906-b326-4e99-9f54-8b4bb6ef3c6d_en-US_helpcontent.zip', because Save-Help for  should download 'Microsoft.PowerShell.Management_eefcb906-b326-4e99-9f54-8b4bb6ef3c6d_en-US_helpcontent.zip', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1: line 333
333:     $compressedFile | Should -Be $expectedCompressedFile -Because "Save-Help for $module should download '$expectedCompressedFile'"

@iSazonov

Copy link
Copy Markdown
Collaborator Author

PoshChan-Bot (@PoshChan) Please retry linux.

@PoshChan

Copy link
Copy Markdown
Collaborator

Ilya (@iSazonov), I do not understand the build target(s) linux.; I only allow static, windows, macos, linux, all

@iSazonov

Copy link
Copy Markdown
Collaborator Author

PoshChan-Bot (@PoshChan) Please retry linux

@PoshChan

Copy link
Copy Markdown
Collaborator

Ilya (@iSazonov), successfully started retry of PowerShell-CI-Linux

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Travis Plunk (@TravisEz13) Could you please look why we lost CodeFactor in CI list?

@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Apr 29, 2019 •

Copy link
Copy Markdown
Member

I was wondering if we can do something about unused using statements. Not sure if there are any.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

I was wondering if we can do something about unused using statements. Not sure if there are any.

Waiting dotnet/vscode-csharp#2873

@iSazonov
Ilya (iSazonov) merged commit bd6fdae into PowerShell:master Apr 30, 2019
@iSazonov
Ilya (iSazonov) deleted the cleanup-sort-usings-1 branch April 30, 2019 05:25
@iSazonov Ilya (iSazonov) self-assigned this Apr 30, 2019
@iSazonov

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) Could you please clarify why we lost CodeFactor in CI list?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants