diff --git a/ChangeLog.md b/ChangeLog.md index 935b14192b..90790c6828 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Order named arguments even if optional arguments are not specified [RCS1205](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1205.md) ([#941](https://github.com/josefpihrt/roslynator/pull/941). - Prefix identifier with `@` if necessary ([RCS1220](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1220.md)) ([#943](https://github.com/josefpihrt/roslynator/pull/943). - Do not suggest to make local variable a const when it is used in ref extension method ([RCS1118](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1118.md)) ([#948](https://github.com/josefpihrt/roslynator/pull/948). +- Fix formatting of argument list ([#952](https://github.com/josefpihrt/roslynator/pull/952). ----- diff --git a/src/CSharp/CSharp/IndentationAnalysis.cs b/src/CSharp/CSharp/IndentationAnalysis.cs index 99949c3e55..f2c9304913 100644 --- a/src/CSharp/CSharp/IndentationAnalysis.cs +++ b/src/CSharp/CSharp/IndentationAnalysis.cs @@ -22,11 +22,11 @@ private IndentationAnalysis(SyntaxTrivia indentation, int indentSize) public SyntaxTrivia Indentation => (_indentSize == -1) ? default : _indentation; - public int IndentSize => (_indentSize == -1) ? _indentation.Span.Length : _indentSize; + public int IndentSize => (_indentSize == -1) ? 0 : _indentSize; public int IndentationLength => (_indentSize == -1) ? 0 : Indentation.Span.Length; - public int IncreasedIndentationLength => (_indentSize == -1) ? _indentation.Span.Length : (Indentation.Span.Length + _indentSize); + public int IncreasedIndentationLength => (_indentSize == -1) ? 0 : (Indentation.Span.Length + _indentSize); public bool IsDefault => _indentation == default && _indentSize == 0; @@ -47,7 +47,7 @@ public static IndentationAnalysis Create(SyntaxNode node, CancellationToken canc { return (trivia1.Span.Length > 0) ? new IndentationAnalysis(indentation, trivia1.Span.Length) - : new IndentationAnalysis(indentation, indentation.Span.Length); + : new IndentationAnalysis(indentation, -1); } else if (trivia1.Span.Length > 0) { diff --git a/src/Tests/Formatting.Analyzers.Tests/RCS0053FixFormattingOfListTests.cs b/src/Tests/Formatting.Analyzers.Tests/RCS0053FixFormattingOfListTests.cs index 6487297c6f..a7e57e8647 100644 --- a/src/Tests/Formatting.Analyzers.Tests/RCS0053FixFormattingOfListTests.cs +++ b/src/Tests/Formatting.Analyzers.Tests/RCS0053FixFormattingOfListTests.cs @@ -1272,5 +1272,29 @@ await VerifyNoDiagnosticAsync(@" .Select(f => f); ", options: Options.WithCompilationOptions(Options.CompilationOptions.WithOutputKind(OutputKind.ConsoleApplication))); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)] + public async Task TestNoDiagnostic_ArrayInitializerInGlobalStatement() + { + await VerifyNoDiagnosticAsync(@" +Foo.Method( + foo: new Foo[] + { + new Foo( + """") + }); +", additionalFiles: new[] { @" +public class Foo +{ + public Foo(string v1) + { + } + + internal static void Method(Foo[] foo) + { + } +} +" }, options: Options.WithCompilationOptions(Options.CompilationOptions.WithOutputKind(OutputKind.ConsoleApplication))); + } } }