Skip to main content

Require Multiline Conditions

Require each operand to be on its own line when a logical expression exceeds the allowed inline count.

Summary

The require-multiline-conditions rule checks all LogicalExpression nodes (&&, ||, ??). It recursively counts the total leaf operands and, when the count exceeds a configurable maxInline threshold (default: 2), requires each operand to start on its own line.

This covers every context — if, while, do...while, for, ternary, return, variable declarations, and standalone expressions.

Why Use This Rule?

  1. Long boolean chains on a single line are hard to scan and review.
  2. Multiline format lets each condition stand out, making diffs cleaner.
  3. Consistent formatting reduces cognitive load when reading complex guards.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.
maxInlinenumber2Maximum number of operands allowed on a single line before requiring multiline.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Warning fires on a two-operand expression — The default maxInline is 2, which allows up to two operands inline. If you see a warning, the expression likely has more operands than expected due to nested logical expressions being flattened.
  • Want to allow three operands inline — Set maxInline: 3 in the rule options.