Skip to content

Commit 8a9a731

Browse files
committed
Check while token of do statement with a non-block body
1 parent 9f7ce61 commit 8a9a731

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1138UnitTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,13 @@ void MethodName()
614614
615615
do
616616
return;
617-
while (true);
617+
while (true);
618618
619619
do
620620
do
621621
return;
622-
while (true);
623-
while (true);
622+
while (true);
623+
while (true);
624624
}
625625
}
626626
";
@@ -635,9 +635,12 @@ void MethodName()
635635
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(10, 1),
636636
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(12, 1),
637637
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(13, 1),
638+
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(14, 1),
638639
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(16, 1),
639640
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(17, 1),
640641
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(18, 1),
642+
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(19, 1),
643+
this.CSharpDiagnostic(SA1137ElementsShouldHaveTheSameIndentation.SA1138DiagnosticId).WithLocation(20, 1),
641644
};
642645

643646
protected string FixedStatementTestCode => @"

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1137ElementsShouldHaveTheSameIndentation.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,16 +1012,21 @@ private void AnalyzeCheckedStatement(CheckedStatementSyntax node)
10121012

10131013
private void AnalyzeDoStatement(DoStatementSyntax node)
10141014
{
1015+
ImmutableArray<SyntaxToken> tokens;
1016+
10151017
if (node.Statement.IsKind(SyntaxKind.Block))
10161018
{
10171019
BlockSyntax block = (BlockSyntax)node.Statement;
1018-
var tokens = ImmutableArray.Create(GetFirstTokenForAnalysis(node), block.OpenBraceToken, block.CloseBraceToken, node.WhileKeyword);
1019-
CheckTokens(this.context, this.compilation, this.settings, this.IndentationLevel - 1, tokens);
1020+
tokens = ImmutableArray.Create(GetFirstTokenForAnalysis(node), block.OpenBraceToken, block.CloseBraceToken, node.WhileKeyword);
10201021
}
10211022
else
10221023
{
1024+
tokens = ImmutableArray.Create(GetFirstTokenForAnalysis(node), node.WhileKeyword);
1025+
10231026
CheckElements(this.context, this.compilation, this.settings, this.IndentationLevel, ImmutableList.Create(node.Statement));
10241027
}
1028+
1029+
CheckTokens(this.context, this.compilation, this.settings, this.IndentationLevel - 1, tokens);
10251030
}
10261031

10271032
private void AnalyzeFixedStatement(FixedStatementSyntax node)

0 commit comments

Comments
 (0)