Skip to content

Workflows should not trigger UseShouldProcessForStateChangingFunctions #922

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

Closed
tboddyspargo opened this issue Mar 5, 2018 · 1 comment · Fixed by #923
Closed

Workflows should not trigger UseShouldProcessForStateChangingFunctions #922

tboddyspargo opened this issue Mar 5, 2018 · 1 comment · Fixed by #923
Assignees

Comments

@tboddyspargo
Copy link

Steps to reproduce

workflow Set-MyConfig {
  [CmdletBinding(DefaultParameterSetName="myset")]
  Param( [Parameter(Mandatory, ParameterSetName="myset")][String]$param1 )
  Return $param1
}

Expected behavior

I expect the above workflow to NOT trigger UseShouldProcessForStateChangingFunctions. Said rule should only apply to functions (not workflows).

Actual behavior

The above workflow definition triggers UseShouldProcessForStateChangingFunctions and it should not. Workflows support the use of certain features of the CmdletBinding attribute, but not "SupportsShouldProcess". As a result, you cannot satisfy the rule while still leveraging the benefits of CmdletBinding attribute (e.g. DefaultParameterSetName).

Environment data

PSVersionTable:

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

PSScriptAnalyzerVersion: 1.10.0

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 5, 2018

Thanks for reporting this. Since you correctly stated that SupportsShouldProcess is not supported (and not even allowed syntax) for a workflow, I agree that workflows should be excluded from this rule. I created a PR with the fix for it is below.
P.S. You should really update your PSScriptAnalyzer version, many more fixes and features have been added since 1.10 (we are already at 1.16.1 and the upcoming release that will come out soon will contain even much more). ;-)

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