PowerShell / PowerShell/PSScriptAnalyzer
Rule Idea: Warn on `[xml](Get-Content <File>)` pattern
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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