PowerShell / PowerShell/PSScriptAnalyzer

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

Aberta
#2,209 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
C#
Estrelas
2.2k
Forks
415
Merge médio
13h 1min
PRs com merge (30d)
2

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece reproduzindo o exemplo repetido de Invoke-Formatter com um comando nativo usando o token --% stop-parsing. Inspecione o tratamento de CheckPipe de PSUseConsistentWhitespace em torno do verbatim-argument extent; estará concluído quando a formatação repetida mantiver o espaçamento estável em vez de inserir outro espaço antes de |.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
powershell
Domínio
tooling
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
55/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.