Skip to content

noUselessStringRaw

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"complexity": {
"noUselessStringRaw": "error"
}
}
}
}

¥Description

禁止在模板字符串字面量中使用不必要的 String.raw 函数(不带任何转义序列)。

¥Disallow unnecessary String.raw function in template string literals without any escape sequence.

当包含没有任何转义序列的原始字符串时,String.raw 无效。

¥String.raw is useless when contains a raw string without any escape-like sequence.

¥Examples

¥Invalid

String.raw`a`;
code-block.js:1:1 lint/complexity/noUselessStringRaw ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

String.raw is useless when the raw string doesn’t contain any escape sequence.

> 1 │ String.raw`a`;
^^^^^^^^^^^^^
2 │

Remove the String.raw call because it’s useless here, String.raw can deal with string which contains escape sequence like \n, \t, \r, \\, \”, \’.

String.raw`a ${v}`;
code-block.js:1:1 lint/complexity/noUselessStringRaw ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

String.raw is useless when the raw string doesn’t contain any escape sequence.

> 1 │ String.raw`a ${v}`;
^^^^^^^^^^^^^^^^^^
2 │

Remove the String.raw call because it’s useless here, String.raw can deal with string which contains escape sequence like \n, \t, \r, \\, \”, \‘.

¥Valid

String.raw`\n ${a}`;
String.raw`\n`;

¥Related links