Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fca5b4e

Browse files
authored
Fix analyzer RCS1077 - Handle IQueryable<T> (#1544)
1 parent bde6487 commit fca5b4e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Fix analyzer [RCS1202](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1202) ([PR](https://github.com/dotnet/roslynator/pull/1542))
1313
- Fix analyzer [RCS1246](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1246) ([PR](https://github.com/dotnet/roslynator/pull/1543))
1414
- Fix analyzer [RCS1140](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1140) ([PR](https://github.com/dotnet/roslynator/pull/1524))
15+
- Fix analyzer [RCS1077](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1077) ([PR](https://github.com/dotnet/roslynator/pull/1544))
1516

1617
## [4.12.6] - 2024-09-23
1718

src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,14 @@ public static void AnalyzeOrderByIdentity(SyntaxNodeAnalysisContext context, in
718718
if (lambdaExpression.Body is not IdentifierNameSyntax identifier || identifier.Identifier.Text != lambdaExpression.Parameter.Identifier.Text)
719719
return;
720720

721+
if (context.SemanticModel
722+
.GetTypeSymbol(invocationInfo.Expression, context.CancellationToken)?
723+
.OriginalDefinition
724+
.HasMetadataName(MetadataNames.System_Linq_IQueryable_T) == true)
725+
{
726+
return;
727+
}
728+
721729
TextSpan span = TextSpan.FromBounds(invocationInfo.Name.SpanStart, invocationExpression.Span.End);
722730
Report(context, invocationExpression, span, checkDirectives: true);
723731
}

src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,23 @@ void M()
15601560
list.FirstOrDefault(predicate);
15611561
}
15621562
}
1563+
");
1564+
}
1565+
1566+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeLinqMethodCall)]
1567+
public async Task TestNoDiagnostic_OrderByToOrder_IQueryable()
1568+
{
1569+
await VerifyNoDiagnosticAsync(@"
1570+
using System.Linq;
1571+
1572+
class C
1573+
{
1574+
void M()
1575+
{
1576+
IQueryable<string> q = null;
1577+
var x = q.OrderBy(f => f);
1578+
}
1579+
}
15631580
");
15641581
}
15651582
}

0 commit comments

Comments
 (0)