csharp-styleguide icon indicating copy to clipboard operation
csharp-styleguide copied to clipboard

NI1017 fails to report errors in certain expressions.

Open gregr-ni opened this issue 4 years ago • 1 comments

The code below should report an NI1017 error but does not because it is in the last section of a ternary operator. Errors in the first value of ternarys are reported correctly.

private static IEnumerable Ternary(IEnumerable numbers) { return numbers is null ? Enumerable.Empty() : numbers.Where(n => n < 10).Select(n => $"{n}"); }

Likewise violations in a return statement are not reported. If you assign to a local then return the local, the error is reported.

private static int Expression(IEnumerable numbers) { return numbers.Where(n => n < 10).Select(n => n * 2).Max(); }

gregr-ni avatar Dec 01 '20 17:12 gregr-ni

The reason why it fails to report is because by registration https://github.com/ni/csharp-styleguide/blob/3827066521a2b000a9e36f60251382502b2efb32/src/NationalInstruments.Analyzers/Style/ChainOfMethodsWithLambdasAnalyzer.cs#L38

The syntax node in the second example is InvocationExpression image

Have to check that node as the root node

Everest2020 avatar Apr 03 '21 08:04 Everest2020