# single-char-in-character-classes

Rule `sonarjs/single-char-in-character-classes`. Character classes in regular expressions should not contain only one character

- 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: #1361 by reach, #662 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
/a[b]c/
/[\^]/
```

### Correct: the rule accepts this

```js
/abc/
/\^/
/a[*]c/ // Compliant, see Exceptions
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/single-char-in-character-classes": "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/session-regeneration](https://lintradar.dev/rules/sonarjs/session-regeneration.md): A new session should be created during user authentication
- [sonarjs/single-character-alternation](https://lintradar.dev/rules/sonarjs/single-character-alternation.md): Single-character alternations in regular expressions should be replaced with character classes
- [sonarjs/review-blockchain-mnemonic](https://lintradar.dev/rules/sonarjs/review-blockchain-mnemonic.md): Wallet phrases should not be hard-coded
- [sonarjs/slow-regex](https://lintradar.dev/rules/sonarjs/slow-regex.md): Regular expressions should not cause catastrophic backtracking
- [sonarjs/regex-complexity](https://lintradar.dev/rules/sonarjs/regex-complexity.md): Regular expressions should not be too complicated
- [sonarjs/sql-queries](https://lintradar.dev/rules/sonarjs/sql-queries.md): SQL queries should not be dynamically formatted

---

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