PowerShell / PowerShell/PSScriptAnalyzer

Rule request: PossibleArgumentWithOperatorConfusion

Đang mở
#2,014 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Issue - New Rule Issue-Enhancement Up-for-Grabs
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ả

PowerShell has two parsing modes:

It is not always clear whenever PowerShell is in argument mode, as in:

if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer"

For background information, see: Call operator (&{}) with no results doesn't type compare #24054

Yet from the argument name (and position and the operators) you could make a reasonable assumption that it probably concerns an operator instead.

For a (PowerShell based) rule prototype, see: https://github.com/iRon7/PSRules/blob/main/PossibleArgumentWithOperatorConfusion.psm1

Invoke-ScriptAnalyzer -CustomRulePath $RulePath -ScriptDefinition 'if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer" }' | Select-Object *

Line                 : 1
Column               : 5
Message              : Possible argument with operator (-isnot) confusion.
Extent               : &{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]
RuleName             : PSPossibleArgumentWithOperatorConfusion
Severity             : Warning
ScriptName           :
ScriptPath           :
RuleSuppressionID    :
SuggestedCorrections : {(&{ (1,2,3).Where{ $_ -eq 4} }) -isnot [int]}
IsSuppressed         : False

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với prototype của rule PowerShell trong PossibleArgumentWithOperatorConfusion.psm1 và xem issue về phân tích cú pháp PowerShell được liên kết để có thêm ngữ cảnh. So sánh chẩn đoán, phạm vi và phần sửa lỗi được đề xuất của prototype với các rule hiện có của PSScriptAnalyzer; được xem là hoàn thành khi sự nhầm lẫn được yêu cầu được phát hiện cùng với cảnh báo và phần sửa lỗi phù hợp.

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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.