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

Cleanup: sort usings #9490

Merged
merged 12 commits into from
Apr 30, 2019
Merged

Conversation

iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Apr 27, 2019

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

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Apr 27, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.1 milestone Apr 27, 2019
@PoshChan
Copy link
Collaborator

@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
Collaborator Author

@PoshChan Please retry linux.

@PoshChan
Copy link
Collaborator

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

@iSazonov
Copy link
Collaborator Author

@PoshChan Please retry linux

@PoshChan
Copy link
Collaborator

@iSazonov, successfully started retry of PowerShell-CI-Linux

@iSazonov
Copy link
Collaborator Author

@TravisEz13 Could you please look why we lost CodeFactor in CI list?

@adityapatwardhan
Copy link
Member

adityapatwardhan commented Apr 29, 2019

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

@iSazonov
Copy link
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 iSazonov merged commit bd6fdae into PowerShell:master Apr 30, 2019
@iSazonov iSazonov deleted the cleanup-sort-usings-1 branch April 30, 2019 05:25
@iSazonov iSazonov self-assigned this Apr 30, 2019
@iSazonov
Copy link
Collaborator Author

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

None yet

4 participants