Skip to content

[RCS1077] Rule produces incorrect formatting when applying code fixes (; placed on wrong indentation level) #1728

@MaksHladki

Description

@MaksHladki

Product and Version Used

Roslynator Version: 4.14.1
IDE: Visual Studio 2022
Framework: .NET 8.0

Description

When running dotnet format or using the Roslyn CLI with Roslynator enabled, the code fix for RCS1077 incorrectly formats the generated code. Specifically, the semicolon after a transformed method call is placed at an incorrect indentation level.

Steps to Reproduce

  • Enable rule RCS1077.
  • Write a LINQ query with formatting issues.
  • Call dotnet format or Roslynator CLI to fix issues.

Input

eventPublisher.EnqueueLowPriorityEvent(() =>
{
    IReadOnlyList<IEvent> events = normalizedSpecialistBios
        .Select(sb => new SpecialistBioUpdatedEvent(sb.ProfileId))
        .ToList();

    return new BatchEvent(events);
});

Actual Behavior

eventPublisher.EnqueueLowPriorityEvent(() =>
{
    IReadOnlyList<IEvent> events = normalizedSpecialistBios
        .ConvertAll(sb => new SpecialistBioUpdatedEvent(sb.ProfileId))
;
    return new BatchEvent(events);
});

Notice that the semicolon is placed on a new line with indentation based on the start of the original expression rather than aligned with the transformed method call.
It appears that the indentation is calculated relative to the original Select(...).ToList() call instead of the new ConvertAll(...) call inserted by the code fix.

Expected Behavior
The semicolon should remain properly aligned with the preceding method call, e.g.:

IReadOnlyList<IEvent> events = normalizedSpecialistBios
    .ConvertAll(sb => new SpecialistBioUpdatedEvent(sb.ProfileId));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions