A composite format string refers to more arguments than are passed, or is malformed
What it finds
string.Format("{0} of {1}", done) throws FormatException at run time: the string asks for two arguments and gets one. The same holds for Console.WriteLine, StringBuilder.AppendFormat and TextWriter.Write with a format, and for unbalanced braces. Only calls whose format is a string literal and whose arguments are listed one by one are checked.
From the rule's source, format_arguments.rs.
using System;using System.Text; class Report{ string Line(int done, int total, StringBuilder sb) { Console.WriteLine("{0} of {1}", done);tx0 reports: the format refers to 2 arguments but 1 are passed sb.AppendFormat("{0}/{1}", done, total); var bad = string.Format("{0", done);tx0 reports: this format string has unbalanced braces and throws at run time Console.WriteLine("{literal}"); return string.Format("{0}: {2}", done, total);tx0 reports: the format refers to 3 arguments but 2 are passed }} 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:format-arguments" = "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:format-arguments] reason="..."tx0 explain tx0/csharp:format-arguments shows the same in the terminal. Found a false positive? Report it.