Skip to content

Commit dba6ce7

Browse files
author
Kapil Borle
committed
Apply NewLineAfter option only for if-else clause
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 ```
1 parent 8e3e68a commit dba6ce7

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Rules/PlaceCloseBrace.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,9 @@ private DiagnosticRecord GetViolationForBraceShouldHaveNewLineAfter(
314314
if (tokens.Length > 1 && tokens.Length > expectedNewLinePos)
315315
{
316316
var closeBraceToken = tokens[closeBracePos];
317-
if (tokens[expectedNewLinePos].Kind != TokenKind.NewLine
318-
&& tokens[expectedNewLinePos].Kind != TokenKind.Comment
319-
&& !tokensToIgnore.Contains(tokens[closeBracePos]))
317+
if ((tokens[expectedNewLinePos].Kind == TokenKind.Else
318+
|| tokens[expectedNewLinePos].Kind == TokenKind.ElseIf))
320319
{
321-
322320
return new DiagnosticRecord(
323321
GetError(Strings.PlaceCloseBraceErrorShouldFollowNewLine),
324322
closeBraceToken.Extent,

0 commit comments

Comments
 (0)