Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PSCloseBrace rule to not wrongly flag closing brace of one-line hashtable, which lead to incorrect formatting #1309

Merged

Conversation

bergmeister
Copy link
Collaborator

@bergmeister bergmeister commented Aug 15, 2019

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

@bergmeister bergmeister changed the title Fix PSCloseBrace rule to not wrongly flag one-line hashtable closing brace Fix PSCloseBrace rule to not wrongly flag closing brace of one-line hashtable, which lead to incorrect formatting Aug 17, 2019
@bergmeister bergmeister marked this pull request as ready for review August 17, 2019 15:50
Engine/TokenOperations.cs Outdated Show resolved Hide resolved
Engine/TokenOperations.cs Outdated Show resolved Hide resolved
Engine/TokenOperations.cs Show resolved Hide resolved
Co-Authored-By: Robert Holt <rjmholt@gmail.com>
@bergmeister bergmeister merged commit 4f82d81 into PowerShell:master Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codeFormatting.IgnoreOneLineBlock / hashtable problem
2 participants