Back to Biomejs

noMultiStr

src/content/docs/linter/rules/no-multi-str.mdx

latest3.7 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.8` - Diagnostic Category: [`lint/nursery/noMultiStr`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`no-multi-str`](https://eslint.org/docs/latest/rules/no-multi-str)

How to configure

json
{
	"linter": {
		"rules": {
			"nursery": {
				"noMultiStr": "error"
			}
		}
	}
}

Description

Disallow creating multiline strings by escaping newlines.

Escaping newlines to create multiline strings is discouraged because it can lead to subtle errors caused by unexpected whitespace after the backslash.

Examples

Invalid

js
const foo =
    "Line 1\n\
Line 2";
<pre class="language-text"><code class="language-text">code-block.js:2:5 <a href="https://biomejs.dev/linter/rules/no-multi-str">lint/nursery/noMultiStr</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Escaping newlines to create multiline strings is disallowed.</span> <strong>1 │ </strong>const foo = <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> &quot;Line 1&#92;n&#92; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>Line 2&quot;; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>4 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

Valid

js
const foo = "Line 1\nLine 2";
js
const bar = `Line 1
Line 2`;
</TabItem> </Tabs>