PowerShell / PowerShell/PSScriptAnalyzer

'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem'

未关闭
#1,907 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue - Enhancement Up-for-Grabs
主要语言
C#
星标
2.2k
派生
414
平均合并
13 小时 1 分钟
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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 摘要。