field-name-no-underscore
What it does
Section titled “What it does”Reports a field whose name begins with an underscore. The option fields is the expression a field name must match.
Why it matters
Section titled “Why it matters”The convention of many style guides names fields in camel case without a prefix and tells them from locals by writing this.. A leading underscore is the other convention; a project picks one, and the rule enforces it.
To fix, rename the field.
Example
Section titled “Example”class C{ private int _count; private int count;}Configuration
Section titled “Configuration”csharp: lint: rules: field-name-no-underscore: level: warn # off (default), warn, error options: fields: "^[^_]"| Option | Type | Default | Description |
|---|---|---|---|
fields |
string | "^[^_]" |
Regular expression the name of a field must match; empty: not checked. |
Enabled by the presets: csharp/stylecop.
Suppress one line with sudsy-disable-next-line field-name-no-underscore in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| StyleCop | SA1309 |
full |