Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
impl
  • Loading branch information
josefpihrt committed Sep 27, 2024
commit 020fd16b9dacb67e68be4521233ea47fc9a2a0a8
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> q = null;
var x = q.OrderBy(f => f);
}
}
");
}

}