Skip to content
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

Setting $ErrorView is flagged as a warning: PSUseDeclaredVarsMoreThanAssignment #1749

Closed
Kurt-von-Laven opened this issue Nov 16, 2021 · 2 comments · Fixed by #1865
Closed

Comments

@Kurt-von-Laven
Copy link

Steps to reproduce

$ErrorView = 'NormalView'

Expected behavior

No warning is issued for assignment without use of any preference variable. This is another variation of #651 and an instance of #1641.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseDeclaredVarsMoreThanAssignment Warning      config.ps1 27    The variable
s                                                                 'ErrorView' i
                                                                  s assigned bu
                                                                  t never used.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
You cannot call a method on a null-valued expression.
At line:1 char:73
+ ... vailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
+                                                           ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

I am running PSScriptAnalyzer via MegaLinter v5.0.7.

@StevenBucher98
Copy link
Collaborator

Thanks @Kurt-von-Laven, we have reproduced this issue and are marking it up for grabs for a fix.

@bergmeister
Copy link
Collaborator

Yes, agree as well. This would be an easy fix by inserting an if statement here:

yield return new DiagnosticRecord(

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.

4 participants