PowerShell / PowerShell/PSScriptAnalyzer

'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem'

オープン
#1,907 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Issue - Enhancement Up-for-Grabs
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
2

説明

I keep getting warnings about implicitly aliasing which I feel are incorrect, but perhaps I'm missing something from my code.

Steps to reproduce

$Date = (get-date).AddDays(-14)
Get-ADComputer -Properties OperatingSystem, LastLogonTimeStamp -Filter {OperatingSystem -like '*Windows*' -and LastLogonTimeStamp -gt $Date}

Expected behavior

I should get a list of Windows computers with recent logons

Actual behavior

VSCode warns me that:

'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem' because it is missing the 'Get-' prefix. This can introduce possible problems and make scripts hard to maintain. Please consider changing command to its full name.

The auto-formatting then changes my code so my code fails.

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.2673
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.2673
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


VSCode 1.76.2
PSScriptAnalyzer 1.21.0
PowerShell extension v2023.3.3

Windows 10 Enterprise Version 22H2
OS Build 19045.2728

Outside of adding the data to the whitelist, should I be writing my code differently to avoid this issue?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue 1907 で提供されている PowerShell の再現手順から始め、VS Code で PSScriptAnalyzer 1.21.0 を使用した場合に報告されている警告とフォーマットの動作を比較します。暗黙的エイリアスの診断と formatter の経路を追跡します。AD プロパティ OperatingSystem が誤った警告や破壊的な書き換えを生成しなくなり、回帰テストのカバレッジが確保されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
powershell
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。