# prefer-string-raw

Rule `unicorn/prefer-string-raw`. Prefer using the `String.raw` tag to avoid escaping `\`.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #903 by reach, #1158 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-string-raw` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-string-raw.md) |
| Oxlint | `unicorn/prefer-string-raw` | no | safe | plugin `unicorn`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-raw.html) |

## Code examples

### Incorrect: the rule reports this

```js
const file = "C:\\windows\\style\\path\\to\\file.js";
```

```js
const regexp = new RegExp('foo\\.bar');
```

```js
const file = `C:\\windows\\temp\\myapp-${process.pid}.log`;
```

### Correct: the rule accepts this

```js
const file = String.raw`C:\windows\style\path\to\file.js`;
```

```js
const regexp = new RegExp(String.raw`foo\.bar`);
```

```js
const file = String.raw`C:\windows\temp\myapp-${process.pid}.log`;
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-string-raw": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/prefer-string-raw": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-useless-iterator-to-array](https://lintradar.dev/rules/unicorn/no-useless-iterator-to-array.md): Disallow unnecessary `.toArray()` on iterators.
- [unicorn/prefer-top-level-await](https://lintradar.dev/rules/unicorn/prefer-top-level-await.md): Prefer top-level await over top-level promises and async function calls.
- [unicorn/prefer-global-this](https://lintradar.dev/rules/unicorn/prefer-global-this.md): Prefer `globalThis` over `window`, `self`, and `global`.
- [unicorn/better-dom-traversing](https://lintradar.dev/rules/unicorn/better-dom-traversing.md): Prefer better DOM traversal APIs.
- [unicorn/no-process-exit](https://lintradar.dev/rules/unicorn/no-process-exit.md): Disallow `process.exit()`.
- [unicorn/no-canvas-to-image](https://lintradar.dev/rules/unicorn/no-canvas-to-image.md): Prefer drawing canvases directly instead of converting them to images.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-string-raw. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
