CleanCode icon indicating copy to clipboard operation
CleanCode copied to clipboard

Too many chained references - Ignore when using LINQ

Open jacerhea opened this issue 7 years ago • 2 comments

I think the inspection for "Too many chained references " should ignore anything in the LINQ namespace.

jacerhea avatar Sep 08 '16 17:09 jacerhea

Hmm. This is an interesting one, because it might be that you're using a custom SelectMany extension method from another namespace, or even a custom operator, DistinctIgnoringCase or something.

I wonder if there's a good way to generalise this? Perhaps extend the check for "fluent" interfaces, where it doesn't count methods that return the same type that's passed in, e.g. IEnumerable<T>. It would need to ignore the actual type of T, for things like Select((string s) => s.Length, which would start as IEnumerable<string> and return IEnumerable<int>.

That would mean the chained LINQ methods are ignored, but if you have too many chained references after standard LINQ, they'd be marked as smelly code.

How does that sound?

citizenmatt avatar Sep 09 '16 08:09 citizenmatt

This may require a few special cases. My suggestion would be to ignore or increase the allowable threshold when

  1. Using extension methods where both the first input argument and return type implement IEnumerable<T>.
  2. Using extension methods where both the first input argument and return type are the same type.

jacerhea avatar Sep 09 '16 19:09 jacerhea