Skip to content

PSNativeCommandUseErrorActionPreference usage flagged by PSUseDeclaredVarsMoreThanAssignments #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aelij opened this issue Jan 12, 2023 · 3 comments · Fixed by #1954
Closed

Comments

@aelij
Copy link
Contributor

aelij commented Jan 12, 2023

Steps to reproduce

$PSNativeCommandUseErrorActionPreference = $true

Expected behavior

No analyzer warning

Actual behavior

The variable 'PSNativeCommandUseErrorActionPreference' is assigned but never used.
PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Microsoft Windows 10.0.22621
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.21.0
@ghost ghost added the Needs: Triage 🔍 label Jan 12, 2023
@StevenBucher98
Copy link
Collaborator

StevenBucher98 commented Jan 30, 2023

$PSNativeCommandUseErrorActionPreference is an experimental feature in 7.3+, its likely it was never added to be excluded from that rule

@bergmeister is there a list of variables that this rule ignores that this could be added to?

@bergmeister
Copy link
Collaborator

@StevenBucher98 Yes, you just need to add it to AutomaticVariables and AutomaticVariableTypes here
https://github.com/PowerShell/PSScriptAnalyzer/blob/4869a78ca0330fc45edac27c11a2879dfbe3caef/Engine/SpecialVars.cs

@aelij
Copy link
Contributor Author

aelij commented Dec 24, 2023

The feature is no longer experimental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants