-
Notifications
You must be signed in to change notification settings - Fork 32
AV2220 behavior on query with multiple sources #137
Description
Analyzer
AvoidQuerySyntaxForSimpleExpressionAnalyzer
This is mostly a question of whether the observed behavior is by design or a bug.
In any case I'll workaround it, so don't drop everything to answer or fix/change this.
Repro steps
When doing a Cartesian product at least I find the query syntax less convoluted than the corresponding method syntax, but this triggers AV2220.
IEnumerable<int[]> QuerySyntax(int[] values)
{
return
from l in values
from r in values
select new[] { l, r };
}IEnumerable<int[]> MethodSyntax(int[] values)
{
return values.SelectMany(_ => values, (l, r) => new[] { l, r });
}I found a unit test with multiple sources.
From the test name I would assume it was the use of multiple sources that made it "complex", but running the test it crosses the complexity threshold of 1 due to the where.
Removing the where brings the complexity score down to 1 which triggers the diagnostic.
Lines 388 to 408 in de03d00
| [Fact] | |
| internal async Task When_method_contains_complex_query_with_multiple_sources_it_must_be_skipped() | |
| { | |
| // Arrange | |
| ParsedSourceCode source = new MemberSourceCodeBuilder() | |
| .Using(typeof(Enumerable).Namespace) | |
| .InDefaultClass(@" | |
| void M() | |
| { | |
| var query = | |
| from item in Enumerable.Empty<string>() | |
| from other in Enumerable.Empty<string>() | |
| where item.Length > 2 | |
| select item; | |
| } | |
| ") | |
| .Build(); | |
| // Act and assert | |
| await VerifyGuidelineDiagnosticAsync(source); | |
| } |
Expected behavior
Whenever multiple sources are used, AV2220 is not triggered.
Actual behavior
AV2220 is triggered.