]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-empty-character-class.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-empty-character-class.md
CommitLineData
eb39fafa
DC
1# disallow empty character classes in regular expressions (no-empty-character-class)
2
3Because empty character classes in regular expressions do not match anything, they might be typing mistakes.
4
5```js
6var foo = /^abc[]/;
7```
8
9## Rule Details
10
11This rule disallows empty character classes in regular expressions.
12
13Examples of **incorrect** code for this rule:
14
15```js
16/*eslint no-empty-character-class: "error"*/
17
18/^abc[]/.test("abcdefg"); // false
19"abcdefg".match(/^abc[]/); // null
20```
21
22Examples of **correct** code for this rule:
23
24```js
25/*eslint no-empty-character-class: "error"*/
26
27/^abc/.test("abcdefg"); // true
28"abcdefg".match(/^abc/); // ["abc"]
29
30/^abc[a-z]/.test("abcdefg"); // true
31"abcdefg".match(/^abc[a-z]/); // ["abcd"]
32```
33
34## Known Limitations
35
36This rule does not report empty character classes in the string argument of calls to the `RegExp` constructor.
37
38Example of a *false negative* when this rule reports correct code:
39
40```js
41/*eslint no-empty-character-class: "error"*/
42
43var abcNeverMatches = new RegExp("^abc[]");
44```