False Positive: Variable Reference Error for Colon After Variable in Double-Quoted Strings (Format Operator and Concatenation)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện chẩn đoán với các ví dụ về toán tử định dạng và phép nối chuỗi trong issue, sử dụng PSScriptAnalyzer 2.10.0 và môi trường PowerShell được báo cáo. Theo dõi điểm vào của analyzer báo lỗi tham chiếu biến; hoàn thành khi cả hai dạng hợp lệ đều không tạo ra chẩn đoán nào, bao gồm cả các trường hợp có dấu hai chấm được trình bày.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Before submitting a bug report:
- I have reproduced this on the latest released version of PSScriptAnalyzer and VS Code PowerShell extension.
- I have searched for existing issues and did not find this bug reported.
Steps to reproduce
$errorMsg = 'Some error details'
$feature = 'EnablePlacesWebApp'
# Using format operator
Write-Log -Message ('Failed to enable {0}: {1}' -f $feature, $errorMsg) -Level 'ERROR'
Write-Host ("`n❌ Failed to enable {0}: {1}" -f $feature, $errorMsg) -ForegroundColor Red
# Using string concatenation
Write-Log -Message ('Failed to enable ' + $feature + ': ' + $errorMsg) -Level 'ERROR'
Write-Host ("`n❌ Failed to enable " + $feature + ": " + $errorMsg) -ForegroundColor Red
Expected behavior
No error or warning should be reported by PSScriptAnalyzer for valid PowerShell syntax using the format operator or string concatenation, regardless of the character following the variable.
Actual behavior
PSScriptAnalyzer reports:
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
This occurs even when using the format operator (-f) or string concatenation, which are valid and idiomatic PowerShell.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
No unexpected error thrown; this is a linter false positive.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
...
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
2.10.0
Additional context:
This issue also appears in the VS Code PowerShell extension, which integrates PSScriptAnalyzer for diagnostics. Please coordinate with the extension maintainers if needed.
- 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ự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
azurenoops/spin_agent#975 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15108 · 1 bình luận ·