PowerShell / PowerShell/PSScriptAnalyzer
I suggest adding an "Accuracy" property to DiagnosticRecord.
还没有人认领这个 Issue。
- 主要语言
- 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪 DiagnosticRecord 和 Invoke-ScriptAnalyzer 的输出路径;该 issue 未指明源文件或测试。确定应如何表示准确性、由规则生成准确性,以及为筛选和排序提供准确性。完成的标准是:在所提议的诊断场景中,该属性及其语义都得到一致支持。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, powershell
- 领域
- cli, devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100