PowerShell / PowerShell/PSScriptAnalyzer
PSUseOutputTypeCorrectly is triggered when it shouldn't.
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
It looks to me like PSUseOutputTypeCorrectly check is not taking very basic, crucial, fundamental fact about PowerShell into account: by default it will not keep any simple collection, unless you explicitly tell it to.
Result? I have PInvoke code (taken from here) and I correctly defined OutputType as [Connection] (I've actually created namespace for it, but that's irrelevant).
As expected, Get-Member confirms that PowerShell function will return stream of connections, not collection as a whole. Yet, PSScriptAnalyzer will complain about it:
Line: 45 - The cmdlet 'Get-OPNetStat' returns an object of type 'Optiver.Connection[]' but this type is not declared in the OutputType attribute.
Line: 54 - The cmdlet 'Get-OPNetStat' returns an object of type 'Optiver.Connection[]' but this type is not declared in the OutputType attribute.
In fact, if I would follow instructions and declare my OutputType as a collection it would be conflicting with what my function actually returns:
Set-StrictMode -Version Latest
Get-OPNetStat | % IsFixedSize
% : The input name "IsFixedSize" cannot be resolved to a member.
IsFixedSize was tab-completed, based on OutputType that PSScriptAnalyzer told me to define. As expected, my Connection object doesn't have it. The only workaround I've found that satisfies both PSScriptAnalyzer and my hope to get nice tab-completion for command I wrote is to pass result of the command thru ForEach-Object:
[Optiver.NetworkUtil]::GetTCP() } | ForEach-Object { $_ }
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
PSUseOutputTypeCorrectly ルールから始め、報告された Get-OPNetStat の例を再現します。これには [Optiver.NetworkUtil]::GetTCP() の出力と Get-Member の動作を含めます。宣言された [Connection] 出力型と、アナライザーの Connection[] 診断を比較します。完了の条件は、有効なストリーム出力でこの誤警告が発生しなくなり、出力型のタブ補完が正確なままであることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100