PSSlack icon indicating copy to clipboard operation
PSSlack copied to clipboard

Private cmdlets use unapproved verbs (PSUseApprovedVerbs)

Open kanjibates opened this issue 7 years ago • 6 comments

A number of the private cmdlets are flagged by PSScriptAnalyzer for using an unapproved PowerShell verb:-

RuleName Severity ScriptName Line Message
PSUseApprovedVerbs Warning Color-ToNumber.ps1 1 The cmdlet 'Color-ToNumber' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackChannel.ps1 2 The cmdlet 'Parse-SlackChannel' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackGroup.ps1 1 The cmdlet 'Parse-SlackGroup' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackMessage.ps1 2 The cmdlet 'Parse-SlackMessage' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackMessage.ps1 9 The cmdlet 'Extract-Previous' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackTeam.ps1 2 The cmdlet 'Parse-SlackTeam' uses an unapproved verb.
PSUseApprovedVerbs Warning Parse-SlackUser.ps1 2 The cmdlet 'Parse-SlackUser' uses an unapproved verb.

The easiest way to fix this would be to explicitly suppress the PSUseApprovedVerbs rule for the Private\Parse-Slack* cmdlets by adding something like the below to each.

[Diagnostics.CodeAnalysis.SuppressMessage("PSUseApprovedVerbs", Scope="function")]

IMO, the cleaner way to fix this would be to rename those cmdlets to use an approved verb.

For the Parse- cmdlets, ConvertTo- or New- may be a suitable candidate from the current list of approved verbs, perhaps coupled with an Object or Type suffix (e.g., ConvertTo-SlackTeamObject),

Thoughts? Is a clean bill of health from PSScriptAnalyzer even worth pursuing?

kanjibates avatar Oct 15 '17 01:10 kanjibates

I feel it's a bit of semantics, however I see your point. Color-ToNumber could become Convert-ColorToNumber, and Extract-Precious could become Export-Previous, but looking at Microsoft's docu on this there really isn't anything that could be interchangeable for Parse. Without looking at what each of those Parse commands do I would assume Get could possibly be used? But as a whole does this really matter besides it would pass some validation tool? Is there confusion with the commands?

https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx

hairymonkeynuts avatar Oct 24 '17 17:10 hairymonkeynuts

IMO, the only time I personally leverage PSScriptAnalyzer suppression is for things like Password parameters when the actual use case for the function doesn't really allow something unsafe to be passed there. Resolving the PSScriptAnalyzer messages with approved verbs would be ideal.

Here are my thoughts on best replacements with approved verbs:

Existing Suggested
Color-ToNumber Convert-ColorToNumber
Extract-Previous Get-Previous
Parse-SlackChannel Resolve-SlackChannel
Parse-SlackGroup Resolve-SlackGroup
Parse-SlackMessage Resolve-SlackMessage
Parse-SlackTeam Resolve-SlackTeam
Parse-SlackUser Resolve-SlackUser

scrthq avatar Oct 25 '17 14:10 scrthq

Would it be proper to use the "diagnostic" verb Resolve? MS suggests diag verbs are "used to diagnose the health of something." I finally got to look those cmdlets over and ConvertTo might be closer to what I understand those scripts to be doing since it is a PSSlack type they are creating. Maybe?

hairymonkeynuts avatar Oct 25 '17 21:10 hairymonkeynuts

I'm thinking along the lines of Resolve-Path's behavior and looking at Resolve in that light, although Resolve is technically a diagnostic verb in PowerShell's definition. Maybe it's diagnosing the initial intention? 🙃

scrthq avatar Oct 25 '17 22:10 scrthq

Ah, right. Good point. Yeah, totally agree with that. Just wish MS didn't use it like that and create the contradiction and confusion.

hairymonkeynuts avatar Oct 26 '17 15:10 hairymonkeynuts

Receive-<...>Response (e.g. Receive-SlackUserResponse) might be an option as well.

hmmwhatsthisdo avatar Feb 17 '18 01:02 hmmwhatsthisdo