PowerShell / PSScriptAnalyzer

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

Proposal: Signal invalid syntax in switch statement condition #1977

Open SetTrend opened 8 months ago

SetTrend commented 8 months ago

The switch statement condition syntax seems obscure from time to time. See PowerShell issues 21299 and 10911.

Hence, I suggest do add a few checks to test switch statement conditions for invalid syntax. (I.e., syntax that will never be evaluated, or that will always evaluate to $false etc.)

SydneyhSmith commented 8 months ago

Thanks @SetTrend would love to see more commentary on how someone would think about constructing this rule/what conditions they would consider before moving to up for grabs

bergmeister commented 7 months ago

Happy to add a rule but we need something concrete that we can alert on based on just static analysis without false positives. But I fear if the parser cannot do that due to PowerShell's dynamic nature, I am not sure PSSA can do better.