Skip to content

Commit

Permalink
Fix formatting (RCS1208) (fix #891)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Apr 2, 2022
1 parent 2e882b7 commit 09a4f2a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1208ReduceIfNestingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Roslynator.CSharp.CodeFixes;
using Roslynator.Testing.CSharp;
using Xunit;

namespace Roslynator.CSharp.Analysis.Tests
{
public class RCS1208ReduceIfNestingTests : AbstractCSharpDiagnosticVerifier<ReduceIfNestingAnalyzer, IfStatementCodeFixProvider>
{
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.ReduceIfNesting;

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ReduceIfNesting)]
public async Task Test()
{
await VerifyDiagnosticAndFixAsync(@"
class C
{
void M(bool p)
{
[|if|] (p)
{
M2();
}
}
void M2()
{
}
}
", @"
class C
{
void M(bool p)
{
if (!p)
{
return;
}
M2();
}
void M2()
{
}
}
");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static async Task<Document> RefactorAsync(
semanticModel,
cancellationToken);

SyntaxNode newNode = rewriter.Visit(node);
SyntaxNode newNode = rewriter.Visit(node).WithFormatterAnnotation();

return await document.ReplaceNodeAsync(node, newNode, cancellationToken).ConfigureAwait(false);
}
Expand Down

0 comments on commit 09a4f2a

Please sign in to comment.