Skip to content

PSUseCmdletCorrectly breaks on Write-Verbose -Verbose #1624

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

Open
Jaykul opened this issue Jan 7, 2021 · 2 comments
Open

PSUseCmdletCorrectly breaks on Write-Verbose -Verbose #1624

Jaykul opened this issue Jan 7, 2021 · 2 comments

Comments

@Jaykul
Copy link
Contributor

Jaykul commented Jan 7, 2021

I'm getting a rule violation when we force Write-Verbose to have output like this:

Write-Verbose -Verbose "My Message"

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition '
Write-Verbose -Verbose "Getting file list from $pwd"
Write-Warning -Verbose "Getting file list from $pwd"
Write-Error -Verbose "Getting file list from $pwd"
Write-Error -ErrorAction SilentlyContinue "Getting file list from $pwd"
' -IncludeRule PSUseCmdletCorrectly

Expected behavior

There are no violations.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseCmdletCorrectly                Warning                 2     Cmdlet 'Write-Verbose' may be used incorrectly. Please
                                                                  check that all mandatory parameters are supplied.
PSUseCmdletCorrectly                Warning                 3     Cmdlet 'Write-Warning' may be used incorrectly. Please
                                                                  check that all mandatory parameters are supplied.

I think it's significant that it has no problem with either of the Write-Error lines, but I have not looked at the code to understand what is happening ...

Environment data

> $PSVersionTable

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


> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
1.19.1
@SydneyhSmith
Copy link
Collaborator

Thanks @Jaykul looks like PSUseCmdletCorrectly isn't very good at positional parameters, especially when a switch is also used...in this case I would expect to get only a warning of PSAvoidPositionalParameters (if that rule is turned on)

@bergmeister
Copy link
Collaborator

I remember seeing this behaviour the first time around 2 years ago as I think previous PSSA versions did not flag that, but I wasn't too concerned as it was easy resolve by having the switch at the end. I believe this regression was introduced in #963

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

No branches or pull requests

3 participants