The result of a string method is ignored, although strings never change
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.
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); }} 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-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.