Unused variable false positive in `ForEach-Object` begin block (`PSUseDeclaredVarsMoreThanAssignments`)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- powershell, typescript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện chẩn đoán với ví dụ ForEach-Object được cung cấp trong tiện ích mở rộng PowerShell và kiểm tra cách các kết quả của PSUseDeclaredVarsMoreThanAssignments được xử lý. So sánh cảnh báo với các khối begin, process và end được hiển thị trong báo cáo. Hoàn tất có nghĩa là false positive không còn được báo cáo, trong khi các cảnh báo thực sự về biến không được sử dụng vẫn tiếp tục xuất hiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- I have written a descriptive issue title.
- I have searched all open and closed 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.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
Variables initialized in begin block of ForEach-Object trigger PSUseDeclaredVarsMoreThanAssignments warning.
PowerShell Version
Name Value
---- -----
PSVersion 5.1.26100.7705
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.7705
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Name : ConsoleHost
Version : 5.1.26100.7705
InstanceId : 4ed60023-e437-45ae-b589-226f399acc62
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.109.5
072586267e68ece9a47aa43f8c108e0dcbf44622
x64
Extension Version
ms-vscode.powershell@2025.4.0
Steps to Reproduce
1, 2, 3 | ForEach-Object { $list = @() } { $list += $_ } { $list }
^^^^^
The variable 'list' is assigned but never used.
PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)
Returning the $list from the begin block offs the warning
1, 2, 3 | ForEach-Object { $list = @(); $list } { $list += $_ } { $list }
Visuals
No response
Logs
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 1.9k
- Fork
- 548
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PowerShell/vscode-powershell
-
[aw] Agentic Issue Triage failed Đang mởagentic-workflows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
PowerShell/vscode-powershell#5599 · 3 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/vscode-powershell#5592 · 2 bình luận · 1 reaction ·
-
[aw] Agentic Issue Triage failed Đang mởagentic-workflows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
PowerShell/vscode-powershell#5583 · 1 bình luận ·
-
powershell.scriptAnalysis.settingsPath (Description): Warning Message Should Provide A Workaround Đang mởArea-Code Formatting Issue-Enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
PowerShell/vscode-powershell#4653 · 3 bình luận · 4 reaction ·
-
nothing Đang mởIssue-Bug Needs: Triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 5/100
PowerShell/vscode-powershell#5603 · 1 reaction ·
Tất cả issue của PowerShell/vscode-powershell
Issue tương tự
-
Browser Waiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
getsentry/sentry-javascript#24577 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
agilepathway/label-checker#640 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
copse-dev/agent-pane#2953 ·
-
[aw] Upgrade available Đang mởagentic-workflows
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
githubnext/rig#534 ·
-
automation missing-model model-sync provider:pioneer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
anomalyco/models.dev#7701 ·