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
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix