dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.09k stars 256 forks source link

Consider disabling `RCS0012` for fields #1395

Open RenderMichael opened 8 months ago

RenderMichael commented 8 months ago

Product and Version Used:

4.10.0

Steps to Reproduce:

internal sealed class C
{
    private readonly string? x; // RCS0012
    private readonly string? y;

    public C(string x, string y)
    {
        this.x = x;
        this.y = y;
    }

    public void UseVariables()
    {
        // dismiss warnings about unused variable
        _ = x;
        _ = y;
    }
}

Actual Behavior: Warning RCS0012: Add blank lines between single-line declarations

Expected Behavior: In contrast with properties and methods, fields are often written without a separate line between them. There is a case to be made that the analyzer should not warn in this case.

Perhaps it would at least be possible to make a different diagnostic for fields, so it can be separately suppressed.

josefpihrt commented 8 months ago

Maybe the desired behavior could be achieved by adding editorconfig option, something like:

roslynator_blank_line_between_singleline_declarations.field = false
roslynator_blank_line_between_single_line_declarations.fields = false
roslynator_blank_line_between_single_line_declarations.field_declarations = false