PowerShell / PowerShell/PSScriptAnalyzer

I suggest adding an "Accuracy" property to DiagnosticRecord.

未關閉
#234 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

Issue - Enhancement Up-for-Grabs
主要語言
C#
星號
2.2k
分支
415
平均合併
13 小時 1 分鐘
30 天內合併 PR
2

描述

Suggestion

Add an "Accuracy" property to DiagnosticRecord that will state the probability of the diagnostic being correct.

Benefits for the Users

Users can filter and sort diagnostics based on their accuracy.

    invoke-scriptanalyzer |
        where {$_.accuracy -gt 0.75} |
        sort rulename, accuracy -descending

Benefits for the Rule Writers

Rule writers can introduce new rules sooner by introducing rules with a low accuracy, and then later increase the accuracy as the rule is refined.

For example, the "UseShouldProcessForStateChangingFunctions" rule right now is based only on the function name, so the rule can be assigned with an accuracy of, let's say, 0.25. If the rule is improved with better heuristics, then its accuracy can be increased. If the default of Invoke-ScriptAnalyzer doesn't show diagnostics with an accuracy of less than 0.50, then users won't have to suppress the "UseShouldProcessForStateChangingFunctions" while the rule is still in its initial stages.

This allows rule writers to get feedback on their rules while the rules are still being refined without adding noise to Invoke-ScriptAnalyzer results.

Benefits for the Rules

The rules can have multiple diagnostic accuracies.

For example, the "PossibleIncorrectComparisonWithNull" will be more useful if it can output diagnostics with different accuracies based on context.

A line such as:

    if ($a -ne $null)

should output a diagnostic for this rule with a high accuracy because "$a -ne $null" is very likely to be a compare operation instead of a filter operation.

However, a line such as:

    $a = $b -ne $null

should output a diagnostic for this rule with a low accuracy because "$b -ne $null" can either be a compare operation or a filter operation, and it will be very difficult to assert that the user violated the rule.

Now, the rule doesn't have to be hardcoded with the compromise of when to generate diagnostics because it can generate all diagnostics with different accuracy levels.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先追蹤 DiagnosticRecord 和 Invoke-ScriptAnalyzer 的輸出路徑;該 issue 未指定原始檔案或測試。確定應如何表示準確度、由規則產生準確度,以及為篩選和排序提供準確度。完成的標準是:在所提議的診斷情境中,該屬性及其語意都得到一致支援。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp, powershell
領域
cli, devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。