Skip to content

Commit

Permalink
Fix formatting of list in a top-level statement (RCS0053) (fix #890)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Apr 2, 2022
1 parent 1bb7bd3 commit e988ffc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/CSharp/CSharp/IndentationAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public static IndentationAnalysis Create(SyntaxNode node, CancellationToken canc
{
return new IndentationAnalysis(indentation, trivia1.Span.Length - trivia2.Span.Length);
}
else if (indentation.Span.Length > 0)
{
return (trivia1.Span.Length > 0)
? new IndentationAnalysis(indentation, trivia1.Span.Length)
: new IndentationAnalysis(indentation, indentation.Span.Length);
}
else if (trivia1.Span.Length > 0)
{
return new IndentationAnalysis(trivia1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,5 +1252,25 @@ void M()
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
public async Task TestNoDiagnostic_LambdaBlockBodyInGlobalStatement()
{
await VerifyNoDiagnosticAsync(@"
using System.Linq;
foreach (var item in Enumerable.Range(0, 10))
{
var s = """";
}
var items = Enumerable.Range(0, 10)
.Select(f =>
{
return f;
})
.Select(f => f);
", options: Options.WithCompilationOptions(Options.CompilationOptions.WithOutputKind(OutputKind.ConsoleApplication)));
}
}
}

0 comments on commit e988ffc

Please sign in to comment.