PowerShell / PSScriptAnalyzer

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

Warn when partial enumeration values are used #600

Open KirkMunro opened 8 years ago

KirkMunro commented 8 years ago

Here's a little known feature that could come back to bite someone later with a broken script:

gsv blah -ea ig

I'm not sure in which version of PowerShell this was added, but you can now use partial enumeration values and as long as that partial value leads to an unambiguous match, it will be accepted.

This may result in errors in scripts that appear to be working correctly if a new emumeration value is added with the same leading characters as those that are in use within a script. It's the same issue/risk with using partial parameter names in scripts. Shorthand should be for ad-hoc use only, and PSScriptAnalyzer should have a rule that warns whenever an enumeration value is used in a script in shorthand (such as in the command above).

KirkMunro commented 8 years ago

I suppose I was making an assumption that I should verify: PSScriptAnalyzer already warns when you use parameter aliases or parameter shorthand, does it not? If not, it definitely should, at least for the latter.

kapilmb commented 8 years ago

At this point, PSScriptAnalyzer doesn't have a rule that warns if you use parameter aliases or parameter shorthand. So, we now are two taking about two new rules -

  1. Warn when partial enumeration values are used
  2. Warn when parameter aliases or parameter shorthand is used