PowerShell / PowerShell/PSScriptAnalyzer
Invoke-Formatter is not idempotent on `--%` verbatim arguments
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
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
mainat PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用带有 --% stop-parsing token 的 native 命令重现重复的 Invoke-Formatter 示例。检查 PSUseConsistentWhitespace 在 verbatim-argument extent 附近对 CheckPipe 的处理;当重复格式化能够保持空格稳定,而不是在 | 前再插入一个空格时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100