◐ Shell
clean mode source ↗

Fix PSCloseBrace rule to not wrongly flag closing brace of one-line hashtable, which lead to incorrect formatting by bergmeister · Pull Request #1309 · PowerShell/PSScriptAnalyzer

PR Summary

Fixes #1284

This fixes a bug (that must've been long-standing) in the GetBracePairs method (which returns all pairs of braces except for hashtables) of the TokenOperations class where it can wrongly pair an RBrace of an hashtable with the LCurly of a braced expression. This caused incorrect formatting of the script definition if ($true) { $test = @{ } } where the selected RBrace was the one of the hashtable and not the ifexpression, therefore leading to an incorrectly added newline before the final brace by the PSCloseBrace rule used by Invoke-Formatter (default rules settings are such that one-line expressions do not require a newline before the closing brace).

PR Checklist