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

RCS0054 doesn't work correctly with top-level statements #859

Closed
xt0rted opened this issue Nov 8, 2021 · 2 comments
Closed

RCS0054 doesn't work correctly with top-level statements #859

xt0rted opened this issue Nov 8, 2021 · 2 comments

Comments

@xt0rted
Copy link
Contributor

xt0rted commented Nov 8, 2021

Product and Version Used:

  • Roslynator.Analyzers 3.2.2
  • Roslynator.CodeAnalysis.Analyzers 1.1.1
  • Roslynator.Formatting.Analyzers 1.2.2
Project config
  <ItemGroup>
    <PackageReference Include="Roslynator.Analyzers" Version="3.2.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="1.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.Formatting.Analyzers" Version="1.2.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

Steps to Reproduce:

  • In VS2022 create a new ASP.NET Core Web App targeting .net 6
  • Add the above packages & versions to the project
  • Set RCS0054 to error
  • Try to chain multiple methods off of builder.Services in Program.cs
builder.Services
    .AddRazorPages()
    .AddTagHelpersAsServices();

Actual Behavior:

This rule reports an error and the build fails. Running the code fix changes the code to this, which also fails the build:

builder.Services
.AddRazorPages()
.AddTagHelpersAsServices();

To get the build to pass I have to indent all 3 lines like so:

    builder.Services
    .AddRazorPages()
    .AddTagHelpersAsServices();

Expected Behavior:

For this rule to support top-level statements.

@xt0rted
Copy link
Contributor Author

xt0rted commented Mar 26, 2022

@josefpihrt I just ran into this again with v4.0.0 and v4.0.2. This block of code is being flagged and the fix is to remove the leading 4 spaces from all of the lines.

https://github.com/xt0rted/dotnet-run-script/blob/1dbd178cb8e08ea0f1629e9c0d4d616af9d665ee/src/Program.cs#L47-L69

I have the same piece of code in another project that's not being flagged, but I think that's because it's scoped inside of a using.

https://github.com/xt0rted/dotnet-rimraf/blob/8e81792965356a65473bd915c52243ed4efa399c/src/Program.cs#L16-L38

@josefpihrt
Copy link
Collaborator

@xt0rted fixed with 83cd527

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

2 participants