The result of a LINQ query method is ignored, so the query never runs
What it finds
items.Where(x => x.Done); and orders.Select(Process); build a lazy query and drop it: nothing is filtered and the lambda never runs. Use the result, or a loop when the lambda is meant for its effects.
From the rule's source, ignored_linq_result.rs.
using System.Collections.Generic;using System.Linq; class Queries{ void Run(List<int> items) { items.Where(x => x > 1);tx0 reports: the result of Where is ignored, so the query never runs items.Select(x => x * 2).Distinct();tx0 reports: the result of Distinct is ignored, so the query never runs items.Reverse(); var kept = items.Where(x => x > 1).ToList(); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:ignored-linq-result" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:ignored-linq-result] reason="..."tx0 explain tx0/csharp:ignored-linq-result shows the same in the terminal. Found a false positive? Report it.