PowerShell / PowerShell/PSScriptAnalyzer

PSAvoidOverwritingBuiltInCmdlets (core-6.1.0-*) returns warning for Write-Log, which is not a built-in cmdlet

Đang mở
#2,146 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Up-for-Grabs
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

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:

https://github.com/PowerShell/PSScriptAnalyzer/blob/e2804796f43eab60f5d105f6bbaea83fb446a13d/Engine/Settings/core-6.1.0-linux-arm.json#L1391-L1395

https://github.com/PowerShell/PSScriptAnalyzer/blob/e2804796f43eab60f5d105f6bbaea83fb446a13d/Engine/Settings/core-6.1.0-linux.json#L1391-L1395

https://github.com/PowerShell/PSScriptAnalyzer/blob/e2804796f43eab60f5d105f6bbaea83fb446a13d/Engine/Settings/core-6.1.0-macos.json#L1391-L1395

https://github.com/PowerShell/PSScriptAnalyzer/blob/e2804796f43eab60f5d105f6bbaea83fb446a13d/Engine/Settings/core-6.1.0-windows.json#L1692-L1696

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các tệp cài đặt nền tảng của core-6.1.0 trong Engine/Settings, đặc biệt là các mục xung quanh Write-Log, và so sánh danh sách cmdlet tích hợp sẵn trên Linux ARM, Linux, macOS và Windows. Xóa hoặc sửa các mục không được phân phối cùng PowerShell, sau đó chạy Invoke-ScriptAnalyzer trên bản tái hiện Write-Log.psm1 và kiểm tra các cảnh báo sai tương tự.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.