unicorn/prefer-string-raw
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-string-raw": "error",
},
},
];const file = "C:\\windows\\style\\path\\to\\file.js";const regexp = new RegExp('foo\\.bar');const file = `C:\\windows\\temp\\myapp-${process.pid}.log`;const file = String.raw`C:\windows\style\path\to\file.js`;const regexp = new RegExp(String.raw`foo\.bar`);const file = String.raw`C:\windows\temp\myapp-${process.pid}.log`;Examples from the ESLint documentation.
unicorn/prefer-string-raw
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-string-raw": "error",
},
},
];unicorn/prefer-string-raw
unicorn plugin · style
{
"rules": {
"unicorn/prefer-string-raw": "error"
}
}Biome does not have this rule.
Disallow unnecessary .toArray() on iterators.
Prefer top-level await over top-level promises and async function calls.
Prefer globalThis over window, self, and global.
Prefer drawing canvases directly instead of converting them to images.