Skip to content

Commit c3d6fce

Browse files
committed
Respect diagnostic RCS0062 for RCS1016 and RR0169
1 parent 392c421 commit c3d6fce

File tree

5 files changed

+201
-61
lines changed

5 files changed

+201
-61
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.CodeAnalysis.CSharp;
2+
3+
namespace Roslynator.CSharp.Analysis;
4+
5+
internal static class ConvertExpressionBodyAnalysis
6+
{
7+
public static bool AllowPutExpressionBodyOnItsOwnLine(SyntaxKind syntaxKind)
8+
{
9+
// allow putting expression on new line for all method-like declarations, except for accessors.
10+
switch (syntaxKind)
11+
{
12+
case SyntaxKind.MethodDeclaration:
13+
case SyntaxKind.ConstructorDeclaration:
14+
case SyntaxKind.DestructorDeclaration:
15+
case SyntaxKind.PropertyDeclaration:
16+
case SyntaxKind.IndexerDeclaration:
17+
case SyntaxKind.OperatorDeclaration:
18+
case SyntaxKind.ConversionOperatorDeclaration:
19+
return true;
20+
default:
21+
return false;
22+
}
23+
}
24+
}

src/Formatting.Analyzers/CSharp/PutExpressionBodyOnItsOwnLineAnalyzer.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.CodeAnalysis.CSharp.Syntax;
77
using Microsoft.CodeAnalysis.Diagnostics;
88
using Roslynator.CSharp;
9+
using Roslynator.CSharp.Analysis;
910
using Roslynator.CSharp.CodeStyle;
1011

1112
namespace Roslynator.Formatting.CSharp;
@@ -37,17 +38,9 @@ private static void AnalyzeArrowExpressionClause(SyntaxNodeAnalysisContext conte
3738
{
3839
var arrowExpressionClause = (ArrowExpressionClauseSyntax)context.Node;
3940

40-
switch (arrowExpressionClause.Parent.Kind())
41+
if (ConvertExpressionBodyAnalysis.AllowPutExpressionBodyOnItsOwnLine(arrowExpressionClause.Parent.Kind()))
4142
{
42-
case SyntaxKind.MethodDeclaration:
43-
case SyntaxKind.ConstructorDeclaration:
44-
case SyntaxKind.DestructorDeclaration:
45-
case SyntaxKind.PropertyDeclaration:
46-
case SyntaxKind.IndexerDeclaration:
47-
case SyntaxKind.OperatorDeclaration:
48-
case SyntaxKind.ConversionOperatorDeclaration:
49-
AnalyzeArrowExpressionClause(arrowExpressionClause.ArrowToken, context);
50-
break;
43+
AnalyzeArrowExpressionClause(arrowExpressionClause.ArrowToken, context);
5144
}
5245
}
5346

0 commit comments

Comments
 (0)