no-empty-character-class
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-empty-character-class": "error",
},
},
];Disallow empty character classes in regular expressions
/^abc[]/.test("abcdefg"); // false
"abcdefg".match(/^abc[]/); // null
/^abc[[]]/v.test("abcdefg"); // false
"abcdefg".match(/^abc[[]]/v); // null
/^abc[[]--[x]]/v.test("abcdefg"); // false
"abcdefg".match(/^abc[[]--[x]]/v); // null
/^abc[[d]&&[]]/v.test("abcdefg"); // false
"abcdefg".match(/^abc[[d]&&[]]/v); // null
const regex = /^abc[d[]]/v;
regex.test("abcdefg"); // true, the nested `[]` has no effect
"abcdefg".match(regex); // ["abcd"]
regex.test("abcefg"); // false, the nested `[]` has no effect
"abcefg".match(regex); // null
regex.test("abc"); // false, the nested `[]` has no effect
"abc".match(regex); // null/^abc/.test("abcdefg"); // true
"abcdefg".match(/^abc/); // ["abc"]
/^abc[a-z]/.test("abcdefg"); // true
"abcdefg".match(/^abc[a-z]/); // ["abcd"]
/^abc[^]/.test("abcdefg"); // true
"abcdefg".match(/^abc[^]/); // ["abcd"]Examples from the ESLint documentation.
no-empty-character-class
eslint
export default [
{
rules: {
"no-empty-character-class": "error",
},
},
];no-empty-character-class
eslint plugin · correctness
{
"rules": {
"no-empty-character-class": "error"
}
}correctness/noEmptyCharacterClassInRegex
correctness · since 1.3.0
{
"linter": {
"rules": {
"correctness": {
"noEmptyCharacterClassInRegex": "error"
}
}
}
}Empty character classes should not be used
Disallow unnecessary escape characters
Disallow control characters in regular expressions
Disallow empty destructuring patterns
Require calls to isNaN() when checking for NaN