Skip to content

Commit d81705d

Browse files
committed
SA1513 no longer reported for closing brace in first part of conditional expression
1 parent 6be2d79 commit d81705d

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1513UnitTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ public object[] ExpressionBodiedMethod() =>
393393
3
394394
}
395395
.Contains(3);
396+
397+
// This is a regression test for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1583
398+
public void TestTernaryConstruction()
399+
{
400+
var target = contained
401+
? new Dictionary<string, string>
402+
{
403+
{ ""target"", ""_parent"" }
404+
}
405+
: new Dictionary<string, string>();
406+
}
396407
}
397408
";
398409

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1513ClosingCurlyBracketMustBeFollowedByBlankLine.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ private void AnalyzeCloseBrace(SyntaxToken token)
249249
return;
250250
}
251251

252+
if (nextToken.IsKind(SyntaxKind.ColonToken)
253+
&& IsPartOf<ConditionalExpressionSyntax>(token))
254+
{
255+
// the close brace is in the first part of a conditional expression.
256+
return;
257+
}
258+
252259
if (nextToken.IsKind(SyntaxKind.AddKeyword)
253260
|| nextToken.IsKind(SyntaxKind.RemoveKeyword)
254261
|| nextToken.IsKind(SyntaxKind.GetKeyword)

0 commit comments

Comments
 (0)