A method that compares or combines two values is given the same expression twice
What it finds
Math.Max(a, a) is a, string.Equals(x, x) is true and s.Replace(old, old) changes nothing: the second argument was meant to be something else. The rule reports Math.Min, Math.Max, ReferenceEquals, Compare and CompareOrdinal with two identical arguments that have no side effects, and Replace with the same literal twice. Equals(x, x) is left alone: on vectors and floating-point values it is the usual test for NaN.
From the rule's source, same_argument_twice.rs.
using System; class Limits{ int Clamp(int a, int b) => Math.Max(a, a);tx0 reports: Max is given a twice string Clean(string s) => s.Replace("-", "-"); // want "`Replace` is given `"-"` twice" int Fine(int a, int b) => Math.Max(a, b);} 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:same-argument-twice" = "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:same-argument-twice] reason="..."tx0 explain tx0/csharp:same-argument-twice shows the same in the terminal. Found a false positive? Report it.