A field is explicitly initialized to the default value of its type, which it has anyway
What it finds
Fields start as zero, false or null before any constructor runs. Initializing them to that value again adds code that the runtime executes for every instance and a line that says nothing. Constants and readonly fields are left alone.
From the rule's source, default_value_initializer.rs.
class Counter{ private int count = 0;tx0 reports: count is initialized to the value it has by default private bool done = false;tx0 reports: done is initialized to the value it has by default private int start = 1; private const int None = 0;} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:default-value-initializer" = "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:default-value-initializer] reason="..."tx0 explain tx0/csharp:default-value-initializer shows the same in the terminal. Found a false positive? Report it.