Skip to content
Open
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 @@ -36,5 +36,83 @@ public void Method()

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied property accessors.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedPropertyAccessorsAsync()
{
var testCode = @"
class TestClass
{
public int TestProperty
{
get =>
// A comment line
42;

set =>
// A comment line
_ = value;
}
}";

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied indexer accessors.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedIndexerAccessorsAsync()
{
var testCode = @"
class TestClass
{
public int this[int i]
{
get =>
// A comment line
42;

set =>
// A comment line
_ = value;
}
}";

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied event accessors.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedEventAccessorsAsync()
{
var testCode = @"
class TestClass
{
public event System.Action TestEvent
{
add =>
// A comment line
_ = value;

remove =>
// A comment line
_ = value;
}
}";

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

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied properties.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedPropertyAsync()
{
var testCode = @"
class TestClass
{
public int TestProperty =>
// A comment line
42;
}";

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied indexers.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedIndexerAsync()
{
var testCode = @"
class TestClass
{
public int this[int i] =>
// A comment line
42;
}";

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

/// <summary>
/// Verifies that the analyzer does not fire in expression bodied methods.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3550, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3550")]
public async Task TestExpressionBodiedMethodAsync()
{
var testCode = @"
class TestClass
{
public int TestMethod(int x) =>
// A comment line
42;
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ private static bool IsAtStartOfScope(SyntaxTrivia trivia)
|| (prevToken.IsKind(SyntaxKind.OpenBracketToken) && prevToken.Parent.IsKind(SyntaxKindEx.CollectionExpression))
|| prevToken.Parent.IsKind(SyntaxKind.CaseSwitchLabel)
|| prevToken.Parent.IsKind(SyntaxKindEx.CasePatternSwitchLabel)
|| prevToken.Parent.IsKind(SyntaxKind.DefaultSwitchLabel);
|| prevToken.Parent.IsKind(SyntaxKind.DefaultSwitchLabel)
|| prevToken.IsKind(SyntaxKind.EqualsGreaterThanToken);
}

private static bool IsPrecededByDirectiveTrivia<T>(T triviaList, int triviaIndex)
Expand Down