PowerShell / PowerShell/PSScriptAnalyzer

Whitespace removed when "Code Formatting: Whitespace Around Operator" Enabled

Đang mở
#1,778 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Issue-Bug
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

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
  1. Enable the "Code Formatting: Whitespace Around Operator" preference
  2. Write code with multiple spaces between variable name and operator
  3. 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi định dạng với tùy chọn "Whitespace Around Operator" và các khai báo biến được nêu trong issue. Kiểm tra phần triển khai formatter và các bài kiểm thử liên quan; report không nêu đường dẫn tệp hoặc đường dẫn kiểm thử nào. Được xem là hoàn tất khi hành vi add-whitespace được ghi thành tài liệu nhất quán với cách xử lý khoảng trắng thừa hiện có và có coverage cho input được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, powershell
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.