PowerShell / PSScriptAnalyzer

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

PSAvoidUsingCmdletAliases triggers on GherkinStep #896

Open codykonior opened 6 years ago

codykonior commented 6 years ago

Gherkin (including in Pester) has a few aliases which you are meant to use when creating steps.

Alias           And -> GherkinStep                                 4.2.0      Pester
Alias           But -> GherkinStep                                 4.2.0      Pester
Alias           Given -> GherkinStep                               4.2.0      Pester
Alias           Then -> GherkinStep                                4.2.0      Pester
Alias           When -> GherkinStep                                4.2.0      Pester

These are valid uses of the alias and shouldn't trigger analyzer warnings.

Steps to reproduce

Create a Gherkin (Pester) step file like Blah.Steps.ps1

Given "something" {
}

Then Invoke-ScriptAnalyzer Blah.Steps.ps1

Expected behavior

No issues.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      Blah.Steps 1     'Given' is an alias of 'GherkinStep'. Alias can introduce
                                                 .ps1             possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.

Environment data

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

1.16.1

LaurentDardenne commented 6 years ago

You can configure this rule.

codykonior commented 6 years ago

You can but I believe users should not have to - not for language built into Pester/Gherkin which in turn is built into and distributed with Windows PowerShell.

bergmeister commented 6 years ago

I agree that this could certainly be improved because Pester is the most commonly used test framework by now. We are open to PRs but otherwise this might take some time otherwise until it gets fixed. Just as a side note: In the future, Pester will get removed from PowerShell again (has already in PowerShell Core and is planned for Windows PowerShell as well) due to various problems.