PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 378 forks source link

Rule PSReservedParams generates Warning instead of Error #1973

Open pulkownik1803 opened 8 months ago

pulkownik1803 commented 8 months ago

PSScriptAnalyzer reports PSReservedParams as warning but according to the documentation it's error

Steps to reproduce

function Test-Function {
    [CmdletBinding()]
    param (
        # Error
        [Parameter()]
        [string]
        $ErrorVariable
    )
    $ErrorVariable = 'Error'
}

> Invoke-ScriptAnalyzer -Path .\Test-Function.ps1

Expected behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSReservedParams                    Error        Test-Funct 5     'Test-Function' defines the reserved common parameter       
                                                 ion.ps1          'ErrorVariable'.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSReservedParams                    Warning      Test-Funct 5     'Test-Function' defines the reserved common parameter       
                                                 ion.ps1          'ErrorVariable'.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.22621.2506
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2506
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.21.0
SydneyhSmith commented 7 months ago

Thanks @pulkownik1803

bergmeister commented 7 months ago

Thanks, I think it's best to fix code like you did rather than documentation because for this rule, violations result in code that won't even run.