PowerShell / PowerShell/PSScriptAnalyzer
PSAvoidOverwritingBuiltInCmdlets (core-6.1.0-*) returns warning for Write-Log, which is not a built-in cmdlet
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
Before submitting a bug report:
- Make sure you are able to repro it on the latest released version
- Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
Create a file called Write-Log.psm1 in your home directory and populate it with an empty function called Write-Log:
function Write-Log {
}
Install and run PSScriptAnalyzer against the file:
> Install-Module PSScriptAnalyzer
> Invoke-ScriptAnalyzer -Path ~\Write-Log.psm1
Expected behavior
PSScriptAnalyzer returns no findings because Write-Log is not a built-in cmdlet.
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidOverwritingBuiltInCmdlets Warning Write-Log.psm1 1 'Write-Log' is a cmdlet that is included with PowerShell (version core-6.1.0-windows) whose definition should not be overridden
This behaviour should be reproducible cross-platform.
Troubleshooting
Write-Log was never shipped with any version of PowerShell, but it is erroneously defined as a built-in cmdlet:
Probable cause is described in https://github.com/PowerShell/PowerShell/issues/7209 as an upstream issue in PSDesiredStateConfiguration that was reportedly fixed in 2020. However, the PSScriptAnalyzer files affected by that issue were never rebuilt afterwards.
The module that may have caused this problem at the time is https://github.com/microsoft/PowerShellForGitHub, which defines Write-Log and then suppresses PSScriptAnalyzer reports in Helper.ps1#L128. The PR to suppress that finding is recorded in https://github.com/microsoft/PowerShellForGitHub/pull/180. If this module was present in the build environment, then PSScriptAnalyzer would have added Write-Log and possibly other cmdlets to the list of built-in cmdlets even though they do not ship with PowerShell.
As a result, default installations of PSScriptAnalyzer return a false warning for PSAvoidOverwritingBuiltInCmdlets against cmdlets named Write-Log.
It is possible that there may be other cmdlets erroneously included in these files for the same reason.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.24.0
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Engine/Settings にある core-6.1.0 のプラットフォーム設定ファイルから始め、特に Write-Log 周辺のエントリを確認し、Linux ARM、Linux、macOS、Windows 間で組み込み cmdlet の一覧を比較します。PowerShell に同梱されていないエントリを削除または修正してから、Write-Log.psm1 の再現に対して Invoke-ScriptAnalyzer を実行し、同様の誤警告がないか確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 68/100