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?
- Long boolean chains on a single line are hard to scan and review.
- Multiline format lets each condition stand out, making diffs cleaner.
- 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.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | File patterns to skip. |
maxInline | number | 2 | Maximum 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
maxInlineis2, 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: 3in the rule options.