No Multiline Strings
Use [].join('\n') instead of multiline string content because backslash continuations, visual newlines, and internal \n escapes fragment string logic across lines.
Summary
The no-multiline-strings rule reports three forms of multiline string content:
- Backslash line continuation (
\at end of line). - Visual newlines inside template literals.
- Internal
\nescape sequences inside string or template literals.
Boundary \n at the start or end of a string is allowed — this is simple padding, not multiline content. Only \n between content (internal) is flagged.
Why Use This Rule?
- The
[].join('\n')pattern keeps each line as its own string, making additions and removals easy to diff. - Backslash continuation is fragile — trailing whitespace after
\silently breaks the continuation. - Visual newlines in template literals are invisible at a glance and make indentation ambiguous.
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 |
|---|---|---|---|
allowEscapeSequences | boolean | false | Skip checking internal \n escape sequences in strings. |
ignoreFiles | string[] | [] | File patterns to skip. |
Autofix
Autofix is not available for this rule. Flagged code must be updated manually.
Troubleshooting
- Warning fires on
'\n'in a join call — The'\n'argument to.join()is a single-character string, not a multiline string. The rule should not flag it. If it does, check that the warning is on the correct node. - Warning fires on boundary
\npadding — Only\nbetween content is flagged. Boundary\nat the start or end of a string (e.g.,'\nhello\n') is allowed. If the string also contains internal\n, the entire string is flagged. - Template literal with expressions is flagged — Only the newline content matters, not the expressions. A template literal like
`${a}\n${b}`with internal\nbetween quasis is flagged. Boundary\nat the start of the first quasi or end of the last quasi is allowed.