Skip to main content

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 \n escape 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?

  1. The [].join('\n') pattern keeps each line as its own string, making additions and removals easy to diff.
  2. Backslash continuation is fragile — trailing whitespace after \ silently breaks the continuation.
  3. 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.

OptionTypeDefaultDescription
allowEscapeSequencesbooleanfalseSkip checking internal \n escape sequences in strings.
ignoreFilesstring[][]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 \n padding — Only \n between content is flagged. Boundary \n at 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 \n between quasis is flagged. Boundary \n at the start of the first quasi or end of the last quasi is allowed.