Skip to content

Fix PlaceCloseBrace rule behavior for NewLineAfter option #741

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

Merged
merged 2 commits into from
Mar 31, 2017

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Mar 30, 2017

This change constrains the behavior of PlaceCloseBrace rule when NewLineAfter option is set to true. Previously, if this option is set to true, the rule will trigger on any close brace that is not followed by a new line except if the close brace is part of a command element AND script block expression. This caused the rule to be too aggressive. We illustrate two such instances.

In the following instance the rule would trigger on the close brace that precedes the comma in the array expression. In VSCode

Some-Command -Param1 @{
 key="value"
},@{
 key="value"
}

would get formatted to

Some-Command -Param1 @{
 key="value"
}
,@{
 key="value"
}

In the following instance the rule would trigger on the close brace that precedes the the parameter -param2 in the command expression. In VSCode,

Some-Command -Param1 @{
 key="value"
} -Param2

would get formatted to

Some-Command -Param1 @{
 key="value"
}
-Param2

Fixes PowerShell/vscode-powershell#559

Kapil Borle added 2 commits March 30, 2017 16:03
This constrains the behavior of PlaceCloseBrace rule when NewLineAfter option is set to true. Previously, if this option is set to true, the rule will trigger on any close brace that is not followed by a new line except if the close brace is part of a command element AND script block expression. This caused the rule to be too aggressive. We illustrate two such instances.

In the following instance the rule would add a new line between the close brace and the comma following it, which makes the command expression invalid.
```powershell
Some-Command -Param1 @{
 key="value"
},@{
 key="value"
}
```
would get formatted to
```powershell
Some-Command -Param1 @{
 key="value"
}
,@{
 key="value"
}
```

In the following instance the rule would add a new line between the close brace and the parameter following it, which again makes the command expression invalid.
```powershell
Some-Command -Param1 @{
 key="value"
} -Param2
```
would get formatted to
```powershell
Some-Command -Param1 @{
 key="value"
}
-Param2
```
Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good!

@kapilmb kapilmb merged commit 9a420d1 into development Mar 31, 2017
@kapilmb
Copy link
Author

kapilmb commented Mar 31, 2017

Thanks @daviwil!

@kapilmb kapilmb deleted the kapilmb/fix-close-brace-rule branch March 31, 2017 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting 'newLineAfterCloseBrace' not recognizing instances where a newline should not be added.
3 participants