diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1515CSharp7UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1515CSharp7UnitTests.cs index 2c57c7072..20ac50089 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1515CSharp7UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1515CSharp7UnitTests.cs @@ -36,5 +36,83 @@ public void Method() await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } + + /// + /// Verifies that the analyzer does not fire in expression bodied property accessors. + /// + /// A representing the asynchronous unit test. + [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); + } + + /// + /// Verifies that the analyzer does not fire in expression bodied indexer accessors. + /// + /// A representing the asynchronous unit test. + [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); + } + + /// + /// Verifies that the analyzer does not fire in expression bodied event accessors. + /// + /// A representing the asynchronous unit test. + [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); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1515UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1515UnitTests.cs index 894ed44aa..52ae74bbb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1515UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1515UnitTests.cs @@ -301,5 +301,62 @@ class TestClass await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); } + + /// + /// Verifies that the analyzer does not fire in expression bodied properties. + /// + /// A representing the asynchronous unit test. + [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); + } + + /// + /// Verifies that the analyzer does not fire in expression bodied indexers. + /// + /// A representing the asynchronous unit test. + [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); + } + + /// + /// Verifies that the analyzer does not fire in expression bodied methods. + /// + /// A representing the asynchronous unit test. + [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); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1515SingleLineCommentMustBePrecededByBlankLine.cs b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1515SingleLineCommentMustBePrecededByBlankLine.cs index 515f276d7..011a37800 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1515SingleLineCommentMustBePrecededByBlankLine.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1515SingleLineCommentMustBePrecededByBlankLine.cs @@ -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 triviaList, int triviaIndex)