PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Proposal: Signal invalid syntax in switch statement condition

Open SetTrend opened this issue 1 year ago • 2 comments

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.)

SetTrend avatar Mar 04 '24 11:03 SetTrend

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

SydneyhSmith avatar Mar 27 '24 22:03 SydneyhSmith

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.

bergmeister avatar Apr 09 '24 10:04 bergmeister