PowerShell / PowerShell/PSScriptAnalyzer
PSUseDeclaredVarsMoreThanAssignments is not aware of the scriptblock context (invocation or dot-sourcing)
Đang mở
Chưa có ai nhận issue này.
Area - PSUseDeclaredVarsMoreThanAssignments
Area - Rules
- 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ả
Steps to reproduce
Extracted from here but similar issues also reported in #711
It’s a PSSA bug. I get the same warning with:
$totalSize = 0
. { $totalSize += 1 }
$totalSize
PSSA is apparently analyzing each script block independently.
It needs to recognize when a script block is dot sourced and analyze it in the context of where it is >invoked. This isn’t always possible, but it’s usually easy to do when using ForEach-Object (which dot >sources like this).
In trying some variants on the idea, it seems like there are multiple bugs:
$totalSize = 0
function foo {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
& {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
. {
$x = $totalSize + 1
$totalSize = $x # Should not warn, doesn't (no bug)
}
. {
$totalSize += 1 # Should not warn, does (bug)
}
$totalSize
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
Bắt đầu từ phần triển khai PSUseDeclaredVarsMoreThanAssignments và tái hiện các ví dụ về invocation, dot-sourcing, function và scriptblock trong issue. So sánh từng chẩn đoán với hành vi mong đợi được mô tả trong các comment; được xem là hoàn thành khi analyzer xử lý các ngữ cảnh này mà không có false positive hoặc cảnh báo bị bỏ sót.
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
- 35/100