DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.64k stars 506 forks source link

[Question] A rule for method chaining (LINQ and similar) #3600

Open Dennis-Petrov opened 1 year ago

Dennis-Petrov commented 1 year ago

Hello. The question is about method chaining style for LINQ and similar fluent APIs. I'm looking for a rule, which can force this style:

var result = source
    .Where(...)
    .GroupBy(...)
    .Select(...);  // and so on

or, at least this one:

var result = source.Where(...)
    .GroupBy(...)
    .Select(...);  // and so on

and forbid one-liners like this:

var result = source.Where(...).GroupBy(...).Select(...);  // and so on

Probably, this one had been answered already, but I can't find anything related. Is there any rule out-of-box?

bjornhellander commented 1 year ago

Personally, I don't think this would be a good rule. I see no problem with one-liners as long as they are short and would not like to be forced to split them up.