Skip to content

Commit

Permalink
Fix analyzer RCS1016 and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Jan 23, 2022
1 parent 0509350 commit 8c633e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -208,7 +208,7 @@ private static void AnalyzeOperatorDeclaration(SyntaxNodeAnalysisContext context
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -272,7 +272,7 @@ private static void AnalyzeConversionOperatorDeclaration(SyntaxNodeAnalysisConte
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -336,7 +336,7 @@ private static void AnalyzeConstructorDeclaration(SyntaxNodeAnalysisContext cont
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -400,7 +400,7 @@ private static void AnalyzeDestructorDeclaration(SyntaxNodeAnalysisContext conte
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -464,7 +464,7 @@ private static void AnalyzeLocalFunctionStatement(SyntaxNodeAnalysisContext cont
if (!analysis.Success)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenDeclarationIsMultiLine == true
Expand Down Expand Up @@ -569,7 +569,7 @@ private static void AnalyzeAccessorDeclarationBlock(
if (expression == null)
return;

if (style.UseBlock)
if (!style.UseExpression)
return;

if (style.UseBlockWhenExpressionIsMultiLine == true
Expand Down
15 changes: 15 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1016UseBlockBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,5 +833,20 @@ public static explicit operator C(string value)
}
", options: Options.AddConfigOption(ConfigOptionKeys.BodyStyle, ConfigOptionValues.BodyStyle_Block));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseBlockBodyOrExpressionBody)]
public async Task TestNoDiagnostic_AccessorWithSingleLineBlock()
{
await VerifyNoDiagnosticAsync(@"
class C
{
public string P
{
get { throw new System.Exception(); }
set { throw new System.Exception(); }
}
}
", options: Options.AddConfigOption(ConfigOptionKeys.UseBlockBodyWhenDeclarationSpansOverMultipleLines, true));
}
}
}

0 comments on commit 8c633e9

Please sign in to comment.