PowerShell / PowerShell/PSScriptAnalyzer
Analyzer for Type Reassignment in `foreach` Loop
Chưa có ai nhận issue này.
- 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ả
Summary of the new feature
Consider the following script:
if ($true) {
[String]$MyVar = "Blah"
}
[int[]]$MyInts = @(1,2,3)
foreach ($MyVar in $MyInts) {
Write-Host "This is my type [$($MyVar.GetType())]"
}
A naïve C# reading of the above PowerShell would assume that the above would print out:
This is my type [int]
This is my type [int]
This is my type [int]
However this is PowerShell and due to Scoping Rules this actually returns:
This is my type [string]
This is my type [string]
This is my type [string]
Proposed technical implementation details (optional)
This has already burned me once in production.
As far as I can tell there is not an existing analyzer to determine this.
It is unclear if it is even feasible to do this reliably.
What is the latest version of PSScriptAnalyzer at the point of writing
PS > Get-Module | Where-Object {$_.Name -eq 'PSScriptAnalyzer' }
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 1.19.1 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke…
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.
Hướng nghiên cứu
Không có tệp nguồn, bài kiểm thử hay điểm bắt đầu nào được nêu. Hãy bắt đầu bằng cách xem xét các quy tắc analyzer hiện có và các quy tắc phạm vi PowerShell được liên kết, sau đó xác định xem việc gán lại kiểu trong các vòng lặp foreach có thể được phát hiện một cách đáng tin cậy hay không. Hoàn tất có nghĩa là có một chẩn đoán analyzer được lập tài liệu, kèm các bài kiểm thử bao quát hành vi của ví dụ.
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
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100