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 Accepting only strange formatting in this situation #1203

Open
eduardomezencio opened this issue Sep 15, 2023 · 4 comments
Open

RCS0054 Accepting only strange formatting in this situation #1203

eduardomezencio opened this issue Sep 15, 2023 · 4 comments

Comments

@eduardomezencio
Copy link

Product and Version Used: dotnet 7, Roslynator.Analyzers 4.5.0

Steps to Reproduce:
The following code, in top level statements:

builder.Services
    .AddMyServices(builder.Configuration)
    .AddHangfire(config => config
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseInMemoryStorage())
    .AddHangfireServer();

Gives RCS0054 here:

    .AddHangfire(config => /*marks warning from here*/ config
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseInMemoryStorage()) /*to here*/

Actual Behavior:
The action suggested by the Code Action keeps the code the same. I've tried multiple formattings, but the only one accepted by this rule is completely unacceptable, which is the following:

builder.Services
    .AddMyServices(builder.Configuration)
.AddHangfire(config => config
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseInMemoryStorage())
    .AddHangfireServer();

(This makes it feel in a way related to this other issue, already solved: #859)

Expected Behavior:
I expect the first code I mentioned here to be accepted as correctly formatted.

@josefpihrt
Copy link
Collaborator

Hi,

Yes, the first code snippet should not produce any diagnostic as it's correctly formatted.

I tried to reproduce the behavior with following snippet but I'm not getting any diagnostic:

top-level statement (essentially entire file)

using System.Collections.Generic;
using System.Linq;

var items = new List<string>();

items
    .Select(f => f)
    .Select(f => f
        .Select(f => f)
        .Select(f => f))
    .Select(f => f);

Can I ask you to create working code sample that I could copy-paste to reproduce the behavior?

Just to rule that out: Can you check that indentation does not contain spaces mixed with tabs?

@eduardomezencio
Copy link
Author

I got the warning with the code you provided above.

@josefpihrt
Copy link
Collaborator

@eduardomezencio I believe you but I need to reproduce the bug.

The best would be to create a project which contains only single file containing code that causes the diagnostic and possibly include editorconfig file which may affect the behavior of the analyzer. Then zip the project and post it here (or create temporary repo if you wish). Thanks.

@eduardomezencio
Copy link
Author

Ok, thanks for looking into it. I'm trying to reproduce this here, too but I'm having problems. I tried to create an empty project enabling only this analyzer and copy your code example into it. Now when I build I get this in the build output:

CSC : warning AD0001: Analyzer 'Roslynator.Formatting.CSharp.FixFormattingOfCallChainAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [/home/eduardo/rcs0054test/rcs0054test.csproj]
    1 Warning(s)
    0 Error(s)

So now the analyzer itself is having problems running.

This project consists only of a Roslynator.Formatting.Analyzers.analyzerconfig file with this inside:

is_global = true

# [RCS0054] Fix formatting of a call chain.
# http://pihrt.net/roslynator/analyzer?id=RCS0054
dotnet_diagnostic.RCS0054.severity = warning

And this in the .csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <GlobalAnalyzerConfigFiles Include="Roslynator.Formatting.Analyzers.analyzerconfig" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Roslynator.Analyzers" Version="4.5.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.5.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.5.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

And the Program.cs, that contains your code from above. I'll try to look deeper into it later.

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