Giter Site home page Giter Site logo

Comments (9)

raghushantha avatar raghushantha commented on May 10, 2024

Feature Team - Triaged - Approved

from psscriptanalyzer.

yutingc avatar yutingc commented on May 10, 2024

Should this rule only be applied to exported functions? There should be cases where helper functions contain these verbs in their function definition?

from psscriptanalyzer.

quoctruong avatar quoctruong commented on May 10, 2024

I was thinking maybe this should apply to function that has CmdletBinding property in the parameter?

from psscriptanalyzer.

raghushantha avatar raghushantha commented on May 10, 2024

Correct. Any function that supports cmdlet-style parameter binding needs to have this rule.

from psscriptanalyzer.

raghushantha avatar raghushantha commented on May 10, 2024

Also, ShouldProcess applies to -whatif and -confirm parameters

"Another pair of common parameters is -whatif and -confirm. Any cmdlet that makes some kind of change to the computer is supposed to recognize those. They give you the option of having the cmdlet display what it would normally do (-whatif), or have it individually confirm each action (-confirm). "

There is a good technet article on this:
https://technet.microsoft.com/en-us/magazine/ff677563.aspx

from psscriptanalyzer.

yutingc avatar yutingc commented on May 10, 2024

So the implementation should be: if a function definition has Verbs that change system status and has CmdletBinding property in the parameter, we should make sure it also include these two attributes:ShouldProcess and ConfirmImpact.

from psscriptanalyzer.

quoctruong avatar quoctruong commented on May 10, 2024

I think that sounds good

from psscriptanalyzer.

yutingc avatar yutingc commented on May 10, 2024

Sorry, I don't think "ConfirmImpact" should be mandatory here."ShouldProcess" is required but "ConfirmImpact" should be optional in this case.

According to MSDN:
"To support confirmation requests, the cmdlet must set the SupportsShouldProcess parameter of the Cmdlet attribute to true. This enables the Confirm and WhatIf cmdlet parameters that are provided by Windows PowerShell."

"For most cmdlets, you do not have to explicitly specify ConfirmImpact. Instead, use the default setting of the parameter, which is Medium. If you set ConfirmImpact to High, the operation will be confirmed by default. Reserve this setting for highly disruptive actions, such as reformatting a hard-disk volume."

from psscriptanalyzer.

yutingc avatar yutingc commented on May 10, 2024

New Rule UseShouldProcessForStateChangingFunctions added (4/17).

from psscriptanalyzer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.