PowerShell / PowerShell/PSScriptAnalyzer

PSAvoidUsingCmdletAliases triggers on GherkinStep

Open
#896 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Rules Issue - Enhancement Up-for-Grabs
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning with the Blah.Steps.ps1 example by running Invoke-ScriptAnalyzer, focusing on PSAvoidUsingCmdletAliases and the GherkinStep aliases. Done means Given, And, But, When, and Then used as Pester Gherkin steps produce no analyzer issues while ordinary aliases remain covered by the rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.