Extend S3240: The simplest possible condition syntax should be used

The current rule states:

In the interests of keeping code clean, the simplest possible conditional syntax should be used. That means

  • […]
  • using the ternary operator ?: for assignment to a single variable.

Can we extend this to

using the ternary operator ?: for assignment to a single variable or a single line of code.

…or something similar.

The problem is, enforcing the current rule would make LINQ code, which regularly uses up multiple lines (eg. to make multiple conditions more readable), less readable.

See this example:

would convert to

Hi @neoscie

Welcome to the community.
Unfortunately we do not have this kind of change in our plan.

Maybe you could try formatting it in the following way:

            foreach (var search in query.Split(' '))
                medicsQuery = context.DataBaseVendor == Enums.DatabaseVendor.PostgreSql
                    ? medicsQuery.Where(x => EF.Functions.Ilike(x.FirstName, search + "%") || EF.Functions.Ilike(x.LastName, search + "%"))
                    : medicsQuery.Where(x => x.FirstName.StartsWith(search) || x.LastName.StartsWith(search));

As another option you can extract the conditions of the where clause into some new methods.

Thank you for your feedback.