PowerShell / PowerShell/PSScriptAnalyzer

Invoke-Formatter is not idempotent on `--%` verbatim arguments

Ouverte
#2,209 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

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

Description

Steps to reproduce

Run the formatter repeatedly on a native command that uses the stop-parsing token:

$formatted = $null
1..3 | ForEach-Object {
    $formatted = Invoke-Formatter ($formatted ?? 'cmd --% raw | text & stuff')
    $formatted
}

Expected behavior

Formatting already formatted output should be a no-op. Spacing adjacent to the verbatim argument should either be left untouched or normalized once to a stable result.

Actual behavior

One additional space is inserted before | on every run:

cmd --% raw  | text & stuff
cmd --% raw   | text & stuff
cmd --% raw    | text & stuff

The output grows without bound in a format-on-save loop.

The verbatim-argument token owns the text up to the pipe. PSUseConsistentWhitespace with CheckPipe sees a zero-width gap before | and inserts a space inside the verbatim argument's extent on each formatting pass.

Environment data

Reproduced with:

  • PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
  • PSScriptAnalyzer 1.25.0 on PowerShell 7.6.3
  • PSScriptAnalyzer built from main at PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4

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

Commencez par reproduire l’exemple répété de Invoke-Formatter avec une commande native utilisant le token --% stop-parsing. Examinez la gestion de CheckPipe de PSUseConsistentWhitespace autour du verbatim-argument extent ; c’est terminé lorsque le formatage répété laisse l’espacement stable au lieu d’insérer un espace supplémentaire avant |.

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é
Active
Clarté
Plutôt claire
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

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