Skip to content

Commit

Permalink
Fix analyzer RCS1077 - Handle IQueryable<T> (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 27, 2024
1 parent bde6487 commit fca5b4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 [RCS1140](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1140) ([PR](https://github.com/dotnet/roslynator/pull/1524))
- 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

Expand Down
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
17 changes: 17 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1077OptimizeLinqMethodCallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,23 @@ void M()
list.FirstOrDefault(predicate);
}
}
");
}

[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);
}
}
");
}
}

0 comments on commit fca5b4e

Please sign in to comment.