Skip to content

Commit e099358

Browse files
Fix review comments
#3759
1 parent 32646fb commit e099358

File tree

2 files changed

+58
-26
lines changed

2 files changed

+58
-26
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1131UnitTests.cs

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,55 @@ public void Test()
521521
[InlineData("Method1", "Const1", false)]
522522
[InlineData("Method2", "Const1", false)]
523523
[WorkItem(3677, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3677")]
524-
public async Task TestMethodsAsync(string expr1, string expr2, bool shouldTrigger)
524+
public async Task TestSimpleMethodsAsync(string expr1, string expr2, bool shouldTrigger)
525+
{
526+
await this.TestMethodAsync(expr1, expr2, shouldTrigger).ConfigureAwait(false);
527+
}
528+
529+
[Theory]
530+
[InlineData("TestClass.Method1", "arg", true)]
531+
[InlineData("this.Method2", "arg", true)]
532+
[InlineData("TestClass.Method1", "field1", true)]
533+
[InlineData("this.Method2", "field1", true)]
534+
[InlineData("TestClass.Method1", "field2", true)]
535+
[InlineData("this.Method2", "field2", true)]
536+
[InlineData("Const1", "TestClass.Method1", false)]
537+
[InlineData("Const1", "this.Method2", false)]
538+
[InlineData("TestClass.Method1", "Const1", false)]
539+
[InlineData("this.Method2", "Const1", false)]
540+
[InlineData("Method3<int>", "arg", true)]
541+
[InlineData("TestClass.Method3<int>", "arg", true)]
542+
[WorkItem(3759, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3759")]
543+
public async Task TestComplexMethodsAsync(string expr1, string expr2, bool shouldTrigger)
544+
{
545+
await this.TestMethodAsync(expr1, expr2, shouldTrigger).ConfigureAwait(false);
546+
}
547+
548+
[Theory]
549+
[InlineData("==")]
550+
[InlineData("!=")]
551+
[InlineData(">=")]
552+
[InlineData("<=")]
553+
[InlineData(">")]
554+
[InlineData("<")]
555+
[WorkItem(3759, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3759")]
556+
public async Task TestComplexLeftHandSideExpressionAsync(string @operator)
557+
{
558+
var testCode = $@"
559+
using System;
560+
public class TypeName
561+
{{
562+
public void Test(int x, int y, Func<int> a)
563+
{{
564+
var r1 = x + 1 {@operator} y;
565+
var r2 = -x {@operator} y;
566+
var r3 = a() {@operator} y;
567+
}}
568+
}}";
569+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
570+
}
571+
572+
private async Task TestMethodAsync(string expr1, string expr2, bool shouldTrigger)
525573
{
526574
var testExpr = $"{expr1} == {expr2}";
527575
var testCode = $@"
@@ -546,6 +594,10 @@ private static void Method1()
546594
private void Method2()
547595
{{
548596
}}
597+
598+
private static void Method3<T>()
599+
{{
600+
}}
549601
}}
550602
";
551603

@@ -572,6 +624,10 @@ private static void Method1()
572624
private void Method2()
573625
{{
574626
}}
627+
628+
private static void Method3<T>()
629+
{{
630+
}}
575631
}}
576632
";
577633

@@ -584,29 +640,5 @@ private void Method2()
584640
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
585641
}
586642
}
587-
588-
[Theory]
589-
[InlineData("==")]
590-
[InlineData("!=")]
591-
[InlineData(">=")]
592-
[InlineData("<=")]
593-
[InlineData(">")]
594-
[InlineData("<")]
595-
[WorkItem(3759, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3759")]
596-
public async Task TestComplexLeftHandSideExpressionAsync(string @operator)
597-
{
598-
var testCode = $@"
599-
using System;
600-
public class TypeName
601-
{{
602-
public void Test(int x, int y, Func<int> a)
603-
{{
604-
var r1 = x + 1 {@operator} y;
605-
var r2 = -x {@operator} y;
606-
var r3 = a() {@operator} y;
607-
}}
608-
}}";
609-
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
610-
}
611643
}
612644
}

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1131UseReadableConditions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static bool IsLiteral(ExpressionSyntax expression, SemanticModel semanti
9090

9191
// NOTE: Without the when clause, this would also treat e.g unary or binary expressions as literals,
9292
// since GetSymbolInfo returns the operator method in those cases.
93-
case IMethodSymbol when expression is IdentifierNameSyntax:
93+
case IMethodSymbol when expression is NameSyntax or MemberAccessExpressionSyntax:
9494
return true;
9595

9696
default:

0 commit comments

Comments
 (0)