The result of a string method is ignored, although strings never change

tx0/csharp:ignored-string-resultdefaultwarningreliability/strings-and-regexdepth fastbug

What it finds

Strings are immutable: name.Trim(); returns a trimmed copy and leaves name as it is. Without using the result the call does nothing. The methods checked are those that exist only on strings among common types: Trim, TrimStart, TrimEnd, ToUpper, ToLower, their invariant forms, PadLeft, PadRight, Substring and Normalize.

From the rule's source, ignored_string_result.rs.

Example from the rule's tests
class Names{    string Clean(string name)    {        name.Trim();tx0 reports: the result of Trim is ignored; strings never change        name.ToUpperInvariant();tx0 reports: the result of ToUpperInvariant is ignored; strings never change        name = name.Trim();        return name.Substring(1);    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/csharp:ignored-string-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-string-result] reason="..."

tx0 explain tx0/csharp:ignored-string-result shows the same in the terminal. Found a false positive? Report it.