/
no-empty-character-class.js
48 lines (42 loc) · 2.14 KB
/
no-empty-character-class.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @fileoverview Tests for no-empty-class rule.
* @author Ian Christian Myers
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-empty-character-class"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-empty-character-class", rule, {
valid: [
"var foo = /^abc[a-zA-Z]/;",
"var regExp = new RegExp(\"^abc[]\");",
"var foo = /^abc/;",
"var foo = /[\\[]/;",
"var foo = /[\\]]/;",
"var foo = /[a-zA-Z\\[]/;",
"var foo = /[[]/;",
"var foo = /[\\[a-z[]]/;",
"var foo = /[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g;",
"var foo = /\\s*:\\s*/gim;",
{ code: "var foo = /[\\]]/uy;", parserOptions: { ecmaVersion: 6 } },
{ code: "var foo = /[\\]]/s;", parserOptions: { ecmaVersion: 2018 } },
{ code: "var foo = /[\\]]/d;", parserOptions: { ecmaVersion: 2022 } },
"var foo = /\\[]/"
],
invalid: [
{ code: "var foo = /^abc[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "var foo = /foo[]bar/;", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "if (foo.match(/^abc[]/)) {}", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "if (/^abc[]/.test(foo)) {}", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "var foo = /[]]/;", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "var foo = /\\[[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "var foo = /\\[\\[\\]a-z[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] },
{ code: "var foo = /[]]/d;", parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Literal" }] }
]
});