Suppression with `SuppressMessageAttribute` is completely broken for variables
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
- 45/100
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.
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
- Ngôn ngữ chính
- C#
- Star
- 2.2k
- Fork
- 415
- Merge trung bình
- 13 giờ 1 phút
- Pull request đã merge (30 ngày)
- 2
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/PSScriptAnalyzer
-
Up-for-Grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 bình luận ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
PowerShell/PSScriptAnalyzer#2210 ·
Tất cả issue của PowerShell/PSScriptAnalyzer
Issue tương tự
-
Status: Waiting triage Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
nanoframework/Home#1857 ·
-
kind/bug kind/regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
unoplatform/uno.toolkit.ui#1646 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nightscout/nocturne#1379 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
elastic/esql-dotnet#47 ·
-
port: add go-steam fork Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100