Skip to content

Commit

Permalink
Fix formatting of argument list (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 15, 2022
1 parent cb3d80d commit 8b27c6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

-----
<!-- Content below does not adhere to 'Keep a Changelog' format -->
Expand Down
6 changes: 3 additions & 3 deletions src/CSharp/CSharp/IndentationAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}

0 comments on commit 8b27c6a

Please sign in to comment.