Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,25 @@ class C
ExpectedDiagnostics = { Diagnostic().WithLocation(4, 35).WithArguments(" not", "preceded") },
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that a closing interpolation brace which is the first token on its line is not reported, using the
/// newlines in interpolations allowed by C# 11.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3898, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3898")]
public async Task TestInterpolationClosingBraceFirstOnLineAsync()
{
var testCode = @"
class C
{
string M(int x) => $""abc {x
} def"";
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,40 @@ class ClassName

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that a closing interpolation brace which is the first token on its line is not reported, while one
/// preceded by a space on the same line still is.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3898, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3898")]
public async Task TestVerbatimInterpolationClosingBraceFirstOnLineAsync()
{
var testCode = @"
public class TestClass
{
public string TestMethod(int x)
{
return $@""abc {x
} def {x {|#0:}|} ghi"";
}
}
";

var fixedCode = @"
public class TestClass
{
public string TestMethod(int x)
{
return $@""abc {x
} def {x} ghi"";
}
}
";

var expected = Diagnostic().WithLocation(0).WithArguments(" not", "preceded");
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, Syn

if (token.Parent is InterpolationSyntax)
{
if (precededBySpace)
// A closing interpolation brace may be the first token on its line, for example when the
// interpolation expression spans multiple lines.
if (precededBySpace && !token.IsFirstInLine())
{
// Closing brace should{ not} be {preceded} by a space.
var properties = TokenSpacingProperties.RemovePreceding;
Expand Down
Loading