Skip to content

separate-field-declarations

C#stylefix: safedefault: offcsharp/stylecop

Reports a declaration of several fields or events (int a, b;), which becomes int a; and int b;, each with the attributes, modifiers and type of the original. The fix is not offered when the declaration has a comment in it.

One field to a declaration gives each its own line, so a change to one is one line in the diff and each can have its own comment and initializer.

Reported
class A {
int a, b;
Nullable<int> n = (long)1 < 2 ? null : null;
void F(object o, int i) {
var f = delegate (int x) { return x; };
...
csharp:
lint:
rules:
separate-field-declarations: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line separate-field-declarations in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1132 full