PowerShell / PowerShell/PSScriptAnalyzer

Format doesn't work for comma `,` separated parameters

Ouverte
#1,684 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Area - Formatter Issue - Bug
Langage dominant
C#
Étoiles
2.2k
Forks
414
Merge moyen
13 h 1 min
PR mergées (30 j)
2

Description

System Details

System Details Output

### VSCode version: 1.51.1 e5a624b788d92b8d34d1392e4c4d9789406efe8f x64

### VSCode extensions:
janisdd.vscode-edit-csv@0.6.0
ms-python.python@2021.2.633441544
ms-toolsai.jupyter@2021.2.576440691
ms-vscode.cpptools@1.1.3
ms-vscode.hexeditor@1.3.0
ms-vscode.powershell@2020.6.0
redhat.vscode-commons@0.0.6
redhat.vscode-xml@0.16.1


### PSES version: 2.2.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue Description

Create a PowerShell file, input following script, and hit Alt+Shift+F. The file is not formatted.

    $a = [pscustomobject]@{
        a=1
      b=2
    }
            $a|Select-Object  a,b

Related settings in settings.json:

    "powershell.codeFormatting.trimWhitespaceAroundPipe": true,
    "powershell.codeFormatting.useCorrectCasing": true,
    "powershell.codeFormatting.whitespaceBetweenParameters": true,
Expected Behaviour

The format result should look similar to:

$a = [pscustomobject]@{
    a = 1
    b = 2
}
$a | Select-Object -Property a, b
Actual Behaviour

The file is unchanged.

Here are some other input/output combinations if I change the script a little bit and hit Alt+Shift+F again:

  • Case 1 -- looks well except that the space is removed in a, b.
    • Input:
        $a = [pscustomobject]@{
            a=1
          b=2
        }
                $a|Select-Object  a, b
    
    • Output:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a,b
    
  • Case 2 -- the necessary comma , is removed in a ,b, which makes the code invalid.
    • Input:
        $a = [pscustomobject]@{
            a=1
          b=2
        }
                $a|Select-Object  a ,b
    
    • Output:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a b
    
  • Case 3 -- the space is removed in a, b.
    • Input:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a, b
    
    • Output:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a,b
    
  • Case 4 -- this is the reverse of Case 3. If I keep hitting Alt+Shift+F, the file will cycle through Case 3 and 4.
    • Input:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a,b
    
    • Output:
    $a = [pscustomobject]@{
        a = 1
        b = 2
    }
    $a | Select-Object a, b
    

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez le problème dans un fichier PowerShell avec Alt+Shift+F, des paramètres séparés par des virgules et les paramètres de formatage du code indiqués. Comparez la sortie du formateur avec les exemples attendus, notamment en vérifiant que les virgules et les espaces dans a, b sont conservés ; le travail est terminé lorsque le formatage est stable et que le code reste valide.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
powershell
Domaine
tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.