# no-useless-escape

> Disallow backslashes that do not change the meaning of a string or regular expression

In `"\d"` the backslash is dropped and the string is `"d"`. Either you don't need the backslash, or you wanted a real backslash and need to write `"\\d"`.

The rule checks strings, template literals, and regular expression literals. Tagged templates are skipped, because the tag function can see the raw text.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-useless-escape" = "off" # or "error"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-useless-escape" = ["warn", {
  allowRegexCharacters = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 5} */}
```js
const quote = "It\'s here";
const digits = new RegExp("\d+");
const price = `\#${amount}`;
const email = /[\w\.]+\@example\.com/;
```

Not reported:

{/* good */}
```js
const quote = "It's here";
const nested = "She said \"hi\"";
const digits = new RegExp("\\d+");
const price = `#${amount} \${literal}`;
const email = /[\w.]+@example\.com/;
const raw = String.raw`C:\Users\me`;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowRegexCharacters` | `[]` | Characters that you may always escape in a regular expression literal. |

{/* good {"options": [{"allowRegexCharacters": ["-", "@"]}]} */}
```js
const slug = /^\w+\-\w+\@/;
```
