From 020fd16b9dacb67e68be4521233ea47fc9a2a0a8 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 27 Sep 2024 16:02:36 +0200 Subject: [PATCH 1/3] impl --- .../Analysis/OptimizeLinqMethodCallAnalysis.cs | 8 ++++++++ .../RCS1077OptimizeLinqMethodCallTests.cs | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs b/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs index 4a1dec85be..935cc02a0d 100644 --- a/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs +++ b/src/Analyzers/CSharp/Analysis/OptimizeLinqMethodCallAnalysis.cs @@ -718,6 +718,14 @@ public static void AnalyzeOrderByIdentity(SyntaxNodeAnalysisContext context, in if (lambdaExpression.Body is not IdentifierNameSyntax identifier || identifier.Identifier.Text != lambdaExpression.Parameter.Identifier.Text) return; + if (context.SemanticModel + .GetTypeSymbol(invocationInfo.Expression, context.CancellationToken)? + .OriginalDefinition + .HasMetadataName(MetadataNames.System_Linq_IQueryable_T) == true) + { + return; + } + TextSpan span = TextSpan.FromBounds(invocationInfo.Name.SpanStart, invocationExpression.Span.End); Report(context, invocationExpression, span, checkDirectives: true); } diff --git a/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs b/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs index 990a40c3d1..c819e3c752 100644 --- a/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs @@ -1562,4 +1562,22 @@ void M() } "); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeLinqMethodCall)] + public async Task TestNoDiagnostic_OrderByToOrder_IQueryable() + { + await VerifyNoDiagnosticAsync(@" +using System.Linq; + +class C +{ + void M() + { + IQueryable q = null; + var x = q.OrderBy(f => f); + } +} +"); + } + } From 24dde60c523697882ac027d64862356f717c6d82 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 27 Sep 2024 16:04:38 +0200 Subject: [PATCH 2/3] changelog --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 60cf048e59..1414509add 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix analyzer [RCS1202](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1202) ([PR](https://github.com/dotnet/roslynator/pull/1542)) - Fix analyzer [RCS1246](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1246) ([PR](https://github.com/dotnet/roslynator/pull/1543)) +- Fix analyzer [RCS1077](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1077) ([PR](https://github.com/dotnet/roslynator/pull/1544)) ## [4.12.6] - 2024-09-23 From e66bded93aeb72e5bdd3eeee62198e031640b561 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 27 Sep 2024 16:12:58 +0200 Subject: [PATCH 3/3] fix --- src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs b/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs index c819e3c752..e3ed4de296 100644 --- a/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs @@ -1579,5 +1579,4 @@ void M() } "); } - }