A method of a date, time span or immutable collection is called for its result, and the result is dropped
What it finds
DateTime, DateTimeOffset, TimeSpan, DateOnly and TimeOnly never change, and neither do the immutable collections: date.AddDays(1) returns a new date and leaves date as it was. Calling such a method as a statement does nothing. The rule reports these calls on variables whose declared type is one of these types, and on DateTime.Now, UtcNow and Today.
From the rule's source, ignored_immutable_result.rs.
using System;using System.Collections.Immutable; class Schedule{ void Move(DateTime start, ImmutableList<int> items) { start.AddDays(1);tx0 reports: the result of AddDays is dropped; the value itself does not change items.Add(3);tx0 reports: the result of Add is dropped; the value itself does not change var next = start.AddDays(1); Use(next); } void Use(DateTime value) { }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:ignored-immutable-result" = "off"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-immutable-result] reason="..."tx0 explain tx0/csharp:ignored-immutable-result shows the same in the terminal. Found a false positive? Report it.