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

The triggering of the PSUseOutputTypeCorrectly rule does not consider the presence of the redirection to $null #1500

Closed
LaurentDardenne opened this issue May 14, 2020 · 2 comments

Comments

@LaurentDardenne
Copy link

Steps to reproduce

$s=@'
  Function Test{
    [CmdletBinding()]
    param()
        [System.Windows.Forms.MessageBox]::Show('Message', 'text',0, 16) > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s

Expected behavior

No error

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseOutputTypeCorrectly            Information             4     The cmdlet 'Test' returns an object of type
                                                                  'System.Windows.Forms.DialogResult' but this type is
                                                                  not declared in the OutputType attribute.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.18362.752
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.752}
BuildVersion                   10.0.18362.752
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.0
1.18.3
1.18.1
1.18.0
1.17.1

Other tests with a type shortcut and a full type name, but with a property name has a different case

$s=@'
  Function Test{
    [CmdletBinding()]
    param()
        [datetime]::Now > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s
$s=@'
  Function Test{
    [CmdletBinding()]
    param()
        [datetime]::now > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s
$s=@'
  Function Test{
    [CmdletBinding()]
    param()
       [datetime]::FromFileTime(1) > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s

$s=@'
  Function Test{
    [CmdletBinding()]
    param()
        [System.Datetime]::now > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s
$s=@'
  Function Test{
    [CmdletBinding()]
    param()
        [System.Datetime]::Now > $null
  }
'@
Invoke-ScriptAnalyzer -ScriptDefinition $s

The code of the last two examples is identical except for the case of the property.
The triggering of the PSUseOutputTypeCorrectly rule seems to be case sensitive.

@bergmeister
Copy link
Collaborator

@LaurentDardenne Not all examples reproduce for me, like for example the first one but some do. I see this as low priority and have therefore marked it as up for grabs

@JustinGrote
Copy link

JustinGrote commented May 25, 2021

@bergmeister related to this, simply redirecting to a file, a common operation which does not actually produce an output, triggers the info as a false positive

image

Workaround: Use Out-File instead of >

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

4 participants