Where(...) is followed by First, Single, Any, Count or a similar call without arguments, which takes the condition itself
What it finds
items.Where(p).First() builds an extra iterator; items.First(p) does the same in one step and reads more directly. The same holds for FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, Any and Count.
From the rule's source, filter_before_terminal.rs.
using System.Linq; class Users{ bool Admin(string[] roles) => roles.Where(r => r == "admin").Any();tx0 reports: Where(...).Any() can pass the condition to Any bool Direct(string[] roles) => roles.Any(r => r == "admin");} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:filter-before-terminal" = "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:filter-before-terminal] reason="..."tx0 explain tx0/csharp:filter-before-terminal shows the same in the terminal. Found a false positive? Report it.