# duplicates-in-character-class

Rule `sonarjs/duplicates-in-character-class`. Character classes in regular expressions should not contain the same character twice

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1207 by reach, #508 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
/[0-99]/ // Noncompliant, this won't actually match strings with two digits
/[0-9.-_]/ // Noncompliant, .-_ is a range that already contains 0-9 (as well as various other characters such as capital letters)
```

### Correct: the rule accepts this

```js
/[0-9]{1,2}/
/[0-9.\-_]/
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/duplicates-in-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

- [sonarjs/dompurify-unsafe-config](https://lintradar.dev/rules/sonarjs/dompurify-unsafe-config.md): DOMPurify configuration should not be bypassable
- [sonarjs/dynamically-constructed-templates](https://lintradar.dev/rules/sonarjs/dynamically-constructed-templates.md): Templates should not be constructed dynamically
- [sonarjs/disabled-timeout](https://lintradar.dev/rules/sonarjs/disabled-timeout.md): Disabling Mocha timeouts should be explicit
- [sonarjs/empty-string-repetition](https://lintradar.dev/rules/sonarjs/empty-string-repetition.md): Repeated patterns in regular expressions should not match the empty string
- [sonarjs/disabled-resource-integrity](https://lintradar.dev/rules/sonarjs/disabled-resource-integrity.md): Remote artifacts should not be used without integrity checks
- [sonarjs/encryption-secure-mode](https://lintradar.dev/rules/sonarjs/encryption-secure-mode.md): Encryption algorithms should be used with secure mode and padding scheme

---

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