Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RCS0053 false positive when using top-level statements #890

Closed
xt0rted opened this issue Mar 30, 2022 · 4 comments
Closed

RCS0053 false positive when using top-level statements #890

xt0rted opened this issue Mar 30, 2022 · 4 comments

Comments

@xt0rted
Copy link
Contributor

xt0rted commented Mar 30, 2022

Product and Version Used: 4.1.0

Steps to Reproduce: The full code triggering this can be seen here and a branch with the error is here xt0rted/dotnet-run-script#11.

var parser = new CommandLineBuilder(rootCommand)
    // ...
    .UseExceptionHandler((ex, ctx) =>
    {
        var verbose = ctx.ParseResult.HasOption(GlobalOptions.Verbose);
        var writer = new ConsoleWriter(ctx.Console, consoleFormatProvider, verbose);

        if (verbose)
        {
            writer.Error(ex.ToString());
        }
        else
        {
            writer.Error(ex.Message);
        }
    })
    // ...
    .Build();

Actual Behavior:

The rule flags the arrow function as being formatted incorrectly. The code fix removes the 4 space indent on the lines after the arrow but the rule still flags the block of code as being incorrectly formatted.

If I wrap the block of code in braces the rule no longer flags this piece of code which is why I believe it's related to using top-level statements.

{
    var parser = new CommandLineBuilder(rootCommand)
        // ...
        .UseExceptionHandler((ex, ctx) =>
        {
            var verbose = ctx.ParseResult.HasOption(GlobalOptions.Verbose);
            var writer = new ConsoleWriter(ctx.Console, consoleFormatProvider, verbose);

            if (verbose)
            {
                writer.Error(ex.ToString());
            }
            else
            {
                writer.Error(ex.Message);
            }
        })
        // ...
        .Build();
}

Something else I noticed is the error in my build output says RCS0053: Fix formatting of arguments while the docs say RCS0053: Fix formatting of a list.

Expected Behavior:

Given the config being used I'd expect the formatting of this piece of code to not flag any formatting rules.

@josefpihrt
Copy link
Collaborator

Hi,

thanks for the report. I can reproduce this bug and I have a fix for it.

The name "Fix formatting of a list" is general name. In this case it is a list of arguments but It also could be a list of parameters, attributes etc.

@fgimian
Copy link

fgimian commented Aug 27, 2022

Hey @josefpihrt, was this part of the 4.1.1 release? I started experiencing this issue when switching to top level statements with Roslynator 4.1.1.

image

Thanks heaps
Fotis

@josefpihrt
Copy link
Collaborator

josefpihrt commented Sep 15, 2022

Hi,

Sorry for late answer.

It would be better to open new issue because these comments to closed issue can easily fall into oblivion.

Anyway, it was part if the 4.1.1 release. Unfortunately, you discovered another bug 😄.

This additional bug was fixed with #952.

@fgimian
Copy link

fgimian commented Sep 16, 2022

Thank you so much. I'll be sure to raise a new issue in the future for such cases, apologies. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants