PowerShell / PowerShell/PSScriptAnalyzer
Rule Idea: Warn on `[xml](Get-Content <File>)` pattern
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
Summary of the new feature
Warn on Pattern: [xml](Get-Content <File>)
Suggest Pattern: $a = [xml]::new(); $a.Load(<File>)
This pattern is currently in wide use, but it has some problems and should be discouraged.
-
This pattern, due to using Get-Content, has problems if the (perfectly valid) xml file being parsed is not utf8 encoded. See: https://github.com/PowerShell/PowerShell/issues/14505 & https://stackoverflow.com/questions/65263942/how-to-load-or-read-an-xml-file-using-convertto-xml-and-select-xml/65264118#65264118
-
This pattern is very inefficient. I know that PSSA does not generally worry about this - but since the encoding issue above exists, feels worth it to mention. Testing against a ~1mb file shows
[xml](Get-Content <File>)as ~12x slower, and against a 170mb file as 22x slower (loading took 46 seconds!).
What is the latest version of PSScriptAnalyzer at the point of writing
PSSA 1.19.1
Powershell Versions
This currently affects both Windows Powershell 5.1 and Powershell 7.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 针对 PSScriptAnalyzer 和 PowerShell 模式 [xml](Get-Content <File>)。首先找到分析器中针对基于模式的诊断的现有规则实现和测试;完成标准是:该模式会触发警告,并且建议的 XML 加载形式在 Windows PowerShell 5.1 和 PowerShell 7 上得到一致报告。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100