PowerShell / PowerShell/PSScriptAnalyzer

`Invoke-Formatter -Range` silently drops corrections after earlier fixes shift text

未關閉
#2,211 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
C#
星號
2.2k
分支
415
平均合併
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 main at PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Invoke-Formatter -Range 入口點開始,並在所述的 PSScriptAnalyzer 版本上重現提供的命令。追蹤反覆格式修正如何依據所選範圍進行篩選,然後驗證完整陳述式中的每個修正都已套用,包括 } 前的最後一個空格。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
powershell
領域
tooling
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
活躍
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。