PowerShell / PowerShell/PSScriptAnalyzer
`Invoke-Formatter -Range` silently drops corrections after earlier fixes shift text
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
Steps to reproduce
Format only the second line, with the range covering the complete statement:
Invoke-Formatter -ScriptDefinition "if(`$a){'x'}`nif(`$b){'y'}" -Range @(2, 1, 2, 12)
Expected behavior
Every formatting correction within the selected statement should be applied:
if($a){'x'}
if ($b) { 'y' }
Actual behavior
The space before the final } is missing:
if($a){'x'}
if ($b) { 'y'}
The formatter applies fixes iteratively. Earlier corrections make the selected line longer, but later violations are still filtered against the original fixed range coordinates. Once a correction shifts beyond the original range end, it is silently dropped even though it belongs to the statement selected by the caller.
Expected resolution
Track the range through applied edits, or filter corrections once against their original extents, so that a range covering a complete statement formats that statement completely.
Environment data
Reproduced with:
- PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
- PSScriptAnalyzer built from
mainat PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Invoke-Formatter -Range 入口点开始,并在所述的 PSScriptAnalyzer 版本上重现所提供的命令。跟踪迭代格式修正如何根据所选范围进行过滤,然后验证完整语句中的每个修正都已应用,包括 } 前的最后一个空格。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100