PowerShell / PowerShell/PSScriptAnalyzer
Suppression with `SuppressMessageAttribute` is completely broken for variables
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ả
Steps to reproduce
Consider this code:
$foo = "never used" # Should generate PSUseDeclaredVarsMoreThanAssignments
$global:var1 = $null # Should generate PSAvoidGlobalVars
Now let's try to add these suppressions:
[Diagnostics.CodeAnalysis.SuppressMessage('NonexistentRule', '')]
$foo = "never used" # Should still generate PSUseDeclaredVarsMoreThanAssignments
[Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidGlobalVars', '')]
$global:var1 = $null # Should NOT generate PSAvoidGlobalVars
Expected behavior
I should still see the PSUseDeclaredVarsMoreThanAssignments warning, but not the PSAvoidGlobalVars one.
Actual behavior
The opposite happens, the first message is suppressed, but the second is not:
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidGlobalVars Warning Test.ps1 5 Found global variable 'global:var1'.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.5
PSEdition Core
GitCommitId 7.4.5
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0
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 bằng cách chạy bản tái hiện PowerShell với PSScriptAnalyzer 1.23.0 và theo dõi cách SuppressMessageAttribute được xử lý đối với các biến. So sánh việc khớp tên quy tắc đối với NonexistentRule và PSAvoidGlobalVars; được xem là hoàn tất khi quy tắc không tồn tại không suppress PSUseDeclaredVarsMoreThanAssignments, trong khi quy tắc hợp lệ suppress PSAvoidGlobalVars.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100