vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Fake warning : $PSNativeCommandUseErrorActionPreference is assigned but never used

Open CyberSinh opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [ ] I have searched all open and closed issues to ensure it has not already been reported.
  • [ ] I have read the troubleshooting guide.
  • [ ] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [ ] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • [ ] If this is a security issue, I have read the security issue reporting guidance.

Summary

If I have $PSNativeCommandUseErrorActionPreference = $true in a script, I get the following warning in the Visual Studio Code issue pane: $PSNativeCommandUseErrorActionPreference is assigned but never used.

It is correct to assigned PowerShell preference variables, without explicitly using them in script.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
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

Visual Studio Code Version

1.86.0
05047486b6df5eb8d44b2ecd70ea3bdf775fd937
x64

Extension Version

[email protected]

Steps to Reproduce

Add $PSNativeCommandUseErrorActionPreference = $true in a script to get the fake warning.

Visuals

No response

Logs

No response

CyberSinh avatar Feb 04 '24 15:02 CyberSinh

These alerts come from ScriptAnalyzer, so the issue's root would be there, could you reopen the issue there? There's nothing we can do about it here. Thanks! https://github.com/PowerShell/PSScriptAnalyzer/issues/new?assignees=&labels=&projects=&template=Bug_report.md

https://github.com/PowerShell/PSScriptAnalyzer/blob/5c32f5559d4096ae2dc0ffc0f9d59fcbfbd02ccb/Engine/SpecialVars.cs#L95

JustinGrote avatar Feb 04 '24 17:02 JustinGrote

Thanks @JustinGrote ! The issue should be fixed in the next PSScriptAnalyzer version: https://github.com/PowerShell/PSScriptAnalyzer/pull/1954

CyberSinh avatar Feb 04 '24 19:02 CyberSinh

Thanks @CyberSinh! I'll reopen this and it will be closed when that version gets integrated into the extension.

CC @andyleejordan

JustinGrote avatar Feb 04 '24 19:02 JustinGrote

This issue has been labeled as resolved, please verify the provided fix (or other reason).

github-actions[bot] avatar Feb 04 '24 20:02 github-actions[bot]

@CyberSinh can you confirm this is fixed in the latest pre-release, v2024.3.2-preview, which as PSScriptAnalyzer 1.22.0 (which is supposed to have that fix)? (Seems to be for me!)

andyleejordan avatar Apr 04 '24 17:04 andyleejordan

This issue has been labeled as resolved, please verify the provided fix (or other reason).

github-actions[bot] avatar Apr 04 '24 18:04 github-actions[bot]

@andyleejordan I can confirm the fix works great. Thanks!

CyberSinh avatar Apr 04 '24 21:04 CyberSinh