# no-misleading-character-class

Rule `sonarjs/no-misleading-character-class`. Unicode Grapheme Clusters should be avoided inside regex character classes

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1298 by reach, #599 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-misleading-character-class` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-5868/) |

## Code examples

### Incorrect: the rule reports this

```js
"cc̈d̈d".replace(/[c̈d̈]/g, "X"); // result is "XXXXXX" and not expected "cXXd"
```

### Correct: the rule accepts this

```js
"cc̈d̈d".replace(/c̈|d̈/g, "X"); // result is "cXXd"
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-misleading-character-class": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [eslint/no-misleading-character-class](https://lintradar.dev/rules/eslint/no-misleading-character-class.md): Disallow characters which are made with multiple code points in character class syntax
- [sonarjs/no-misleading-array-reverse](https://lintradar.dev/rules/sonarjs/no-misleading-array-reverse.md): Array-mutating methods should not be used misleadingly
- [sonarjs/no-mutate-reactive-state-in-updated-hook](https://lintradar.dev/rules/sonarjs/no-mutate-reactive-state-in-updated-hook.md): Reactive state should not be unconditionally mutated inside Vue's "updated" lifecycle hook
- [sonarjs/no-mime-sniff](https://lintradar.dev/rules/sonarjs/no-mime-sniff.md): Browsers should not be allowed to perform MIME type sniffing
- [sonarjs/no-nested-assignment](https://lintradar.dev/rules/sonarjs/no-nested-assignment.md): Assignments should not be made from within sub-expressions
- [sonarjs/no-literal-call](https://lintradar.dev/rules/sonarjs/no-literal-call.md): Literals should not be used as functions

---

Web page: https://lintradar.dev/rules/sonarjs/no-misleading-character-class. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
