Skip to content

Commit

Permalink
Fix indentation analysis (fix #859) (RCS0054)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Nov 13, 2021
1 parent 3a82b0b commit 9a0d664
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/CSharp/CSharp/SyntaxTriviaAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ public static int DetermineIndentationSize(SyntaxNode node, CancellationToken ca
if (size > 0)
return size;

break;
}
case GlobalStatementSyntax:
{
break;
}
default:
Expand All @@ -431,9 +435,7 @@ public static int DetermineIndentationSize(SyntaxNode node, CancellationToken ca

int DetermineIndentationSize(CompilationUnitSyntax compilationUnit)
{
MemberDeclarationSyntax member = compilationUnit.Members.FirstOrDefault();

if (member != null)
foreach (MemberDeclarationSyntax member in compilationUnit.Members)
{
if (member is NamespaceDeclarationSyntax namespaceDeclaration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ C M(string s)
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfCallChain)]
public async Task Test_TopLevelStatement()
{
await VerifyNoDiagnosticAsync(@"
using System;
Console
.WriteLine();
class Program
{
void Main(string[] args)
{
}
}
", options: Options.WithCompilationOptions(Options.CompilationOptions.WithOutputKind(OutputKind.ConsoleApplication)));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfCallChain)]
public async Task TestNoDiagnostic()
{
Expand Down

0 comments on commit 9a0d664

Please sign in to comment.