PowerShell / PowerShell/PSScriptAnalyzer
Rule request: Prefix parameters with an unambiguous (ASCII) hyphen-minus
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ả
Hyphen-minus characters are sometimes unintendedly replaced when passed by word processors as Microsoft Office applications as MSWord and Outlook. It is recommended to prefix parameters with an unambiguous hyphen-minus as Unicode dashes might cause parsing errors in earlier versions of PowerShell.
Besides it unnecessary triggers the UseBOMForUnicodeEncodedFile rule with no clear indication of the location.
PowerShell 7
# .\Test.ps1
Write-Host “test” –ForegroundColor ‘Red’ -BackgroundColor ‘Green’
Invoke-ScriptAnalyzer .\Test.ps1
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidUsingWriteHost Warning Test.ps1 1 File 'Test.ps1' uses Write-Host. Avoid using
Write-Host because it might not work in all hosts,
does not work when there is no host, and (prior to
PS 5.0) cannot be suppressed, captured, or
redirected. Instead, use Write-Output,
Write-Verbose, or Write-Information.
PSUseBOMForUnicodeEncodedFile Warning Test.ps1 Missing BOM encoding for non-ASCII encoded file
'Test.ps1'
Windows PowerShell (5.1)
Windows PowerShell (5.1) still has issue with EM-dashes:
.\test.ps1
At C:\Users\Gebruiker\downloads\Test.ps1:1 char:25
+ ... “test†–ForegroundColor ‘Red’ -BackgroundColor ‘Green’
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Invoke-ScriptAnalyzer .\Test.ps1
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
TerminatorExpectedAtEndOfString ParseError Test.ps1 1 The string is missing the terminator: ".
PSAvoidUsingWriteHost Warning Test.ps1 1 File 'Test.ps1' uses Write-Host. Avoid using
Write-Host because it might not work in all hosts,
does not work when there is no host, and (prior to
PS 5.0) cannot be suppressed, captured, or
redirected. Instead, use Write-Output,
Write-Verbose, or Write-Information.
PSUseBOMForUnicodeEncodedFile Warning Test.ps1 Missing BOM encoding for non-ASCII encoded file
'Test.ps1'
Proposed technical implementation details (optional)
See (PowerShell based) prototype UseHyphenMinusForParameter at: https://github.com/iRon7/PSRules
What is the latest version of PSScriptAnalyzer at the point of writing
1.21.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 với các ví dụ PowerShell trong issue và xem xét prototype UseHyphenMinusForParameter được liên kết trong PSRules. So sánh hành vi được đề xuất với các rule PSScriptAnalyzer hiện có và output của UseBOMForUnicodeEncodedFile. Công việc được xem là hoàn tất khi các ký tự gạch ngang Unicode được dùng để thêm tiền tố cho tham số được phát hiện kèm vị trí và chẩn đoán rõ ràng, bao gồm các trường hợp PowerShell đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ 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