PowerShell / PowerShell/PSScriptAnalyzer
Whitespace removed when "Code Formatting: Whitespace Around Operator" Enabled
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 415
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
Prerequisites
- I have written a descriptive issue title.
- I have searched all issues to ensure it has not already been reported.
- I have read the troubleshooting guide.
- I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
Summary
When enabling the "Whitespace Around Operator" formatting option, which description reads "Adds spaces before and after an operator...", the setting will also remove redundant whitespace around operators, despite the description not detailing that.
This means that if a user deliberately adds additional whitespace in order to line up declarations, that deliberate extra whitespace is removed and their declarations no longer cleanly line up.
From my perspective, the removal of the additional whitespace should be moved to it's own separate preference, which is how it already operates for "Add Whitespace Around Pipe" and "Trim Whitespace Around Pipe". For these settings related to pipes, the Add setting only adds, and the Trim setting only removes. Or at the very least, the dual nature of "Whitespace Around Operator" should be detailed in it's description.
While not directly related to the bug itself, I could also very easily see an argument being made to have an option similar to "Align Property Value Pairs" when multiple variable declarations are made on consecutive lines, like in the instance of my example below. At least for my personal preference a setting like that could also be an reasonable solution to this problem.
PowerShell Version
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visual Studio Code Version
1.64.2
f80445acd5a3dadef24aa209168452a3d97cc326
x64
Extension Version
ms-vscode.powershell@2021.12.0
Steps to Reproduce
- Enable the "Code Formatting: Whitespace Around Operator" preference
- Write code with multiple spaces between variable name and operator
- Apply formatting
Visuals
Input
$foo = 'bar'
$testing = 'stuff'
$month='March'
Expected behavior (based on description text that only mentions adding whitespace)
$foo = 'bar'
$testing = 'stuff'
$month = 'March'
Actual behavior
$foo = 'bar'
$testing = 'stuff'
$month = 'March'
Logs
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 "Whitespace Around Operator" 偏好设置和 issue 中显示的变量声明重现格式化行为。检查 formatter 的实现及其相关测试;报告中未指定任何文件路径或测试路径。当文档所述的 add-whitespace 行为与对现有额外空白的处理保持一致,并且针对所报告输入具有覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, powershell
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100