A StringBuilder is created with a char, which is taken as its capacity and not as its text
What it finds
StringBuilder has no constructor that takes a char; new StringBuilder('[') converts the character to its code, 91, and creates an empty builder with that capacity. Passing a string, new StringBuilder("["), starts the builder with the text.
From the rule's source, char_as_builder_capacity.rs.
using System.Text; class Lists{ string Start() { var sb = new StringBuilder('[');tx0 reports: '[' is taken as the capacity of the builder, not as its text var ok = new StringBuilder("["); return sb.ToString() + ok; }} 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:char-as-builder-capacity" = "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:char-as-builder-capacity] reason="..."tx0 explain tx0/csharp:char-as-builder-capacity shows the same in the terminal. Found a false positive? Report it.