# no-misleading-character-class

> Disallow characters made of several code points inside a regular expression character class

A character class such as `[ab]` matches one code point from the list. Many things that look like one character are several: a letter followed by a combining accent, an emoji with a skin tone, a flag, a family joined with zero-width joiners. Without the `u` flag, most emoji count as two. Inside `[...]` each part becomes its own alternative, so `/^[👍]$/.test("👍")` is `false`.

The rule checks regular expression literals and the patterns given to `RegExp(...)` and `new RegExp(...)`.

`--fix-suggestions` adds the `u` flag when that's all that's missing and the pattern stays valid with it.

This rule is on by default.

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

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-misleading-character-class" = "off" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-misleading-character-class" = ["error", {
  allowEscape = false,
}]
```

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

## Examples

Reported:

{/* bad */}
```js
const isThumbsUp = /^[👍]$/;
```

{/* bad */}
```js
const isFlag = /^[🇯🇵🇩🇪]$/u;
```

{/* bad */}
```js
const isFamily = new RegExp("[👨‍👩‍👦]", "u");
```

Not reported:

{/* good */}
```js
const isThumbsUp = /^[👍]$/u;
```

{/* good */}
```js
const isFlag = /^(?:🇯🇵|🇩🇪)$/u;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowEscape` | `false` | Don't report code points that are written as escapes, such as `\u0301`. The escape shows that you meant a separate code point. |

{/* bad */}
```js
const accents = /[A\u0301]/;
```

{/* good {"options": [{"allowEscape": true}]} */}
```js
const accents = /[A\u0301]/;
```
