Version: SonarQube 9.5
I have noticed this code snippet raises S3358 (avoid nested ternary operators):
public Func<TObject, ReportCellStyle> GetFormat<TObject>(bool withTime, Func<TObject, bool> withTimeAccessor)
{
return withTimeAccessor != null
? item => withTimeAccessor(item) ? ReportCellStyle.DateTime : ReportCellStyle.Date
: item => withTime ? ReportCellStyle.DateTime : ReportCellStyle.Date;
}
This is a case of a ternary operator returning lambdas which contain a ternary operator.
This is different from having nested ternary operators in the same “code flow” and I don’t know if this rule should apply to this specific case.
I have encountered this issue with C# but it might apply to other languages with similar constructs.