Skip to content

[RCS0054] Add option to force "true" call chain formatting (start chain on new line) #1722

Description

@MaksHladki

Product and Version Used

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

Description

Currently, rule RCS0054 (Fix formatting of a call chain) enforces a style where the first method call in a chain remains on the same line as the object being operated on, while subsequent calls are wrapped to new lines.
I would like to request a configuration option for RCS0054 that enforces wrapping the first call in the chain to a new line as well. This is often preferred for "fluent" API readability.

Steps to Reproduce

  1. Enable rule RCS0054.
  2. Write a LINQ chain with formatting issues.
  3. Apply the code fix by fix --supported-diagnostics RCS0054

Input

 var filteredProfiles = profiles.Where(p => p.Id != 0)
     .OrderBy(p => p.LastName).ToList();

Actual Behavior

var filteredProfiles = profiles.Where(p => p.Id != 0)
    .OrderBy(p => p.LastName)
    .ToList();

Expected Behavior

var filteredProfiles = profiles
    .Where(p => p.Id != 0)
    .OrderBy(p => p.LastName)
    .ToList();

Handling Null-Conditional Operators (?.)

Crucially, this behavior must handle the null-conditional operator correctly by settings. If the chain initiates with ?., the operator should wrap to the new line along with the method.

var profileNames = profiles
    ?.Select(p => $"{p.FirstName} {p.LastName}")
    .ToList();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions