Two arguments of a call are named like each other's parameters, so they are likely passed in the wrong order

tx0/csharp:swapped-argumentsstrictwarningreliability/api-misusedepth fastbug

What it finds

Resize(height, width) for a method declared as Resize(int width, int height) passes each value to the other parameter; with parameters of one type the compiler cannot notice. Reported are calls of methods and local functions declared in the same file, under a name no other method there has, where two arguments are plain names that are the names of each other's parameters. Exchanges that are usually on purpose are left alone: a method calling itself, pairs such as left and right or min and max, names of one or two characters, calls in a method that also passes the two in order, and calls in code named for comparing, reversing or swapping.

From the rule's source, swapped_arguments.rs.

Example from the rule's tests
class Shapes{    int Area(int width, int height) => width * height;     int Span(int low, int high)    {        if (low > high)        {            return Span(high, low);        }        return high - low;    }     int Box(int width, int height, int depth)    {        int a = Area(height, width);tx0 reports: height and width are passed to Area in the order of each other's parameters        int c = Area(depth, width);        int d = Area(width: height, height: width);        return this.Area(height, width) + a + c + d;tx0 reports: height and width are passed to Area in the order of each other's parameters    }     int Both(int width, int height) => Area(width, height) + Area(height, width);     int Turned(int width, int height)    {        int reversed = Area(height, width);        return reversed;    }     int Ratio(int x, int y, int min, int max) => Scale(y, x) + Clamp(max, min);     int Scale(int x, int y) => x / y;     int Clamp(int min, int max) => max - min;}
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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

tx0 explain tx0/csharp:swapped-arguments shows the same in the terminal. Found a false positive? Report it.